InitSystemChannel.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Channel;
  4. use App\Tools\Tools;
  5. use Illuminate\Console\Command;
  6. class InitSystemChannel extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'init:system.channel';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'create system channel. like pali text , wbw template ect.';
  20. protected $channels = [
  21. [
  22. 'name' => '_System_Pali_VRI_',
  23. 'type' => 'original',
  24. 'lang' => 'pali',
  25. ],
  26. [
  27. 'name' => '_System_Wbw_VRI_',
  28. 'type' => 'wbw',
  29. 'lang' => 'pali',
  30. ],
  31. [
  32. 'name' => '_System_Grammar_Term_zh-hans_',
  33. 'type' => 'translation',
  34. 'lang' => 'zh-Hans',
  35. ],
  36. [
  37. 'name' => '_System_Grammar_Term_zh-hant_',
  38. 'type' => 'translation',
  39. 'lang' => 'zh-Hant',
  40. ],
  41. [
  42. 'name' => '_System_Grammar_Term_en_',
  43. 'type' => 'translation',
  44. 'lang' => 'en',
  45. ],
  46. [
  47. 'name' => '_System_Grammar_Term_my_',
  48. 'type' => 'translation',
  49. 'lang' => 'my',
  50. ],
  51. [
  52. 'name' => '_community_term_zh-hans_',
  53. 'type' => 'translation',
  54. 'lang' => 'zh-Hans',
  55. ],
  56. [
  57. 'name' => '_community_term_zh-hant_',
  58. 'type' => 'translation',
  59. 'lang' => 'zh-Hant',
  60. ],
  61. [
  62. 'name' => '_community_term_en_',
  63. 'type' => 'translation',
  64. 'lang' => 'en',
  65. ],
  66. [
  67. 'name' => '_community_translation_zh-hans_',
  68. 'type' => 'translation',
  69. 'lang' => 'zh-Hans',
  70. ],
  71. [
  72. 'name' => '_community_translation_zh-hant_',
  73. 'type' => 'translation',
  74. 'lang' => 'zh-Hant',
  75. ],
  76. [
  77. 'name' => '_community_translation_en_',
  78. 'type' => 'translation',
  79. 'lang' => 'en',
  80. ],
  81. [
  82. 'name' => '_System_Quote_',
  83. 'type' => 'original',
  84. 'lang' => 'en',
  85. ],
  86. [
  87. 'name' => '_community_summary_zh-hans_',
  88. 'type' => 'translation',
  89. 'lang' => 'zh-Hans',
  90. ],
  91. [
  92. 'name' => '_System_commentary_',
  93. 'type' => 'commentary',
  94. 'lang' => 'en',
  95. 'status' => 30,
  96. ],
  97. [
  98. 'name' => '_system_glossary_',
  99. 'type' => 'original',
  100. 'lang' => 'pi',
  101. ],
  102. ];
  103. /**
  104. * Create a new command instance.
  105. *
  106. * @return void
  107. */
  108. public function __construct()
  109. {
  110. parent::__construct();
  111. }
  112. /**
  113. * Execute the console command.
  114. *
  115. * @return int
  116. */
  117. public function handle()
  118. {
  119. if (Tools::isStop()) {
  120. return 0;
  121. }
  122. $this->info('init:system.channel start');
  123. foreach ($this->channels as $key => $value) {
  124. // code...
  125. $channel = Channel::firstOrNew([
  126. 'name' => $value['name'],
  127. 'owner_uid' => config('mint.admin.root_uuid'),
  128. ]);
  129. if (empty($channel->id)) {
  130. $channel->id = app('snowflake')->id();
  131. }
  132. $channel->type = $value['type'];
  133. $channel->lang = $value['lang'];
  134. $channel->editor_id = 0;
  135. $channel->owner_uid = config('mint.admin.root_uuid');
  136. $channel->create_time = time() * 1000;
  137. $channel->modify_time = time() * 1000;
  138. $channel->is_system = true;
  139. if (isset($value['status'])) {
  140. $channel->status = $value['status'];
  141. }
  142. $channel->save();
  143. $this->line('init '.$value['name']);
  144. }
  145. $this->info('init:system.channel successful');
  146. return 0;
  147. }
  148. }