update_index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>Update Resouce DataBase</h2>
  7. <?php
  8. include "../public/_pdo.php";
  9. include "../public/config.php";
  10. include "../app/public.inc";
  11. if (isset($_GET["res"])) {
  12. $res_type = $_GET["res"];
  13. } else {
  14. echo "请输入资源类型";
  15. exit;
  16. }
  17. if (isset($_GET["from"])) {
  18. $from = $_GET["from"];
  19. }
  20. if (isset($_GET["to"])) {
  21. $to = $_GET["to"];
  22. }
  23. switch ($res_type) {
  24. case "palitext":
  25. echo "<h2>正在处理 - $res_type - $from</h2>";
  26. PDO_Connect("" . _FILE_DB_PALITEXT_);
  27. $query = "select * from pali_text_album where 1";
  28. $Fetch = PDO_FetchAll($query);
  29. $iFetch = count($Fetch);
  30. echo "找到album记录 $iFetch<br/>";
  31. if ($iFetch > 0 && $from < $iFetch) {
  32. $i = $from;
  33. {
  34. $album_id = $Fetch[$i]["id"];
  35. $guid = $Fetch[$i]["guid"];
  36. $title = $Fetch[$i]["title"];
  37. $file = _FILE_DB_PALITEXT_;
  38. $cover = $Fetch[$i]["cover"];
  39. $language = $Fetch[$i]["language"];
  40. $author = $Fetch[$i]["author"];
  41. $target = $Fetch[$i]["target"];
  42. $summary = $Fetch[$i]["summary"];
  43. $publish_time = $Fetch[$i]["publish_time"];
  44. $update_time = $Fetch[$i]["update_time"];
  45. $edition = $Fetch[$i]["edition"];
  46. $edition1 = $Fetch[$i]["edition_text"];
  47. $type = $Fetch[$i]["type"];
  48. PDO_Connect("" . _FILE_DB_PALITEXT_);
  49. $query = "select * from pali_text where album_index='$album_id' ";
  50. $title_data = PDO_FetchAll($query);
  51. echo "Paragraph Count:" . count($title_data) . "<br>";
  52. $query = "select count(*) from pali_text where album_index='$album_id'";
  53. $paragraph_count = PDO_FetchOne($query);
  54. // 开始一个事务,关闭自动提交
  55. $PDO->beginTransaction();
  56. $query = "UPDATE pali_text SET chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ? WHERE book=? and paragraph=?";
  57. $stmt = $PDO->prepare($query);
  58. $paragraph_info = array();
  59. array_push($paragraph_info, array($from, -1, $paragraph_count, -1, -1, -1));
  60. for ($iPar = 0; $iPar < count($title_data); $iPar++) {
  61. $book = $from + 1;
  62. $paragraph = $title_data[$iPar]["paragraph"];
  63. if ($title_data[$iPar]["level"] == 8) {
  64. $title_data[$iPar]["level"] = 100;
  65. }
  66. $curr_level = $title_data[$iPar]["level"];
  67. $length = -1;
  68. for ($iPar1 = $iPar + 1; $iPar1 < count($title_data); $iPar1++) {
  69. if ($title_data[$iPar1]["level"] <= $curr_level) {
  70. $length = $title_data[$iPar1]["paragraph"] - $paragraph;
  71. break;
  72. }
  73. }
  74. if ($length == -1) {
  75. $length = $paragraph_count - $paragraph + 1;
  76. }
  77. $prev = -1;
  78. if ($iPar > 0) {
  79. for ($iPar1 = $iPar - 1; $iPar1 >= 0; $iPar1--) {
  80. if ($title_data[$iPar1]["level"] == $curr_level) {
  81. $prev = $title_data[$iPar1]["paragraph"];
  82. break;
  83. }
  84. }
  85. }
  86. $next = -1;
  87. if ($iPar < count($title_data) - 1) {
  88. for ($iPar1 = $iPar + 1; $iPar1 < count($title_data); $iPar1++) {
  89. if ($title_data[$iPar1]["level"] == $curr_level) {
  90. $next = $title_data[$iPar1]["paragraph"];
  91. break;
  92. }
  93. }
  94. }
  95. $parent = -1;
  96. if ($iPar > 0) {
  97. for ($iPar1 = $iPar - 1; $iPar1 >= 0; $iPar1--) {
  98. if ($title_data[$iPar1]["level"] < $curr_level) {
  99. $parent = $title_data[$iPar1]["paragraph"];
  100. break;
  101. }
  102. }
  103. }
  104. $newData = array($length,
  105. $next,
  106. $prev,
  107. $parent,
  108. $book,
  109. $paragraph);
  110. $stmt->execute($newData);
  111. if ($curr_level > 0 && $curr_level < 8) {
  112. array_push($paragraph_info, array($book, $paragraph, $length, $prev, $next, $parent));
  113. }
  114. //echo "<tr><td>$book</td><td>$paragraph</td><td>$curr_level</td><td>$length</td><td>$prev</td><td>$next</td><td>$parent</td></tr>";
  115. }
  116. // 提交更改
  117. $PDO->commit();
  118. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  119. $error = PDO_ErrorInfo();
  120. echo "error - $error[2] <br>";
  121. $log = $log . "$from, $FileName, error, $error[2] \r\n";
  122. } else {
  123. $count = count($title_data);
  124. echo "updata $count paragraph info recorders.<br>";
  125. echo count($paragraph_info) . " Heading<br>";
  126. }
  127. /*
  128. */
  129. $db_file = _FILE_DB_RESRES_INDEX_;
  130. PDO_Connect("$db_file");
  131. $query = "select * from album where guid = '$guid'";
  132. $search_album = PDO_FetchAll($query);
  133. if (count($search_album) == 0) {
  134. $query = "INSERT INTO album (id,
  135. guid,
  136. title,
  137. file,
  138. cover,
  139. language,
  140. author,
  141. target,
  142. summary,
  143. publish_time,
  144. update_time,
  145. edition,
  146. edition1,
  147. type) VALUES (NULL,
  148. '$guid',
  149. '" . $title . "',
  150. '$file',
  151. '',
  152. '0',
  153. 'VRI',
  154. '',
  155. '',
  156. '1',
  157. '" . time() . "',
  158. '1',
  159. 'CSCD4',
  160. '1')";
  161. $stmt = @PDO_Execute($query);
  162. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  163. $error = PDO_ErrorInfo();
  164. print_r($error[2]);
  165. break;
  166. }
  167. //获取刚刚插入的索引号
  168. $album_index = $PDO->lastInsertId();
  169. } else {
  170. $album_index = $search_album[0]["id"];
  171. $query = "UPDATE album SET title = '$title' ,
  172. file = '$file' ,
  173. cover = '$cover' ,
  174. language = '$language' ,
  175. author = '$author' ,
  176. target = '$target' ,
  177. summary = '$summary' ,
  178. publish_time = '$publish_time' ,
  179. update_time = '$update_time' ,
  180. edition = '$edition' ,
  181. edition1 = '$edition1' ,
  182. type = '$type'
  183. WHERE guid='$guid' ";
  184. $stmt = @PDO_Execute($query);
  185. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  186. $error = PDO_ErrorInfo();
  187. print_r($error[2]);
  188. break;
  189. }
  190. }
  191. echo "开始更新索引 ", count($title_data), "<br />";
  192. //开始更新索引
  193. foreach ($title_data as $oneTitle) {
  194. if ($oneTitle["level"] > 0 && $oneTitle["level"] < 8) {
  195. $query = "select * from 'index' where album = '$album_index' and book='" . $oneTitle["book"] . "' and paragraph='" . $oneTitle["paragraph"] . "'";
  196. $search_title = PDO_FetchAll($query);
  197. $title_en = pali2english($oneTitle["text"]);
  198. //找到已有的记录 更新
  199. if (count($search_title) != 0) {
  200. $query = "UPDATE 'index' SET title = '" . $oneTitle["text"] . "' ,
  201. title_en = '" . $title_en . "' ,
  202. language = '1' ,
  203. type = '$type',
  204. editor = '1' ,
  205. share = '1' ,
  206. update_time = '" . time() . "'
  207. WHERE id='" . $search_title[0]["id"] . "' ";
  208. $stmt = @PDO_Execute($query);
  209. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  210. $error = PDO_ErrorInfo();
  211. print_r($error[2]);
  212. break;
  213. }
  214. } else {
  215. /*未找到 插入*/
  216. $book = $oneTitle["book"];
  217. if (substr($book, 0, 1) == "b") {
  218. $book = substr($book, 1);
  219. }
  220. $query = "INSERT INTO 'index' (id,
  221. book,
  222. paragraph,
  223. title,
  224. title_en,
  225. level,
  226. type,
  227. language,
  228. author,
  229. editor,
  230. share,
  231. edition,
  232. album,
  233. update_time)
  234. VALUES (NULL,
  235. '" . $book . "',
  236. '" . $oneTitle["paragraph"] . "',
  237. '" . $oneTitle["text"] . "',
  238. '" . $title_en . "',
  239. '" . $oneTitle["level"] . "',
  240. '1',
  241. '1',
  242. '5',
  243. '1',
  244. '1',
  245. '1',
  246. '$album_index',
  247. '" . time() . "')";
  248. $stmt = @PDO_Execute($query);
  249. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  250. $error = PDO_ErrorInfo();
  251. print_r($error[2]);
  252. break;
  253. }
  254. }
  255. }
  256. }
  257. foreach ($paragraph_info as $onePar) {
  258. $query = "select * from 'paragraph_info' where book='" . $onePar[0] . "' and paragraph='" . $onePar[1] . "'";
  259. $search_par = PDO_FetchAll($query);
  260. //找到已有的记录 更新
  261. if (count($search_par) != 0) {
  262. $query = "UPDATE 'paragraph_info' SET length = '" . $onePar[2] . "' ,
  263. prev = '" . $onePar[3] . "' ,
  264. next = '" . $onePar[4] . "' ,
  265. parent = '" . $onePar[5] . "'
  266. WHERE id='" . $search_par[0]["id"] . "' ";
  267. $stmt = @PDO_Execute($query);
  268. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  269. $error = PDO_ErrorInfo();
  270. print_r($error[2]);
  271. break;
  272. }
  273. } else {
  274. //未找到 插入
  275. $query = "INSERT INTO 'paragraph_info' (id,
  276. book,
  277. paragraph,
  278. length,
  279. prev,
  280. next,
  281. parent)
  282. VALUES (NULL,
  283. '" . $onePar[0] . "',
  284. '" . $onePar[1] . "',
  285. '" . $onePar[2] . "',
  286. '" . $onePar[3] . "',
  287. '" . $onePar[4] . "',
  288. '" . $onePar[5] . "')";
  289. $stmt = @PDO_Execute($query);
  290. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  291. $error = PDO_ErrorInfo();
  292. print_r($error[2]);
  293. break;
  294. }
  295. }
  296. }
  297. }
  298. }
  299. echo "insert ok<br>";
  300. if ($from >= $to) {
  301. echo "<h2>齐活!功德无量!all done!</h2>";
  302. } else {
  303. echo "<script>";
  304. echo "window.location.assign(\"update_index.php?res=palitext&from=" . ($from + 1) . "&to=" . $to . "\")";
  305. echo "</script>";
  306. echo "正在载入:" . ($from + 1);
  307. }
  308. break;
  309. case "heading":
  310. break;
  311. case "album":
  312. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  313. $query = "select * from album where 1";
  314. $search_album = PDO_FetchAll($query);
  315. foreach ($search_album as $oneAlbum) {
  316. $query = "select id from 'index' where album = '{$oneAlbum["id"]}' and
  317. book='{$oneAlbum["book"]}' and
  318. paragraph='-1'";
  319. $id = PDO_FetchAll($query);
  320. //找到已有的记录 更新
  321. $title_en = pali2english($oneAlbum["title"]);
  322. if (count($id) > 0) {
  323. $query = "UPDATE 'index' SET title = '{$oneAlbum["title"]}' ,
  324. title_en = '{$title_en}' ,
  325. language = '{$oneAlbum["language"]}' ,
  326. type = '{$oneAlbum["type"]}',
  327. editor = '1' ,
  328. share = '1' ,
  329. update_time = '" . time() . "'
  330. WHERE id='{$id[0]["id"]}' ";
  331. $stmt = @PDO_Execute($query);
  332. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  333. $error = PDO_ErrorInfo();
  334. print_r($error[2]);
  335. break;
  336. } else {
  337. echo "Updae记录成功。{$oneAlbum["title"]} <br />";
  338. }
  339. } else {
  340. /*未找到 插入*/
  341. $book = $oneAlbum["book"];
  342. $query = "INSERT INTO 'index' (id,
  343. book,
  344. paragraph,
  345. title,
  346. title_en,
  347. level,
  348. type,
  349. language,
  350. author,
  351. editor,
  352. share,
  353. edition,
  354. album,
  355. update_time)
  356. VALUES (NULL,
  357. '" . $book . "',
  358. '-1',
  359. '{$oneAlbum["title"]}',
  360. '{$title_en}',
  361. '-1',
  362. '{$oneAlbum["type"]}',
  363. '{$oneAlbum["language"]}',
  364. '{$oneAlbum["author"]}',
  365. '1',
  366. '1',
  367. '{$oneAlbum["edition"]}',
  368. '{$oneAlbum["id"]}',
  369. '" . time() . "')";
  370. $stmt = @PDO_Execute($query);
  371. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  372. $error = PDO_ErrorInfo();
  373. print_r($error[2]);
  374. break;
  375. } else {
  376. echo "新建记录成功。{$oneAlbum["title"]} <br />";
  377. }
  378. }
  379. }
  380. break;
  381. case "translation":
  382. break;
  383. case "note":
  384. break;
  385. }
  386. ?>