Explorar el Código

:bug: 加错误处理

visuddhinanda hace 4 años
padre
commit
a8f51ba3c2

+ 9 - 5
public/deploy/migaration/20211125155700_pali_sent_org.php

@@ -1,11 +1,15 @@
 <?php
 require_once __DIR__."/../../app/config.php";
 
-define("_PG_DB_PALI_SENTENCE_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_PALI_SENT_ORG_", "pali_sent_orgs");
+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;
+});
 
-$src_db=_SRC_DB_PALI_SENTENCE_;#源数据库
-$src_table=_TABLE_SRC_PALI_SENT_;#源表名
+$src_db=_SQLITE_DB_PALI_SENTENCE_;#源数据库
+$src_table=_SQLITE_TABLE_PALI_SENT_;#源表名
 
 $dest_db=_PG_DB_PALI_SENTENCE_;#目标数据库
 $dest_table=_PG_TABLE_PALI_SENT_ORG_;#目标表名
@@ -39,7 +43,7 @@ echo "begin Transaction".PHP_EOL;
 
 $PDO_DEST->beginTransaction();
 
-$query = "INSERT INTO ".$dest_table." (id, book , paragraph , word_begin , word_end , length , count , text , html,sim_sents ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? ,?)";
+$query = "INSERT INTO ".$dest_table." (id, book , paragraph , word_begin , word_end , length , count , text , html,sim_sents  ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? ,?)";
 try{
 	$stmtDEST = $PDO_DEST->prepare($query);
 }catch(PDOException $e){

+ 17 - 15
public/deploy/migaration/20211125165700-pali_sent-upgrade.php

@@ -1,10 +1,12 @@
 <?php
 require_once __DIR__."/../../app/config.php";
 
-
-define("_PG_DB_PALI_SENTENCE_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_PALI_SENT_", "pali_sentences");
-define("_PG_TABLE_PALI_SENT_ORG_", "pali_sent_orgs");
+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;
+});
 
 $src_db=_PG_DB_PALI_SENTENCE_;#源数据库
 $src_table=_PG_TABLE_PALI_SENT_ORG_;#源表名
@@ -51,7 +53,7 @@ try{
 }
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true order by id asc";
+$query = "SELECT *  FROM ".$src_table." order by id asc";
 try{
 	$stmtSrc = $PDO_SRC->prepare($query);
 	$stmtSrc->execute();
@@ -65,20 +67,20 @@ $currMergeCell = 1;
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
 	#插入目标表
 	$currData = array(
-					(int)$srcData["id"],
-					(int)$srcData["book"],
-					(int)$srcData["paragraph"],
-					(int)$srcData["word_begin"],
-					(int)$srcData["word_end"],
-					(int)$srcData["length"],
-					(int)$srcData["count"],
+					$srcData["id"],
+					$srcData["book"],
+					$srcData["paragraph"],
+					$srcData["word_begin"],
+					$srcData["word_end"],
+					$srcData["length"],
+					$srcData["count"],
 					$srcData["text"],
 					$srcData["html"],
 					$srcData["sim_sents"]);
-	if($srcData["cell"]==1 ){
+	if($srcData["merge"]==1 ){
 		$stmtDEST->execute($currData);
-	}else if($srcData["cell"]>1){
-		$currMergeCell = (int)$srcData["cell"];
+	}else if($srcData["merge"]>1){
+		$currMergeCell = $srcData["merge"];
 		$data = $currData;
 	}else{
 		$data["word_end"] = $srcData["word_end"];

+ 7 - 5
public/deploy/migaration/20211126220400-pali_sent_index-upgrade.php

@@ -1,11 +1,13 @@
 <?php
 require_once __DIR__."/../../app/config.php";
-
-define("_PG_DB_PALI_SENTENCE_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_PALI_SENT_", "pali_sentences");
-
+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;
+});
 $dest_db = _PG_DB_PALI_SENTENCE_;#目标数据库
-$dest_table = _TABLE_PALI_SENT_INDEX_;#目标表名
+$dest_table = _PG_TABLE_PALI_SENT_INDEX_;#目标表名
 
 echo "migarate pali_sent_index".PHP_EOL;
 

+ 21 - 17
public/deploy/migaration/20211127214800_sent_sim.php

@@ -1,14 +1,18 @@
 <?php
 require_once __DIR__."/../../app/config.php";
 
-define("_PG_DB_PALI_SENTENCE_SIM_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_SENT_SIM_", "sent_sims");
+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;
+});
 
