visuddhinanda 3 năm trước cách đây
mục cha
commit
fd530c07bd
1 tập tin đã thay đổi với 64 bổ sung0 xóa
  1. 64 0
      app/Console/Commands/UpgradePcdBookId.php

+ 64 - 0
app/Console/Commands/UpgradePcdBookId.php

@@ -0,0 +1,64 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\FtsText;
+use App\Models\WbwTemplate;
+use App\Models\BookTitle;
+
+class UpgradePcdBookId extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'upgrade:pcd.book.id {--table=all}';
+
+    /**
+     * 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()
+    {
+        $table = $this->option('table');
+        $bookTitles = BookTitle::orderBy('id')->get();
+        $bar = $this->output->createProgressBar(count($bookTitles));
+        foreach ($bookTitles as $key => $value) {
+            # code...
+            if($table === 'all' || $table ==='fts'){
+                FtsText::where('book',$value->book)
+                    ->where('paragraph','>=',$value->paragraph)
+                    ->update(['pcd_book_id'=>$value->id]);
+            }
+            if($table === 'all' || $table ==='wbw'){
+                WbwTemplate::where('book',$value->book)
+                    ->where('paragraph','>=',$value->paragraph)
+                    ->update(['pcd_book_id'=>$value->id]);
+            }
+            $bar->advance();
+        }
+        $bar->finish();
+
+        return 0;
+    }
+}