2
0
visuddhinanda@gmail.com 4 жил өмнө
parent
commit
ebc6e61684

+ 38 - 10
app/Console/Commands/UpgradePaliText.php

@@ -21,7 +21,7 @@ class UpgradePaliText extends Command
      *
      * @var string
      */
-    protected $description = 'Command description';
+    protected $description = 'upgrade pali_texts paragraph infomation';
 
     /**
      * Create a new command instance.
@@ -65,12 +65,12 @@ class UpgradePaliText extends Command
 
 		for ($from=$_from; $from <= $_to; $from++) {
 			$inputRow = 0;
-			
 			$arrInserString = array();
 			#载入csv数据
 			$FileName = $filelist[$from-1][1];
-			$csvFile = config("app.path.palicsv") .'/'. $FileName .'/'. $FileName.'_pali.csv';
+			$csvFile = config("app.path.pali_title") .'/'. $from.'_pali.csv';
 			if (($fp = fopen($csvFile, "r")) !== false) {
+                Log::info("csv load:" . $csvFile);
 				while (($data = fgetcsv($fp, 0, ',')) !== false) {
 					if ($inputRow > 0) {
 						array_push($arrInserString, $data);
@@ -78,22 +78,24 @@ class UpgradePaliText extends Command
 					$inputRow++;
 				}
 				fclose($fp);
-				Log::info("csv load:" . $csvFile);
+				
 			} else {
 				$this->error( "can not open csv file. filename=" . $csvFile. PHP_EOL) ;
 				Log::error( "can not open csv file. filename=" . $csvFile) ;
 				continue;
 			}
 			$title_data = PaliText::where('book',$from)->orderby('paragraph','asc')->get();
-			DB::transaction(function ()use($from,$arrInserString,$title_data) {
+			//DB::transaction(
+                //function ()use($from,$arrInserString,$title_data) 
+            {
 				$paragraph_count = count($title_data);
 				$paragraph_info = array();
 				$paragraph_info[] = array($from, -1, $paragraph_count, -1, -1, -1);
 
 
-				for ($iPar = 0; $iPar < count($title_data); $iPar++) {
-					$title_data[$iPar]["level"] = $arrInserString[$iPar][3];
-				}
+                for ($iPar = 0; $iPar < count($title_data); $iPar++) {
+                    $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
+                }
 
 
 				for ($iPar = 0; $iPar < count($title_data); $iPar++) {
@@ -163,7 +165,7 @@ class UpgradePaliText extends Command
 					for ($i = $iPar; $i < $iPar + $length; $i++) {
 						$iChapter_strlen += $title_data[$i]["lenght"];
 					}
-					
+
 					$newData = [
 						'level' => $arrInserString[$iPar][3],
 						'toc' => $arrInserString[$iPar][5],
@@ -173,6 +175,29 @@ class UpgradePaliText extends Command
 						'parent' => $parent,
 						'chapter_strlen'=> $iChapter_strlen,
 					];
+
+                    $path = [];
+
+                    $title_data[$iPar]["level"] = $newData["level"];
+                    $title_data[$iPar]["toc"] = $newData["toc"];
+                    $title_data[$iPar]["parent"] = $newData["parent"];
+
+					/*
+                    *获取路径
+                    */
+                    $currParent = $parent;
+                    
+                    $iLoop = 0;
+                    while ($currParent != -1 && $iLoop<7) {
+                        # code...
+                        $pathTitle = $title_data[$currParent-1]["toc"];
+                        $pathLevel = $title_data[$currParent-1]['level'];
+                        $path[] = ["book"=>$book,"paragraph"=>$currParent,"title"=>$pathTitle,"level"=>$pathLevel];
+                        $currParent = $title_data[$currParent-1]["parent"];
+                        $iLoop++;
+                    }
+                    $newData['path'] = $path;
+
 					PaliText::where('book',$book)
 							->where('paragraph',$paragraph)
 							->update($newData);
@@ -181,7 +206,10 @@ class UpgradePaliText extends Command
 						$paragraph_info[] = array($book, $paragraph, $length, $prev, $next, $parent);
 					}
 				}
-			});
+			}
+            //);
+
+            
 			$bar->advance();
 		}
 		$bar->finish();

+ 87 - 66
public/app/install/db_update_palitext_cli.php

