2
0

UpgradePcdBookId.php 2.1 KB

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