2
0

UpdateSentenceVer.php 1.4 KB

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