UpgradePcdBookId.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\BookTitle;
  4. use App\Models\FtsText;
  5. use App\Models\PageNumber;
  6. use App\Models\PaliText;
  7. use App\Models\WbwTemplate;
  8. use App\Tools\Tools;
  9. use Illuminate\Console\Command;
  10. class UpgradePcdBookId extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'upgrade:pcd.book.id {--table=all}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return int
  37. */
  38. public function handle()
  39. {
  40. if (Tools::isStop()) {
  41. return 0;
  42. }
  43. $table = $this->option('table');
  44. $bookTitles = BookTitle::orderBy('sn')->get();
  45. $bar = $this->output->createProgressBar(count($bookTitles));
  46. foreach ($bookTitles as $key => $value) {
  47. // code...
  48. if ($table === 'all' || $table === 'fts') {
  49. FtsText::where('book', $value->book)
  50. ->where('paragraph', '>=', $value->paragraph)
  51. ->update(['pcd_book_id' => $value->sn]);
  52. }
  53. if ($table === 'all' || $table === 'wbw') {
  54. WbwTemplate::where('book', $value->book)
  55. ->where('paragraph', '>=', $value->paragraph)
  56. ->update(['pcd_book_id' => $value->sn]);
  57. }
  58. if ($table === 'all' || $table === 'pali_text') {
  59. PaliText::where('book', $value->book)
  60. ->where('paragraph', '>=', $value->paragraph)
  61. ->update(['pcd_book_id' => $value->sn]);
  62. }
  63. if ($table === 'all' || $table === 'page_number') {
  64. PageNumber::where('book', $value->book)
  65. ->where('paragraph', '>=', $value->paragraph)
  66. ->update(['pcd_book_id' => $value->sn]);
  67. }
  68. $bar->advance();
  69. }
  70. $bar->finish();
  71. return 0;
  72. }
  73. }