UpdateSentenceVer.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Sentence;
  5. use Illuminate\Support\Str;
  6. class UpdateSentenceVer extends Command
  7. {
  8. /**
  9. * 将无channel_uid的旧版句子数据的ver修改为1.
  10. * php artisan update:sentence.ver
  11. * @var string
  12. */
  13. protected $signature = 'update:sentence.ver';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '将无channel_uid的旧版句子数据的ver修改为1';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $count = 0;
  37. $total = Sentence::whereNull('channel_uid')->orWhere('channel_uid','')->count();
  38. foreach (Sentence::whereNull('channel_uid')->orWhere('channel_uid','')->cursor() as $key => $value) {
  39. # code...
  40. $value->ver = 1;
  41. $value->channel_uid = Str::uuid();
  42. $value->save();
  43. $count++;
  44. if($count % 1000 === 0){
  45. $per = (int)($count*100 / $total);
  46. $this->info("[{$per}%]-{$count}");
  47. }
  48. }
  49. $this->info("all done [{$count}]");
  50. return 0;
  51. }
  52. }