Przeglądaj źródła

同步增加表

visuddhinanda 4 lat temu
rodzic
commit
27497c870e

+ 1 - 1
app/sync/login.php

@@ -36,7 +36,7 @@ if(isset($_POST["userid"]) && isset($_POST["password"]) ){
 				setcookie ( "sync_userid" ,  $_POST["userid"] , 0 ,  "/" , "" ,  false , true );
 				setcookie ( "sync_server" ,  $_POST["server"] , 0 ,  "/" , "" ,  false , true );				
 				$redis->hset("sync://key",$_POST["userid"],$arrServerMsg["key"]);
-				$output["message"]="本机登录成功<br>服务器验证成功<br>";
+				$output["message"]="本机登录成功<br>服务器验证成功<br>".$arrServerMsg["message"];
 				$output["message"].="<a href='index.php'>开始同步</a>";
 			}
 			else{

+ 41 - 10
app/sync/sync.js

@@ -1,8 +1,9 @@
 var sync_db_list = [
+	{ script: "sync/table_channel.php", count: -1, finished: 0, enable: false },
 	{ script: "sync/table_article.php", count: -1, finished: 0, enable: false },
-	{ script: "sync/table_term.php", count: -1, finished: 0, enable: false },
 	{ script: "sync/table_article_collect.php", count: -1, finished: 0, enable: false },
-	{ script: "sync/table_channel.php", count: -1, finished: 0, enable: false },
+	{ script: "sync/table_term_channel.php", count: -1, finished: 0, enable: false },
+	{ script: "sync/table_term_editor.php", count: -1, finished: 0, enable: false },
 	{ script: "sync/table_sentence.php", count: -1, finished: 0, enable: true },
 ];
 var isStop = false;
@@ -15,13 +16,13 @@ function sync_pull() {
 	sync_curr_do_db = 0;
 	isStop = false;
 	$("#sync_log").html("working"); //
-	sync_do_db($("#sync_server_address").val(), $("#sync_local_address").val(), 1);
+	sync_do_db($("#sync_server_address").val(), $("#sync_local_address").val(), 0);
 }
 function sync_push() {
 	isStop = false;
 	sync_curr_do_db = 0;
 	$("#sync_log").html("working"); //
-	sync_do_db($("#sync_local_address").val(), $("#sync_server_address").val(), 1);
+	sync_do_db($("#sync_local_address").val(), $("#sync_server_address").val(), 0);
 }
 function sync_stop() {
 	isStop = true;
@@ -29,6 +30,7 @@ function sync_stop() {
 var retryCount = 0;
 function sync_do_db(src, dest, time = 1) {
 	let size = 500;
+	//找到下一个有效的数据库
 	while (sync_db_list[sync_curr_do_db].enable == false) {
 		sync_curr_do_db++;
 		if (sync_curr_do_db >= sync_db_list.length) {
@@ -36,7 +38,16 @@ function sync_do_db(src, dest, time = 1) {
 			return;
 		}
 	}
+	if (time == 0) {
+		time = localStorage.getItem(sync_db_list[sync_curr_do_db].script + src);
+		if (time) {
+			time = parseInt(time);
+		} else {
+			time = 1;
+		}
+	}
 	if (sync_db_list[sync_curr_do_db].count < 0) {
+		//获取全部数据条数,用来绘制进度条
 		$.get(
 			"sync.php",
 			{
@@ -76,10 +87,14 @@ function sync_do_db(src, dest, time = 1) {
 					console.error(error + " data:" + data);
 					return;
 				}
+				let myDate = new Date();
+				myDate.setTime(result.time);
+
 				$("#sync_log").html(
 					$("#sync_log").html() +
 						"<div><h2>" +
 						sync_db_list[sync_curr_do_db].script +
+						myDate +
 						"</h2>" +
 						result.message +
 						"</div>"
@@ -89,12 +104,14 @@ function sync_do_db(src, dest, time = 1) {
 					return;
 				}
 				if (result.error > 0 && retryCount < 2) {
+					//失败重试
 					retryCount++;
 					sync_do_db(src, dest, time);
 					return;
 				}
 				retryCount = 0;
 				sync_db_list[sync_curr_do_db].finished += parseInt(result.src_row);
+				localStorage.setItem(sync_db_list[sync_curr_do_db].script + src, result.time);
 				if (result.src_row >= size) {
 					//没弄完,接着弄
 					sync_do_db(src, dest, result.time);
@@ -118,21 +135,35 @@ function sync_do_db(src, dest, time = 1) {
 		);
 	}
 }
+
+function db_selected(obj) {
+	let index = $(obj).attr("index");
+	sync_db_list[index].enable = obj.checked;
+}
+
 function render_progress() {
 	let html = "";
-	for (const iterator of sync_db_list) {
-		let spanWidth = parseInt((500 * iterator.finished) / iterator.count);
+	for (let index = 0; index < sync_db_list.length; index++) {
+		const element = sync_db_list[index];
+		let spanWidth = parseInt((500 * element.finished) / element.count);
+		html += "<div style='width:500px;background-color:white;color:black;'>";
+		html += "<input type='checkbox' index='" + index + "' ";
+		if (element.enable) {
+			html += "checked";
+		}
+		html += " onclick='db_selected(this)' />";
 		html +=
-			"<div style='width:500px;background-color:white;color:black;'><span style='background-color:green;display:inline-block;width:" +
+			"<span style='background-color:green;display:inline-block;width:" +
 			spanWidth +
 			"px;'>" +
-			iterator.script +
+			element.script +
 			"|" +
-			iterator.finished +
+			element.finished +
 			"/" +
-			iterator.count +
+			element.count +
 			"<span></div>";
 	}
+
 	$("#sync_result").html(html);
 }
 function login() {

+ 10 - 1
app/sync/table_article_collect.php

@@ -59,6 +59,10 @@ if (isset($_GET["op"])) {
 }
 
 switch ($op) {
+	case "sync_count":
+		$result = do_sync($input);
+		echo json_encode($result, JSON_UNESCAPED_UNICODE);
+		break;
 	case "sync":
 		$result = do_sync($input);
 		echo json_encode($result, JSON_UNESCAPED_UNICODE);
@@ -106,7 +110,12 @@ switch ($op) {
 			$output["message"]=$collection->getError();
 		}
 		echo json_encode($result, JSON_UNESCAPED_UNICODE);
-	break;	
+	break;
+	default:
+		$output["error"]=1;
+		$output["message"]="错误的操作码";	
+		echo json_encode($result, JSON_UNESCAPED_UNICODE);
+	break;
 }
 
 

+ 2 - 2
app/sync/table_sentence.php

@@ -13,7 +13,7 @@ $input = (object) [
     "sync_id" =>  ["book","paragraph","begin","end","channal"],
     "modify_time" =>  "modify_time",
     "receive_time" =>  "receive_time",
-	"where"=>"and (not (channal is null))",
+	"where"=>"and ( channal IS NOT NULL )",
     "insert" => [
         'id',
 		'block_id',
@@ -108,7 +108,7 @@ switch ($op) {
 			$result = $Sent->update($arrData);
 			if($result==false){
 				$output["error"]=1;
-				$output["message"]="修改失败";				
+				$output["message"]="修改失败";
 			}
 			else{
 				$output["error"]=0;

+ 49 - 0
app/sync/table_term_channel.php

@@ -0,0 +1,49 @@
+<?php
+//header('Content-type: application/json; charset=utf8');
+
+require_once "../path.php";
+require_once "../sync/function.php";
+
+$input = (object) [
+    "database" =>  _FILE_DB_TERM_,
+    "table" =>  "term",
+    "uuid" =>  "guid",
+    "sync_id" =>  ["pali","tag","channal"],
+    "modify_time" =>  "modify_time",
+    "receive_time" =>  "receive_time",
+	"where"=>" and ( (channal IS NOT NULL) or channal <> '') ",
+    "insert" => [
+        'guid',
+		'word',
+		'word_en',
+		'meaning',
+		'other_meaning',
+		'note',
+		'tag',
+		'create_time',
+		'owner',
+		'hit',
+		'language',
+		'receive_time',
+		'modify_time'
+    ],
+    "update" =>  [
+        "word",
+        "word_en",
+        "meaning",
+        "other_meaning",
+        "note",
+        "tag",
+        "owner",
+        "hit",
+        "language",
+        "create_time",
+		"modify_time",
+        "receive_time" 
+    ]    
+];
+
+$result = do_sync($input);
+echo json_encode($result, JSON_UNESCAPED_UNICODE);
+
+?>

+ 49 - 0
app/sync/table_term_editor.php

@@ -0,0 +1,49 @@
+<?php
+//header('Content-type: application/json; charset=utf8');
+
+require_once "../path.php";
+require_once "../sync/function.php";
+
+$input = (object) [
+    "database" =>  _FILE_DB_TERM_,
+    "table" =>  "term",
+    "uuid" =>  "guid",
+    "sync_id" =>  ["pali","tag","owner"],
+    "modify_time" =>  "modify_time",
+    "receive_time" =>  "receive_time",
+	"where"=>" and ( (channal IS NULL) or channal = '' )",
+    "insert" => [
+        'guid',
+		'word',
+		'word_en',
+		'meaning',
+		'other_meaning',
+		'note',
+		'tag',
+		'create_time',
+		'owner',
+		'hit',
+		'language',
+		'receive_time',
+		'modify_time'
+    ],
+    "update" =>  [
+        "word",
+        "word_en",
+        "meaning",
+        "other_meaning",
+        "note",
+        "tag",
+        "owner",
+        "hit",
+        "language",
+        "create_time",
+		"modify_time",
+        "receive_time" 
+    ]    
+];
+
+$result = do_sync($input);
+echo json_encode($result, JSON_UNESCAPED_UNICODE);
+
+?>

+ 49 - 0
app/sync/table_user_wbw_block.php

@@ -0,0 +1,49 @@
+<?php
+//header('Content-type: application/json; charset=utf8');
+
+require_once "../path.php";
+require_once "../sync/function.php";
+
+$input = (object) [
+    "database" =>  _FILE_DB_TERM_,
+    "table" =>  "term",
+    "uuid" =>  "guid",
+    "sync_id" =>  ["pali","tag","channal"],
+    "modify_time" =>  "modify_time",
+    "receive_time" =>  "receive_time",
+	"where"=>" and ( (channal IS NOT NULL) or channal <> '') ",
+    "insert" => [
+        'guid',
+		'word',
+		'word_en',
+		'meaning',
+		'other_meaning',
+		'note',
+		'tag',
+		'create_time',
+		'owner',
+		'hit',
+		'language',
+		'receive_time',
+		'modify_time'
+    ],
+    "update" =>  [
+        "word",
+        "word_en",
+        "meaning",
+        "other_meaning",
+        "note",
+        "tag",
+        "owner",
+        "hit",
+        "language",
+        "create_time",
+		"modify_time",
+        "receive_time" 
+    ]    
+];
+
+$result = do_sync($input);
+echo json_encode($result, JSON_UNESCAPED_UNICODE);
+
+?>