-$src_db=_SRC_DB_PALI_SENTENCE_SIM_;#源数据库
-$src_table=_TABLE_SRC_SENT_SIM_;#源表名
+$src_db = _SQLITE_DB_PALI_SENTENCE_SIM_;#源数据库
+$src_table = _SQLITE_TABLE_SENT_SIM_;#源表名
 
-$dest_db=_PG_DB_PALI_SENTENCE_SIM_;#目标数据库
-$dest_table=_PG_TABLE_SENT_SIM_;#目标表名
+$dest_db = _PG_DB_PALI_SENTENCE_SIM_;#目标数据库
+$dest_table = _PG_TABLE_SENT_SIM_;#目标表名
 
 echo "migarate sent_sim".PHP_EOL;
 #打开源数据库
@@ -23,14 +27,11 @@ echo "open dest".PHP_EOL;
 
 #删除目标表中所有数据
 fwrite(STDOUT,"deleting date".PHP_EOL) ;
-try{
-	$query = "DELETE FROM ".$dest_table;
-	$stmt = $PDO_DEST->prepare($query);
-	$stmt->execute();
-}catch(PDOException $e){
-	fwrite(STDERR,"error:".$e->getMessage());
-	exit;
-}
+
+$query = "DELETE FROM ".$dest_table;
+$stmt = $PDO_DEST->prepare($query);
+$stmt->execute();
+
 fwrite(STDOUT,"deleted date".PHP_EOL) ;
 
 // 开始一个事务,关闭自动提交
@@ -48,12 +49,13 @@ try{
 }
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 try{
 	$stmtSrc = $PDO_SRC->prepare($query);
 	$stmtSrc->execute();
 }catch(PDOException $e){
-	fwrite(STDERR,"error:".$e->getMessage());
+	fwrite(STDERR,"error:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
 	exit;
 }
 
@@ -67,7 +69,9 @@ while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
 	try{					
 		$stmtDEST->execute($data);		
 	}catch(PDOException $e){
-		fwrite(STDERR,"error:".$e->getMessage().implode(',',$data));
+		fwrite(STDERR,"error:".$e->getMessage().PHP_EOL);
+		fwrite(STDERR,"error-data:".implode(',',$data).PHP_EOL);
+		fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
 		exit;
 	}
 		

+ 6 - 3
public/deploy/migaration/20211127214900-sent_sim_index.php

@@ -1,9 +1,12 @@
 <?php
 require_once __DIR__."/../../app/config.php";
 
-define("_PG_DB_PALI_SENTENCE_SIM_", _DB_ENGIN_.":host="._DB_HOST_.";port="._DB_PORT_.";dbname="._DB_NAME_.";user="._DB_USERNAME_.";password="._DB_PASSWORD_.";");
-define("_PG_TABLE_SENT_SIM_", "sent_sims");
-define("_PG_TABLE_SENT_SIM_INDEX_", "sent_sim_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;
+});
 
 $dest_db = _PG_DB_PALI_SENTENCE_SIM_;#目标数据库
 $dest_table = _PG_TABLE_SENT_SIM_INDEX_;#目标表名

+ 15 - 10
public/deploy/migaration/20211202084900_init_pali_serieses.php

@@ -4,8 +4,12 @@
 */
 require_once __DIR__."/../../app/config.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_BOOK_NAME_","books");
+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;
+});
 
 $src_file=_DIR_PALI_TITLE_."/pali_serieses.csv";#源数据
 
@@ -43,7 +47,7 @@ echo "begin Transaction".PHP_EOL;
 
 $PDO_DEST->beginTransaction();
 
-$query = "INSERT INTO ".$dest_table." (id, book , paragraph , title ) VALUES ( ? , ? , ? , ? )";
+$query = "INSERT INTO ".$dest_table." ( book , paragraph , title ) VALUES (  ? , ? , ? )";
 try{
 	$stmtDEST = $PDO_DEST->prepare($query);
 }catch(PDOException $e){
@@ -58,16 +62,17 @@ $count = 0;
 while (($data = fgetcsv($fp, 0, ',')) !== false){
 	if($row>0){
 		#插入目标表
-		$date= array(
-			(int)$data[0],
-			(int)$data[1],
-			(int)$data[2],
-			$data[3],
+		$rowData= array(
+			$data[1],
+			$data[2],
+			$data[3]
 		);
 		try{					
-			$stmtDEST->execute($data);		
+			$stmtDEST->execute($rowData);		
 		}catch(PDOException $e){
-			fwrite(STDERR,"error:".$e->getMessage().implode(',',$data));
+			fwrite(STDERR,"error:".$e->getMessage().PHP_EOL);
+			fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+			fwrite(STDERR,"error-data:".implode(',',$rowData).PHP_EOL);
 			exit;
 		}
 		$count++;