InitSystemChannel.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /**
  47. * Create a new command instance.
  48. *
  49. * @return void
  50. */
  51. public function __construct()
  52. {
  53. parent::__construct();
  54. }
  55. /**
  56. * Execute the console command.
  57. *
  58. * @return int
  59. */
  60. public function handle()
  61. {
  62. $this->info("start");
  63. foreach ($this->channels as $key => $value) {
  64. # code...
  65. $channel = Channel::firstOrNew([
  66. 'name' => $value['name'],
  67. 'owner_uid' => config("app.admin.root_uuid"),
  68. ]);
  69. if(empty($channel->id)){
  70. $channel->id = app('snowflake')->id();
  71. }
  72. $channel->type = $value['type'];
  73. $channel->lang = $value['lang'];
  74. $channel->editor_id = 0;
  75. $channel->owner_uid = config("app.admin.root_uuid");
  76. $channel->create_time = time()*1000;
  77. $channel->modify_time = time()*1000;
  78. $channel->save();
  79. $this->info("created". $value['name']);
  80. }
  81. return 0;
  82. }
  83. }