Explorar o código

增加异常处理 更改表定义为配置字符串

visuddhinanda %!s(int64=4) %!d(string=hai) anos
pai
achega
695176cc31

+ 20 - 12
app/admin/word_index_weight_refresh.php

@@ -5,11 +5,19 @@
 require_once __DIR__.'/../config.php';
 require_once __DIR__.'/word_index_weight_table.php';
 
-define("_PG_DB_WORD_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_WORD_INDEX_", "word_indexs");
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
 
-define("_PG_DB_PALI_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_WORD_", "words");
+
+define("__DB_WORD_INDEX__", _PG_DB_WORD_INDEX_);
+define("__TABLE_WORD_INDEX__", _PG_TABLE_WORD_INDEX_);
+
+define("__DB_PALI_INDEX__", _PG_DB_PALI_INDEX_);
+define("__TABLE_WORD__", _PG_TABLE_WORD_);
 
 if (isset($_GET["from"])) {
     $from = (int)$_GET["from"];
@@ -26,17 +34,17 @@ if (isset($_GET["from"])) {
     }
 }
 
-$dh_word = new PDO( _PG_DB_WORD_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
+$dh_word = new PDO( __DB_WORD_INDEX__, _DB_USERNAME_, _DB_PASSWORD_);
 $dh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
-$dh_pali = new PDO( _PG_DB_PALI_INDEX_, _DB_USERNAME_, _DB_PASSWORD_);
+$dh_pali = new PDO( __DB_PALI_INDEX__, _DB_USERNAME_, _DB_PASSWORD_);
 $dh_pali->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 echo "from=$from to = $to \n";
 for ($i = $from; $i <= $to; $i++) {
     $time_start = microtime(true);
     echo "正在处理 book= $i ";
-    $query = "SELECT max(paragraph) from "._PG_TABLE_WORD_." where book=?";
+    $query = "SELECT max(paragraph) from ".__TABLE_WORD__." where book=?";
 	try {
 		//code...
 		$stmt = $dh_pali->prepare($query);
@@ -52,11 +60,11 @@ for ($i = $from; $i <= $to; $i++) {
         echo "段落数量:$max_para ";
         for ($j = 0; $j <= $max_para; $j++) {
             # code...
-            $query = "SELECT id,book,wordindex,bold from "._PG_TABLE_WORD_." where book={$i} and paragraph={$j} order by id ASC";
+            $query = "SELECT id,book,wordindex,bold from ".__TABLE_WORD__." where book={$i} and paragraph={$j} order by id ASC";
             $stmt = $dh_pali->query($query);
             $fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
-            $query = "SELECT wordindex,count(*) as co from "._PG_TABLE_WORD_." where book={$i} and paragraph={$j} group by wordindex";
+            $query = "SELECT wordindex,count(*) as co from ".__TABLE_WORD__." where book={$i} and paragraph={$j} group by wordindex";
             $stmt = $dh_pali->query($query);
             $fetch_voc = $stmt->fetchAll(PDO::FETCH_ASSOC);
 			
@@ -96,7 +104,7 @@ for ($i = $from; $i <= $to; $i++) {
                     $bold_count = $end - $begin + 1;
                     if ($bold_count == 1) {
 
-                        $query = "SELECT * from "._PG_TABLE_WORD_INDEX_." where id=" . $fetch[$iWord]["wordindex"];
+                        $query = "SELECT * from ".__TABLE_WORD_INDEX__." where id=" . $fetch[$iWord]["wordindex"];
                         $stmt_word = $dh_word->query($query);
                         $wordinfo = $stmt_word->fetch(PDO::FETCH_ASSOC);
                         $bookId = (int) $fetch[$iWord]["book"];
@@ -114,7 +122,7 @@ for ($i = $from; $i <= $to; $i++) {
                         for ($iBold = $begin; $iBold <= $end; $iBold++) {
                             # code...
                             $boldid = $fetch[$iBold]["wordindex"];
-                            $query = "SELECT len from "._PG_TABLE_WORD_INDEX_." where id=" . $boldid;
+                            $query = "SELECT len from ".__TABLE_WORD_INDEX__." where id=" . $boldid;
                             $stmt_bold = $dh_word->query($query);
                             $wordbold = $stmt_bold->fetch(PDO::FETCH_ASSOC);
                             $len_sum += $wordbold["len"];
@@ -130,7 +138,7 @@ for ($i = $from; $i <= $to; $i++) {
             }
             # 将整段权重写入据库
             $dh_pali->beginTransaction();
-            $query = "UPDATE "._PG_TABLE_WORD_." set weight = ? where id=? ";
+            $query = "UPDATE ".__TABLE_WORD__." set weight = ? , updated_at = now() where id=? ";
             $stmt_weight = $dh_pali->prepare($query);
             foreach ($fetch as $key => $value) {
                 $stmt_weight->execute(array($value["weight"], $value["id"]));

+ 9 - 4
app/install/db_insert_bookword_from_csv_cli.php

@@ -3,8 +3,13 @@
 生成 巴利原文段落表
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
 
 echo "Insert Pali Text To DB".PHP_EOL;
 
@@ -30,8 +35,8 @@ $fileNums = 0;
 $log = "";
 
 //PostgreSQL
-define("_DB_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_", "book_words");
+define("_DB_",_PG_DB_BOOK_WORD_);
+define("_TABLE_", _PG_TABLE_BOOK_WORD_);
 
 global $dbh_word_index;
 $dns = _DB_;
@@ -82,7 +87,7 @@ for ($from=$_from-1; $from < $_to; $from++) {
     }else{
         // 开始一个事务,关闭自动提交
         $dbh_word_index->beginTransaction();
-        $query = "INSERT INTO "._TABLE_." (book , wordindex , count) VALUES ( ? , ? , ?  )";
+        $query = "INSERT INTO "._TABLE_." (book , wordindex , count , created_at,updated_at) VALUES ( ? , ? , ? , now(),now() )";
         $stmt = $dbh_word_index->prepare($query);
 
         foreach ($bookword as $key => $value) {

+ 11 - 6
app/install/db_insert_palitext_cli.php

@@ -3,10 +3,15 @@
 生成 巴利原文段落表
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 
-define("_PG_DB_PALITEXT_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_PALI_TEXT_","pali_texts");
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+define("_DB_", _PG_DB_PALITEXT_);
+define("_TABLE_",_PG_TABLE_PALI_TEXT_);
 
 echo "Insert Pali Text To DB".PHP_EOL;
 
@@ -40,7 +45,7 @@ if ($to == 0 || $to >= $fileNums) {
     $to = $fileNums - 1;
 }
 
-$dns = _PG_DB_PALITEXT_;
+$dns = _DB_;
 $dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
@@ -109,7 +114,7 @@ for ($from=$_from-1; $from < $to; $from++) {
     }
     
     #删除 旧数据
-    $query = "DELETE FROM "._PG_TABLE_PALI_TEXT_." WHERE book=?";
+    $query = "DELETE FROM "._TABLE_." WHERE book=?";
 	$stmt = $dbh->prepare($query);
 	try{
 		$stmt->execute(array($from+1));
@@ -122,7 +127,7 @@ for ($from=$_from-1; $from < $to; $from++) {
     // 开始一个事务,关闭自动提交
     $dbh->beginTransaction();
     
-    $query = "INSERT INTO "._PG_TABLE_PALI_TEXT_." ( book , paragraph , level , class , toc , text , html , lenght ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
+    $query = "INSERT INTO "._TABLE_." ( book , paragraph , level , class , toc , text , html , lenght , created_at,updated_at ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? ,now(),now() )";
     $stmt = $dbh->prepare($query);
     foreach ($arrInserString as $oneParam) {
         if ($oneParam[3] < 100) {

+ 7 - 7
app/install/db_insert_templet_cli.php

@@ -3,7 +3,6 @@
 用拆分好的三藏数据 生成模板库
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 
 set_exception_handler(function($e){
 	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
@@ -29,8 +28,8 @@ if ($_to > 217) {
 
 
 #pg
-define("_DB_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_","wbw_templates");
+define("_DB_", _PG_DB_PALICANON_TEMPLET_);
+define("_TABLE_",_PG_TABLE_PALICANON_TEMPLET_);
 
 
 $filelist = array();
@@ -100,7 +99,7 @@ for ($from=$_from; $from <=$_to ; $from++) {
 	$row=0;
 	// 开始一个事务,关闭自动提交
 	$dbh->beginTransaction();
-	$query = "INSERT INTO "._TABLE_." ( book , paragraph, wid , word , real , type , gramma , part , style ) VALUES (?,?,?,?,?,?,?,?,?)";
+	$query = "INSERT INTO "._TABLE_." ( book , paragraph, wid , word , real , type , gramma , part , style, created_at,updated_at ) VALUES (?,?,?,?,?,?,?,?,?,now(),now())";
 	$stmt = $dbh->prepare($query);
 	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
 		$error = $dbh->errorInfo();
@@ -152,15 +151,16 @@ for ($from=$_from; $from <=$_to ; $from++) {
 
 		$log = "$from, $FileName, error, $error[2] \r\n";
 		//fwrite($myLogFile, $log);
+		exit(1);
 	} else {
 		
 		echo "updata $row recorders.".PHP_EOL;
-	}
-
-
 
+	}
 }
 
+exit();
+
 
 
 

+ 11 - 4
app/install/db_insert_word_from_csv_cli.php

@@ -3,8 +3,16 @@
 生成 巴利原文段落表
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
+define("_DB_", _PG_DB_PALI_INDEX_);
+define("_TABLE_", _PG_TABLE_WORD_);
 
 echo "Insert Word To DB".PHP_EOL;
 
@@ -28,8 +36,7 @@ $filelist = array();
 $fileNums = 0;
 $log = "";
 
-define("_DB_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_", "words");
+
 
 global $dbh_word_index;
 $dns = _DB_;
@@ -62,7 +69,7 @@ for ($from=$_from-1; $from < $_to; $from++) {
     if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) {
         // 开始一个事务,关闭自动提交
         $dbh_word_index->beginTransaction();
-        $query = "INSERT INTO "._TABLE_." ( sn , book , paragraph , wordindex , bold ) VALUES (?,?,?,?,?)";
+        $query = "INSERT INTO "._TABLE_." ( sn , book , paragraph , wordindex , bold ,created_at,updated_at ) VALUES (?,?,?,?,?,now(),now())";
         $stmt = $dbh_word_index->prepare($query);
 
         $count = 0;

+ 14 - 7
app/install/db_insert_wordindex_from_csv_cli.php

@@ -3,8 +3,17 @@
 生成 巴利原文段落表
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
+//PostgreSQL
+define("_DB_", _PG_DB_WORD_INDEX_);
+define("_TABLE_", _PG_TABLE_WORD_INDEX_);
 
 echo "Insert Word Index To DB".PHP_EOL;
 
@@ -12,11 +21,9 @@ echo "Insert Word Index To DB".PHP_EOL;
 $dirLog = _DIR_LOG_ . "/";
 $log = "";
 
-//PostgreSQL
-define("_DB_WORD_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_", "word_indexs");
 
-$dns = _DB_WORD_INDEX_;
+
+$dns = _DB_;
 $dbh_word_index = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
@@ -40,8 +47,8 @@ try{
 
                 // 开始一个事务,关闭自动提交
                 $dbh_word_index->beginTransaction();
-                $query = "INSERT INTO "._TABLE_." (id , word , word_en , count , normal , bold , is_base , len ) 
-				                            VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)";
+                $query = "INSERT INTO "._TABLE_." (id , word , word_en , count , normal , bold , is_base , len , created_at,updated_at ) 
+				                            VALUES ( ?, ?, ?, ?, ?, ?, ?, ? , now(), now())";
 				try{
 					$stmt = $dbh_word_index->prepare($query);
 				}catch(PDOException $e){

+ 11 - 4
app/install/db_update_palitext_cli.php

@@ -3,10 +3,17 @@
 生成 巴利原文段落表
  */
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
+require_once __DIR__."/../public/_pdo.php";
 
-define("_DB_PALITEXT_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_","pali_texts");
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
+define("_DB_PALITEXT_", _PG_DB_PALITEXT_);
+define("_TABLE_",_PG_TABLE_PALI_TEXT_);
 
 echo "Update Pali Text ".PHP_EOL;
 
@@ -115,7 +122,7 @@ $paragraph_count = count($title_data);
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query = "UPDATE "._TABLE_." SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ?  ,  chapter_strlen = ?  WHERE book=? and paragraph=?";
+$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);
 
 $paragraph_info = array();

+ 10 - 4
app/install/db_update_toc_cli.php

@@ -1,10 +1,16 @@
 <?php
 require_once __DIR__."/../config.php";
-require_once __DIR__.'/../public/_pdo.php';
 require_once __DIR__."/../public/function.php";
 
-define("_DB_RES_INDEX_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_TABLE_","res_indexs");
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
+define("_DB_RES_INDEX_", _PG_DB_RESRES_INDEX_);
+define("_TABLE_",_PG_TABLE_RES_INDEX_);
 
 echo "Update toc to res_index".PHP_EOL;
 
@@ -105,7 +111,7 @@ for ($from=$_from-1; $from < $_to; $from++) {
     
     // 开始一个事务,关闭自动提交
     $dbh->beginTransaction();
-    $query = "INSERT INTO \""._TABLE_."\" (book , paragraph, title, title_en , level, type , language , author , share , create_time , update_time  ) VALUES (  ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+    $query = "INSERT INTO \""._TABLE_."\" (book , paragraph, title, title_en , level, type , language , author , share , create_time , update_time,created_at,updated_at  ) VALUES (  ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,now(),now())";
     try{
 	$stmt = $dbh->prepare($query);
 	}catch(PDOException $e){