InitSystemChannel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Channel;
  4. use Illuminate\Console\Command;
  5. class InitSystemChannel extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'init:system.channel';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'create system channel. like pali text , wbw template ect.';
  19. protected $channels =[
  20. [
  21. "name"=>'_System_Pali_VRI_',
  22. 'type'=>'original',
  23. 'lang'=>'pali',
  24. ],
  25. [
  26. "name"=>'_System_Wbw_VRI_',
  27. 'type'=>'original',
  28. 'lang'=>'pali',
  29. ],
  30. [
  31. "name"=>'_System_Grammar_Term_zh-hans_',
  32. 'type'=>'translation',
  33. 'lang'=>'zh-Hans',
  34. ],
  35. [
  36. "name"=>'_System_Grammar_Term_zh-hant_',
  37. 'type'=>'translation',
  38. 'lang'=>'zh-Hant',
  39. ],
  40. [
  41. "name"=>'_System_Grammar_Term_en_',
  42. 'type'=>'translation',
  43. 'lang'=>'en',
  44. ],
  45. [
  46. "name"=>'_community_term_zh-hans_',
  47. 'type'=>'translation',
  48. 'lang'=>'zh-Hans',
  49. ],
  50. [
  51. "name"=>'_community_term_zh-hant_',
  52. 'type'=>'translation',
  53. 'lang'=>'zh-Hant',
  54. ],
  55. [
  56. "name"=>'_community_term_en_',
  57. 'type'=>'translation',
  58. 'lang'=>'en',
  59. ],
  60. ];
  61. /**
  62. * Create a new command instance.
  63. *
  64. * @return void
  65. */
  66. public function __construct()
  67. {
  68. parent::__construct();
  69. }
  70. /**
  71. * Execute the console command.
  72. *
  73. * @return int
  74. */
  75. public function handle()
  76. {
  77. $this->info("start");
  78. foreach ($this->channels as $key => $value) {
  79. # code...
  80. $channel = Channel::firstOrNew([
  81. 'name' => $value['name'],
  82. 'owner_uid' => config("app.admin.root_uuid"),
  83. ]);
  84. if(empty($channel->id)){
  85. $channel->id = app('snowflake')->id();
  86. }
  87. $channel->type = $value['type'];
  88. $channel->lang = $value['lang'];
  89. $channel->editor_id = 0;
  90. $channel->owner_uid = config("app.admin.root_uuid");
  91. $channel->create_time = time()*1000;
  92. $channel->modify_time = time()*1000;
  93. $channel->save();
  94. $this->info("created". $value['name']);
  95. }
  96. return 0;
  97. }
  98. }