visuddhinanda 2 лет назад
Родитель
Сommit
385a4c0ab5

+ 72 - 0
app/Console/Commands/UpgradePageNumber.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\WbwTemplate;
+use App\Models\PageNumber;
+
+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()
+    {
+        $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;
+    }
+}

+ 14 - 0
app/Models/PageNumber.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class PageNumber extends Model
+{
+    use HasFactory;
+	protected $fillable = ['type','volume','page',
+                            'book','paragraph','wid','pcd_book_id'];
+
+}

+ 38 - 0
database/migrations/2023_10_06_111407_create_page_numbers_table.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreatePageNumbersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('page_numbers', function (Blueprint $table) {
+            $table->id();
+            $table->string('type',1)->index();
+            $table->integer('volume')->index();
+            $table->integer('page')->index();
+            $table->integer('book')->index();
+            $table->integer('paragraph')->index();
+            $table->integer('wid')->index();
+            $table->integer('pcd_book_id')->index();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('page_numbers');
+    }
+}