Parcourir la source

install:paliseries

visuddhinanda il y a 4 ans
Parent
commit
7c65315051
2 fichiers modifiés avec 42 ajouts et 1 suppressions
  1. 40 1
      app/Console/Commands/InstallPaliSeries.php
  2. 2 0
      app/Models/BookTitle.php

+ 40 - 1
app/Console/Commands/InstallPaliSeries.php

@@ -3,6 +3,9 @@
 namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
+use App\Models\BookTitle;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
 
 class InstallPaliSeries extends Command
 {
@@ -11,7 +14,7 @@ class InstallPaliSeries extends Command
      *
      * @var string
      */
-    protected $signature = 'command:name';
+    protected $signature = 'install:paliseries';
 
     /**
      * The console command description.
@@ -37,6 +40,42 @@ class InstallPaliSeries extends Command
      */
     public function handle()
     {
+		$this->info("upgrade pali text");
+		$startTime = time();
+
+
+
+					DB::transaction(function () {
+						#删除目标数据库中数据
+						BookTitle::where('book','>',0)->delete();
+
+					// 打开csv文件并读取数据										
+						$strFileName = config("app.path.pali_title") . "/pali_serieses.csv";
+						if(!file_exists($strFileName)){
+							return 1;
+						}						
+						$inputRow = 0;
+						if (($fp = fopen($strFileName, "r")) !== false) {
+							while (($data = fgetcsv($fp, 0, ',')) !== false) {
+								if($inputRow>0){
+									$newData = [
+										'book'=>$data[1],
+										'paragraph'=>$data[2],
+										'title'=>$data[3],
+									];
+		
+									BookTitle::create($newData);									
+								}
+								$inputRow++;
+							}
+							fclose($fp);
+							Log::info("res load:" .$strFileName);
+						} else {
+							$this->error("can not open csv $strFileName");
+							Log::error("can not open csv $strFileName");
+						}
+					});
+		$this->info("ok");
         return 0;
     }
 }

+ 2 - 0
app/Models/BookTitle.php

@@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
 class BookTitle extends Model
 {
     use HasFactory;
+	
+	protected $fillable = ['book' , 'paragraph' , 'title'];
 }