| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Console\Commands;
- use App\Models\PageNumber;
- use App\Models\WbwTemplate;
- use App\Tools\Tools;
- use Illuminate\Console\Command;
- class UpgradePageNumber extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'upgrade:page.number';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- if (Tools::isStop()) {
- return 0;
- }
- $table = WbwTemplate::where('type', '.ctl.')->orderBy('book')->orderBy('paragraph')->cursor();
- $pageHead = ['M', 'P', 'T', 'V', 'O'];
- $bar = $this->output->createProgressBar(WbwTemplate::where('type', '.ctl.')->count());
- foreach ($table as $key => $value) {
- $type = substr($value->word, 0, 1);
- if (in_array($type, $pageHead)) {
- $arrPage = explode('.', $value->word);
- if (count($arrPage) !== 2) {
- continue;
- }
- $page = PageNumber::firstOrNew(
- [
- 'book' => $value->book,
- 'paragraph' => $value->paragraph,
- 'wid' => $value->wid,
- ],
- [
- 'type' => $type,
- 'volume' => (int) substr($arrPage[0], 1),
- 'page' => (int) $arrPage[1],
- 'pcd_book_id' => $value->pcd_book_id,
- ]
- );
- $page->save();
- }
- $bar->advance();
- }
- $bar->finish();
- return 0;
- }
- }
|