国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
8.3KB

  1. <?php
  2. /**
  3. * 系统修复工具
  4. *
  5. * @version $Id: sys_repair.php 1 22:28 2010年7月20日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__).'/config.php');
  12. CheckPurview('sys_ArcBatch');
  13. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  14. if (empty($dopost)) {
  15. $win = new OxWindow();
  16. $win->Init("sys_repair.php", "js/blank.js", "POST' enctype='multipart/form-data' ");
  17. $win->mainTitle = "系统修复工具";
  18. $wecome_info = "<a href='index_body.php'>系统主页</a> &gt; 系统错误修复工具";
  19. $win->AddTitle('本工具用于检测和修复您的系统可能存在的错误');
  20. $msg = "
  21. <table>
  22. <tr>
  23. <td>
  24. 由于手动升级时用户没运行指定的SQL语句,或自动升级的遗漏处理或处理出错,可能会导致一些错误,使用本工具会自动检测并处理<br>
  25. 本工具目前主要执行下面动作:<br>
  26. 1、修复/优化数据表;<br>
  27. 2、更新系统缓存;<br>
  28. 3、检测系统变量一致性<br>
  29. 4、检测微表与主表数据一致性<br>
  30. <br>
  31. <a href='sys_repair.php?dopost=1' class='btn btn-danger'>常规检测</a>
  32. </td>
  33. </tr>
  34. </table>
  35. ";
  36. $win->AddMsgItem("<div style='line-height:26px'>$msg</div>");
  37. $winform = $win->GetWindow('hand', '');
  38. $win->Display();
  39. exit();
  40. }
  41. /*-------------------
  42. 数据结构常规检测
  43. function 1_test_db() { }
  44. --------------------*/
  45. else if ($dopost == 1) {
  46. $win = new OxWindow();
  47. $win->Init("sys_repair.php", "js/blank.js", "POST' enctype='multipart/form-data' ");
  48. $win->mainTitle = "系统修复工具";
  49. $wecome_info = "<a href='sys_repair.php'>系统错误修复工具</a> &gt; 检测数据结构";
  50. $win->AddTitle('本工具用于检测和修复您的系统可能存在的错误');
  51. $msg = "
  52. <table>
  53. <tr>
  54. <td>
  55. <span class='text-dark'>已完成数据结构完整性检测</span>
  56. <br>
  57. 如果您系统有下面几种问题之一,请检测微表正确性:<br>
  58. 1、无法获得主键,因此无法进行后续操作<br>
  59. 2、更新数据库archives表时出错<br>
  60. 3、列表显示数据目与实际文档数不一致<br>
  61. <br>
  62. <a href='sys_repair.php?dopost=2' class='btn btn-danger'>检测数据</a>
  63. </td>
  64. </tr>
  65. </table>
  66. ";
  67. $win->AddMsgItem("<div style='line-height:26px'>$msg</div>");
  68. $winform = $win->GetWindow('hand', '');
  69. $win->Display();
  70. exit();
  71. }
  72. /*-------------------
  73. 检测微表正确性并尝试修复
  74. function 2_test_arctiny() { }
  75. --------------------*/
  76. else if ($dopost == 2) {
  77. $msg = '';
  78. $allarcnum = 0;
  79. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__archives` ");
  80. $allarcnum = $arcnum = $row['dd'];
  81. $msg .= "#@__archives 表总记录数:{$arcnum} <br>";
  82. $shtables = array();
  83. $dsql->Execute('me', " SELECT addtable FROM `#@__channeltype` WHERE id < -1 ");
  84. while ($row = $dsql->GetArray('me')) {
  85. $addtable = strtolower(trim(str_replace('#@__', $cfg_dbprefix, $row['addtable'])));
  86. if (empty($addtable)) {
  87. continue;
  88. } else {
  89. if (!isset($shtables[$addtable])) {
  90. $shtables[$addtable] = 1;
  91. $row = $dsql->GetOne("SELECT COUNT(aid) AS dd FROM `$addtable` ");
  92. $msg .= "{$addtable} 表总记录数:{$row['dd']} <br>";
  93. $allarcnum += $row['dd'];
  94. }
  95. }
  96. }
  97. $msg .= "总有效记录数:{$allarcnum} <br> ";
  98. $errall = "<a href='index_body.php' class='btn btn-success btn-sm'>完成修正</a>";
  99. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__arctiny` ");
  100. $msg .= "微统计表记录数:{$row['dd']}<br>";
  101. if ($row['dd'] == $allarcnum) {
  102. $msg .= "<span class='text-dark'>两者记录一致,无需修正</span><br>";
  103. } else {
  104. $sql = "TRUNCATE TABLE `#@__arctiny`";
  105. $dsql->ExecuteNoneQuery($sql);
  106. $msg .= "<span class='text-danger'>两者记录不一致,尝试进行简单修正</span><br>";
  107. //导入普通模型微数据
  108. $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)
  109. SELECT id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid FROM `#@__archives` ";
  110. $dsql->ExecuteNoneQuery($sql);
  111. //导入单表模型微数据
  112. foreach ($shtables as $tb => $v) {
  113. $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)
  114. SELECT aid, typeid, 0, arcrank, channel, senddate, 0, mid FROM `$tb` ";
  115. $rs = $dsql->ExecuteNoneQuery($sql);
  116. $doarray[$tb] = 1;
  117. }
  118. $row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__arctiny` ");
  119. if ($row['dd'] == $allarcnum) {
  120. $msg .= "<span class='text-dark'>修正记录成功</span><br>";
  121. } else {
  122. $msg .= "<span class='text-danger'>修正记录失败,建议进行高级综合检测</span><br>";
  123. $errall = "<a href='sys_repair.php?dopost=3' class='btn btn-danger'>结合性检测</a> ";
  124. }
  125. }
  126. UpDateCatCache();
  127. $win = new OxWindow();
  128. $win->Init("sys_repair.php", "js/blank.js", "POST' enctype='multipart/form-data' ");
  129. $win->mainTitle = "系统修复工具";
  130. $wecome_info = "<a href='sys_repair.php'>系统错误修复工具</a> &gt; 检测微表正确性";
  131. $win->AddTitle('本工具用于检测和修复您的系统可能存在的错误');
  132. $msg = "
  133. <table>
  134. <tr>
  135. <td>
  136. {$msg}
  137. <br>
  138. {$errall}
  139. </td>
  140. </tr>
  141. </table>
  142. ";
  143. $win->AddMsgItem("<div style='line-height:26px'>$msg</div>");
  144. $winform = $win->GetWindow('hand', '');
  145. $win->Display();
  146. exit();
  147. }
  148. /*-------------------
  149. 高级方式修复微表(会删除不合法主键的内容)
  150. function 3_re_arctiny() { }
  151. --------------------*/
  152. else if ($dopost == 3) {
  153. $errnum = 0;
  154. $sql = " TRUNCATE TABLE `#@__arctiny`";
  155. $dsql->ExecuteNoneQuery($sql);
  156. $sql = "SELECT arc.id, arc.typeid, arc.typeid2, arc.arcrank, arc.channel, arc.senddate, arc.sortrank, arc.mid, ch.addtable FROM `#@__archives` arc LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel ";
  157. $dsql->Execute('me', $sql);
  158. while ($row = $dsql->GetArray('me')) {
  159. $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)
  160. VALUES('{$row['id']}','{$row['typeid']}','{$row['typeid2']}','{$row['arcrank']}', '{$row['channel']}','{$row['senddate']}','{$row['sortrank']}','{$row['mid']}'); ";
  161. $rs = $dsql->ExecuteNoneQuery($sql);
  162. if (!$rs) {
  163. $addtable = trim($addtable);
  164. $errnum++;
  165. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='{$row['id']}' ");
  166. if (!empty($addtable)) $dsql->ExecuteNoneQuery("DELETE FROM `$addtable` WHERE id='{$row['id']}' ");
  167. }
  168. }
  169. //导入单表模型微数据
  170. $dsql->SetQuery("SELECT id,addtable FROM `#@__channeltype` WHERE id < -1 ");
  171. $dsql->Execute();
  172. $doarray = array();
  173. while ($row = $dsql->GetArray()) {
  174. $tb = str_replace('#@__', $cfg_dbprefix, $row['addtable']);
  175. if (empty($tb) || isset($doarray[$tb])) {
  176. continue;
  177. } else {
  178. $sql = "INSERT INTO `#@__arctiny`(id, typeid, typeid2, arcrank, channel, senddate, sortrank, mid)
  179. SELECT aid, typeid, 0, arcrank, channel, senddate, 0, mid FROM `$tb` ";
  180. $rs = $dsql->ExecuteNoneQuery($sql);
  181. $doarray[$tb] = 1;
  182. }
  183. }
  184. $win = new OxWindow();
  185. $win->Init("sys_repair.php", "js/blank.js", "POST' enctype='multipart/form-data'");
  186. $win->mainTitle = "系统修复工具";
  187. $wecome_info = "<a href='sys_repair.php'>系统错误修复工具</a> &gt; 高级综合检测修复";
  188. $win->AddTitle('本工具用于检测和修复您的系统可能存在的错误');
  189. $msg = "
  190. <table>
  191. <tr>
  192. <td>
  193. 完成所有修复操作,移除错误记录 {$errnum} 条
  194. <br>
  195. <a href='index_body.php' class='btn btn-success btn-sm'>完成修正</a>
  196. </td>
  197. </tr>
  198. </table>
  199. ";
  200. $win->AddMsgItem("<div style='line-height:26px'>$msg</div>");
  201. $winform = $win->GetWindow('hand', '');
  202. $win->Display();
  203. exit();
  204. }