2
0

update_translate.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>Change DB</h2>
  7. <?php
  8. include "./_pdo.php";
  9. include "./config.php";
  10. include "../app/public.inc";
  11. $dbfile = $_GET["file"];
  12. $from = $_GET["from"];
  13. $to = $_GET["to"];
  14. echo "<h2>$from</h2>";
  15. {
  16. $db_file = "../appdata/palicanon/translate/$dbfile.db3";
  17. PDO_Connect("$db_file");
  18. $query = "select * from album where 1";
  19. $Fetch = PDO_FetchAll($query);
  20. $iFetch = count($Fetch);
  21. echo "找到album记录 $iFetch<br/>";
  22. if ($iFetch > 0) {
  23. for ($i = 0; $i < $iFetch; $i++) {
  24. $album_id = $Fetch[$i]["id"];
  25. $book = $Fetch[$i]["book"];
  26. $guid = $Fetch[$i]["guid"];
  27. $title = $Fetch[$i]["title"];
  28. $file = $Fetch[$i]["file"];
  29. $cover = $Fetch[$i]["cover"];
  30. $language = $Fetch[$i]["language"];
  31. $author = $Fetch[$i]["author"];
  32. $target = $Fetch[$i]["target"];
  33. $summary = $Fetch[$i]["summary"];
  34. $publish_time = $Fetch[$i]["publish_time"];
  35. $update_time = $Fetch[$i]["update_time"];
  36. $edition = $Fetch[$i]["edition"];
  37. $edition1 = $Fetch[$i]["edition1"];
  38. $type = $Fetch[$i]["type"];
  39. PDO_Connect(_FILE_DB_PALITEXT_);
  40. $query = "select * from pali_text where book = '{$book}' and level > 0 and level < 8";
  41. $title_data = PDO_FetchAll($query);
  42. echo "par count:" . count($title_data) . "<br>";
  43. $par_list = "";
  44. foreach ($title_data as $oneTitle) {
  45. $par_list .= " , " . $oneTitle["paragraph"] . " ";
  46. }
  47. $par_list = substr($par_list, 3);
  48. $db_file = "../appdata/palicanon/translate/$dbfile.db3";
  49. PDO_Connect("$db_file");
  50. $query = "select * from data where album='$album_id' and paragraph in ($par_list)";
  51. echo $query . "<br>";
  52. $paragraph_list = PDO_FetchAll($query);
  53. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  54. $query = "select * from album where guid = '$guid'";
  55. $search_album = PDO_FetchAll($query);
  56. if (count($search_album) == 0) {
  57. $query = "INSERT INTO album (id,
  58. guid,
  59. title,
  60. file,
  61. cover,
  62. language,
  63. author,
  64. target,
  65. summary,
  66. publish_time,
  67. update_time,
  68. edition,
  69. edition1,
  70. type) VALUES (NULL,
  71. '$guid',
  72. '" . $title . "',
  73. '$file',
  74. '',
  75. '0',
  76. '$author',
  77. '',
  78. '',
  79. '1',
  80. '" . time() . "',
  81. '1',
  82. '$edition1',
  83. '1')";
  84. $stmt = @PDO_Execute($query);
  85. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  86. $error = PDO_ErrorInfo();
  87. print_r($error[2]);
  88. break;
  89. }
  90. //获取刚刚插入的索引号
  91. $album_index = $PDO->lastInsertId();
  92. } else {
  93. $album_index = $search_album[0]["id"];
  94. $query = "UPDATE album SET title = '$title' ,
  95. file = '$file' ,
  96. cover = '$cover' ,
  97. language = '$language' ,
  98. author = '$author' ,
  99. target = '$target' ,
  100. summary = '$summary' ,
  101. publish_time = '$publish_time' ,
  102. update_time = '$update_time' ,
  103. edition = '$edition' ,
  104. edition1 = '$edition1' ,
  105. type = '$type'
  106. WHERE guid='$guid' ";
  107. $stmt = @PDO_Execute($query);
  108. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  109. $error = PDO_ErrorInfo();
  110. print_r($error[2]);
  111. break;
  112. }
  113. }
  114. echo "开始更新索引 " . count($paragraph_list) . "<br />";
  115. //开始更新索引
  116. for ($iPar = 0; $iPar < count($paragraph_list); $iPar++) {
  117. $oneTitle = $paragraph_list[$iPar];
  118. $query = "select * from \""._TABLE_RES_INDEX_."\" where album = '$album_index' and book='" . $book . "' and paragraph='" . $paragraph_list[$iPar]["paragraph"] . "'";
  119. $search_title = PDO_FetchAll($query);
  120. $title_en = $oneTitle["text"];
  121. //找到已有的记录 更新
  122. if (count($search_title) != 0) {
  123. $query = "UPDATE \""._TABLE_RES_INDEX_."\" SET title = '" . $oneTitle["text"] . "' ,
  124. title_en = '" . $title_en . "' ,
  125. language = '1' ,
  126. type = '$type',
  127. editor = '1' ,
  128. share = '1' ,
  129. update_time = '" . time() . "'
  130. WHERE id='" . $search_title[0]["id"] . "' ";
  131. $stmt = @PDO_Execute($query);
  132. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  133. $error = PDO_ErrorInfo();
  134. print_r($error[2]);
  135. break;
  136. }
  137. } else {
  138. # 未找到 插入
  139. if (substr($book, 0, 1) == "b") {
  140. $book = substr($book, 1);
  141. }
  142. $query = "INSERT INTO \""._TABLE_RES_INDEX_."\"
  143. (id,
  144. book,
  145. paragraph,
  146. title,
  147. title_en,
  148. level,
  149. type,
  150. language,
  151. author,
  152. editor,
  153. share,
  154. edition,
  155. album,
  156. update_time)
  157. VALUES (NULL,
  158. '" . $book . "',
  159. '" . $oneTitle["paragraph"] . "',
  160. '" . $oneTitle["text"] . "',
  161. '" . $title_en . "',
  162. '" . $title_data[$iPar]["level"] . "',
  163. '$type',
  164. '$language',
  165. '1',
  166. '1',
  167. '1',
  168. '1',
  169. '$album_index',
  170. '" . time() . "')";
  171. $stmt = @PDO_Execute($query);
  172. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  173. $error = PDO_ErrorInfo();
  174. print_r($error[2]);
  175. break;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. echo "insert ok<br>";
  182. }
  183. if ($from >= $to) {
  184. echo "<h2>齐活!功德无量!all done!</h2>";
  185. } else {
  186. echo "<script>";
  187. echo "window.location.assign(\"update_translate.php?from=" . ($from + 1) . "&to=" . $to . "\")";
  188. echo "</script>";
  189. echo "正在载入:" . ($from + 1);
  190. }
  191. ?>