@@ -52,96 +52,96 @@ PDO_Connect(_DB_PALITEXT_,_DB_USERNAME_,_DB_PASSWORD_);
 
 
 for ($from=$_from-1; $from < $to; $from++) { 
-    fwrite(STDOUT, "doing $from".PHP_EOL);
+    fwrite(STDOUT, "doing $_from".PHP_EOL);
 
-$FileName = $filelist[$from][1] . ".htm";
-$fileId = $filelist[$from][0];
-$fileId = $filelist[$from][0];
+    $FileName = $filelist[$from][1] . ".htm";
+    $fileId = $filelist[$from][0];
+    $fileId = $filelist[$from][0];
 
-$dirLog = _DIR_LOG_ . "/";
+    $dirLog = _DIR_LOG_ . "/";
 
-$dirDb = "/";
-$inputFileName = $FileName;
-$outputFileNameHead = $filelist[$from][1];
-$bookId = $filelist[$from][2];
-$vriParNum = 0;
-$wordOrder = 1;
+    $dirDb = "/";
+    $inputFileName = $FileName;
+    $outputFileNameHead = $filelist[$from][1];
+    $bookId = $filelist[$from][2];
+    $vriParNum = 0;
+    $wordOrder = 1;
 
-$dirXmlBase = _DIR_PALI_CSV_ . "/";
-$dirPaliTextBase = _DIR_PALI_HTML_ . "/";
-$dirXml = $outputFileNameHead . "/";
+    $dirXmlBase = _DIR_PALI_CSV_ . "/";
+    $dirPaliTextBase = _DIR_PALI_HTML_ . "/";
+    $dirXml = $outputFileNameHead . "/";
 
-$xmlfile = $inputFileName;
-fwrite(STDOUT, "doing:" . $xmlfile . PHP_EOL);
+    $xmlfile = $inputFileName;
+    fwrite(STDOUT, "doing:" . $xmlfile . PHP_EOL);
 
-$log = $log . date("Y-m-d h:i:sa") . ",$from,$FileName,open\r\n";
+    $log = $log . date("Y-m-d h:i:sa") . ",$from,$FileName,open\r\n";
 
-$arrInserString = array();
+    $arrInserString = array();
 
-// 打开vri html文件并读取数据
-$pali_text_array = array(); //vri text
-if (($fpPaliText = fopen($dirPaliTextBase . $xmlfile, "r")) !== false) {
-    while (($data = fgets($fpPaliText)) !== false) {
-        array_push($pali_text_array, $data);
+    // 打开vri html文件并读取数据
+    $pali_text_array = array(); //vri text
+    if (($fpPaliText = fopen($dirPaliTextBase . $xmlfile, "r")) !== false) {
+        while (($data = fgets($fpPaliText)) !== false) {
+            array_push($pali_text_array, $data);
+        }
+        fclose($fpPaliText);
+        fwrite(STDOUT, "pali text load:" . $dirPaliTextBase . $xmlfile . PHP_EOL);
+    } else {
+        fwrite(STDERR, "can not pali text file. filename=" . $dirPaliTextBase . $xmlfile.PHP_EOL);
     }
-    fclose($fpPaliText);
-    fwrite(STDOUT, "pali text load:" . $dirPaliTextBase . $xmlfile . PHP_EOL);
-} else {
-    fwrite(STDERR, "can not pali text file. filename=" . $dirPaliTextBase . $xmlfile.PHP_EOL);
-}
 
-// 打开csv文件并读取数据
-$inputRow = 0;
-$tocFile = _DIR_PALI_TITLE_ . "/" . ($from + 1) . "_pali.csv";
-if (($fp = fopen($tocFile, "r")) !== false) {
-    while (($data = fgetcsv($fp, 0, ',')) !== false) {
-        if ($inputRow > 0) {
-            $params = $data;
-            array_push($arrInserString, $params);
+    // 打开csv文件并读取数据
+    $inputRow = 0;
+    $tocFile = _DIR_PALI_TITLE_ . "/" . ($from + 1) . "_pali.csv";
+    if (($fp = fopen($tocFile, "r")) !== false) {
+        while (($data = fgetcsv($fp, 0, ',')) !== false) {
+            if ($inputRow > 0) {
+                $params = $data;
+                array_push($arrInserString, $params);
+            }
+            $inputRow++;
         }
-        $inputRow++;
+        fclose($fp);
+        fwrite(STDOUT, "Toc load:" . $tocFile. PHP_EOL);
+    } else {
+        fwrite(STDERR, "can not open csv file. filename=" . $tocFile . PHP_EOL);
     }
-    fclose($fp);
-    fwrite(STDOUT, "Toc load:" . $tocFile. PHP_EOL);
-} else {
-    fwrite(STDERR, "can not open csv file. filename=" . $tocFile . PHP_EOL);
-}
 
-if ((count($arrInserString)) != count($pali_text_array) - 2) {
-    $log = $log . "$from, $FileName,error,文件行数不匹配 csv = " . (count($arrInserString) - 1) . " pali_text_array=" . (count($pali_text_array) - 2) . " \r\n";
-}
+    if ((count($arrInserString)) != count($pali_text_array) - 2) {
+        $log = $log . "$from, $FileName,error,文件行数不匹配 csv = " . (count($arrInserString) - 1) . " pali_text_array=" . (count($pali_text_array) - 2) . " \r\n";
+    }
 
-$book = $from + 1;
+    $book = $from + 1;
 
-//计算段落信息,如上一段
+    //计算段落信息,如上一段
 
-$query = "SELECT * from "._TABLE_." where book = '$book'  order by paragraph asc";
-$title_data = PDO_FetchAll($query);
-fwrite(STDOUT, "Paragraph Count:" . count($title_data) . " arrInserString:".count($arrInserString). PHP_EOL);
+    $query = "SELECT book,paragraph,level,toc,lenght from "._TABLE_." where book = '$book'  order by paragraph asc";
+    $title_data = PDO_FetchAll($query);
+    fwrite(STDOUT, "Paragraph Count:" . count($title_data) . " arrInserString:".count($arrInserString). PHP_EOL);
 
-$paragraph_count = count($title_data);
+    $paragraph_count = count($title_data);
 
-// 开始一个事务,关闭自动提交
-$PDO->beginTransaction();
-$query = "UPDATE "._TABLE_." SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ?  ,  chapter_strlen = ? , updated_at = now()  WHERE book=? and paragraph=?";
-$stmt = $PDO->prepare($query);
+    // 开始一个事务,关闭自动提交
+    $PDO->beginTransaction();
+    $query = "UPDATE "._TABLE_." SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ?  ,  chapter_strlen = ? , path = ? ,updated_at = now()  WHERE book=? and paragraph=?";
+    $stmt = $PDO->prepare($query);
 
-$paragraph_info = array();
-array_push($paragraph_info, array($from, -1, $paragraph_count, -1, -1, -1));
+    $paragraph_info = array();
+    array_push($paragraph_info, array($from, -1, $paragraph_count, -1, -1, -1));
 
 
-for ($iPar = 0; $iPar < count($title_data); $iPar++) {
-    $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
-}
+    for ($iPar = 0; $iPar < count($title_data); $iPar++) {
+        $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
+    }
 
 
-for ($iPar = 0; $iPar < count($title_data); $iPar++) {
-    $book = $from + 1;
-    $paragraph = $title_data[$iPar]["paragraph"];
+    for ($iPar = 0; $iPar < count($title_data); $iPar++) {
+        $book = $from + 1;
+        $paragraph = $title_data[$iPar]["paragraph"];
 
-/*
-level 8 为 偈诵编号。不当作标题
-*/
+    /*
+    level 8 为 偈诵编号。不当作标题
+    */
     if ((int)$title_data[$iPar]["level"] == 8) {
         $title_data[$iPar]["level"] = 100;
     }
@@ -208,6 +208,25 @@ level 8 为 偈诵编号。不当作标题
         $iChapter_strlen += $title_data[$i]["lenght"];
     }
     
+
+        $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
+        $title_data[$iPar]["toc"] = $arrInserString[$iPar][5];
+        $title_data[$iPar]["parent"] = $parent;
+        /*
+        *获取路径
+        */
+        $currParent = $parent;
+        $path = [];
+        $iLoop = 0;
+        while ($currParent != -1 && $iLoop<7) {
+            # code...
+            $pathTitle = $title_data[$currParent-1]["toc"];
+            $pathLevel = $title_data[$currParent-1]['level'];
+            $path[] = ["book"=>$book,"paragraph"=>$currParent,"title"=>$pathTitle,"level"=>$pathLevel];
+            $currParent = $title_data[$currParent-1]["parent"];
+            $iLoop++;
+        }
+
     $newData = array(
         $arrInserString[$iPar][3],
         $arrInserString[$iPar][5],
@@ -216,9 +235,11 @@ level 8 为 偈诵编号。不当作标题
         $prev,
         $parent,
         $iChapter_strlen,
+        json_encode($path),
         $book,
         $paragraph,
     );
+
     $stmt->execute($newData);
 
     if ($curr_level > 0 && $curr_level < 8) {