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. $db_file = _FILE_DB_PALITEXT_;
  40. PDO_Connect("$db_file");
  41. $query = "select * from pali_text where book = '{$book}' and level > 0 and level < 8";
  42. $title_data = PDO_FetchAll($query);
  43. echo "par count:" . count($title_data) . "<br>";
  44. $par_list = "";
  45. foreach ($title_data as $oneTitle) {
  46. $par_list .= " , " . $oneTitle["paragraph"] . " ";
  47. }
  48. $par_list = substr($par_list, 3);
  49. $db_file = "../appdata/palicanon/translate/$dbfile.db3";
  50. PDO_Connect("$db_file");
  51. $query = "select * from data where album='$album_id' and paragraph in ($par_list)";
  52. echo $query . "<br>";
  53. $paragraph_list = PDO_FetchAll($query);
  54. $db_file = _FILE_DB_RESRES_INDEX_;
  55. PDO_Connect("$db_file");
  56. $query = "select * from album where guid = '$guid'";
  57. $search_album = PDO_FetchAll($query);
  58. if (count($search_album) == 0) {
  59. $query = "INSERT INTO album (id,
  60. guid,
  61. title,
  62. file,
  63. cover,
  64. language,
  65. author,
  66. target,
  67. summary,
  68. publish_time,
  69. update_time,
  70. edition,
  71. edition1,
  72. type) VALUES (NULL,
  73. '$guid',
  74. '" . $title . "',
  75. '$file',
  76. '',
  77. '0',
  78. '$author',
  79. '',
  80. '',
  81. '1',
  82. '" . time() . "',
  83. '1',
  84. '$edition1',
  85. '1')";
  86. $stmt = @PDO_Execute($query);
  87. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  88. $error = PDO_ErrorInfo();
  89. print_r($error[2]);
  90. break;
  91. }
  92. //获取刚刚插入的索引号
  93. $album_index = $PDO->lastInsertId();
  94. } else {
  95. $album_index = $search_album[0]["id"];
  96. $query = "UPDATE album SET title = '$title' ,
  97. file = '$file' ,
  98. cover = '$cover' ,
  99. language = '$language' ,
  100. author = '$author' ,
  101. target = '$target' ,
  102. summary = '$summary' ,
  103. publish_time = '$publish_time' ,
  104. update_time = '$update_time' ,
  105. edition = '$edition' ,
  106. edition1 = '$edition1' ,
  107. type = '$type'
  108. WHERE guid='$guid' ";
  109. $stmt = @PDO_Execute($query);
  110. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  111. $error = PDO_ErrorInfo();
  112. print_r($error[2]);
  113. break;
  114. }
  115. }
  116. echo "开始更新索引 " . count($paragraph_list) . "<br />";
  117. //开始更新索引
  118. for ($iPar = 0; $iPar < count($paragraph_list); $iPar++) {
  119. $oneTitle = $paragraph_list[$iPar];
  120. $query = "select * from 'index' where album = '$album_index' and book='" . $book . "' and paragraph='" . $paragraph_list[$iPar]["paragraph"] . "'";
  121. $search_title = PDO_FetchAll($query);
  122. $title_en = $oneTitle["text"];
  123. //找到已有的记录 更新
  124. if (count($search_title) != 0) {
  125. $query = "UPDATE 'index' SET title = '" . $oneTitle["text"] . "' ,
  126. title_en = '" . $title_en . "' ,
  127. language = '1' ,
  128. type = '$type',
  129. editor = '1' ,
  130. share = '1' ,
  131. update_time = '" . time() . "'
  132. WHERE id='" . $search_title[0]["id"] . "' ";
  133. $stmt = @PDO_Execute($query);
  134. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  135. $error = PDO_ErrorInfo();
  136. print_r($error[2]);
  137. break;
  138. }
  139. } else { /*未找到 插入*/
  140. if (substr($book, 0, 1) == "b") {
  141. $book = substr($book, 1);
  142. }
  143. $query = "INSERT INTO 'index' (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. ?>