UpgradePcdBookId.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\FtsText;
  5. use App\Models\WbwTemplate;
  6. use App\Models\BookTitle;
  7. class UpgradePcdBookId extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:pcd.book.id {--table=all}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  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. if(\App\Tools\Tools::isStop()){
  38. return 0;
  39. }
  40. $table = $this->option('table');
  41. $bookTitles = BookTitle::orderBy('sn')->get();
  42. $bar = $this->output->createProgressBar(count($bookTitles));
  43. foreach ($bookTitles as $key => $value) {
  44. # code...
  45. if($table === 'all' || $table ==='fts'){
  46. FtsText::where('book',$value->book)
  47. ->where('paragraph','>=',$value->paragraph)
  48. ->update(['pcd_book_id'=>$value->id]);
  49. }
  50. if($table === 'all' || $table ==='wbw'){
  51. WbwTemplate::where('book',$value->book)
  52. ->where('paragraph','>=',$value->paragraph)
  53. ->update(['pcd_book_id'=>$value->id]);
  54. }
  55. $bar->advance();
  56. }
  57. $bar->finish();
  58. return 0;
  59. }
  60. }