database.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. {template 'common/header'}
  2. <ul class="we7-page-tab">
  3. <li{if $do == 'backup'} class="active"{/if}><a href="{php echo url('system/database');}">备份</a></li>
  4. <li{if $do == 'restore'} class="active"{/if}><a href="{php echo url('system/database/restore');}">还原</a></li>
  5. <li{if $do == 'trim'} class="active"{/if}><a href="{php echo url('system/database/trim');}">数据库结构整理</a></li>
  6. <li{if $do == 'optimize'} class="active"{/if}><a href="{php echo url('system/database/optimize');}">优化</a></li>
  7. <li{if $do == 'run'} class="active"{/if}><a href="{php echo url('system/database/run');}">运行SQL</a></li>
  8. <li{if $do == 'scrap_table'} class="active"{/if}><a href="{php echo url('system/database/scrap_table');}">废弃表</a></li>
  9. </ul>
  10. {if $do == 'backup'}
  11. <div class="alert we7-page-alert">
  12. <p><i class="wi wi-info-sign"></i>使用本系统备份的备份数据, 只能使用本系统来进行还原. 如果使用其他工具, 或者自行导入sql, 可能造成数据不完整或不正确.<p>
  13. <p><strong>请在站点访问量比较低的时间段(如:深夜)操作, 或操作之前关闭站点. 来防止可能出现的意外数据丢失. </strong><p>
  14. </div>
  15. <div class="form-group">
  16. <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-2 col-xs-12 col-md-10" style = "margin-top:20px">
  17. <a class="btn btn-primary span3" style = "margin-left:220px" href="{php echo url('system/database/backup', array('status'=>1,'start'=>2));}">开始备份</a>
  18. </div>
  19. </div>
  20. {/if}
  21. {if $do == 'restore'}
  22. <div class="alert we7-page-alert">
  23. <p><i class="wi wi-info-sign"></i>使用微擎系统备份的备份数据, 只能使用微擎系统来进行还原. 如果使用其他工具, 或者自行导入sql, 可能造成数据不完整或不正确.</p>
  24. <p><strong>请在站点访问量比较低的时间段(如:深夜)操作, 或操作之前关闭站点. 来防止可能出现的意外数据丢失. </strong></p>
  25. </div>
  26. <form action="" method="post" class="form-horizontal form">
  27. <table class="table we7-table table-hover site-list">
  28. <col width="285px"/>
  29. <col width="160px"/>
  30. <col width="120px"/>
  31. <col width="140px"/>
  32. <tr>
  33. <th class="text-left">备份名称</th>
  34. <th class="text-left">备份时间</th>
  35. <th>分卷数量</th>
  36. <th class="text-right">操作</th>
  37. </tr>
  38. {loop $reduction $row}
  39. <tr>
  40. <td class="text-left">{$row['bakdir']}</td>
  41. <td class="text-left">{php echo date('Y-m-d H:i:s', $row['time']);}</td>
  42. <td>{$row['volume']}</td>
  43. <td>
  44. <div class="link-group">
  45. <a href="javascript:;" onclick="confirmNotice('restore', '{$row["bakdir"]}', '{php echo date('Y-m-d H:i:s', $row['time']);}');">还原此备份</a>
  46. <a href="javascript:;" class="del" onclick="confirmNotice('delete', '{$row["bakdir"]}');">删除</a>
  47. </div>
  48. </td>
  49. </tr>
  50. {/loop}
  51. </table>
  52. <script>
  53. function confirmNotice(type, bakdir, storeTime) {
  54. if (type == 'restore') {
  55. util.confirm(function () {
  56. window.location.href = "{php echo url('system/database/restore')}" + 'restore_dirname=' + bakdir;
  57. }, function () {
  58. return false;
  59. }, '确定要将数据库数据还原到<span class="color-red">' + storeTime + '</span> 备份的数据吗? <p>还原备份数据, 数据库将被覆盖。请谨慎操作!</p>');
  60. } else {
  61. util.confirm(function () {
  62. window.location.href = "{php echo url('system/database/restore')}" + 'delete_dirname=' + bakdir;
  63. }, function () {
  64. return false;
  65. }, '确认删除备份记录? ');
  66. }
  67. }
  68. </script>
  69. </form>
  70. {/if}
  71. {if $do == 'trim'}
  72. <div class="alert we7-page-alert table-info" style="display:none;">
  73. <p><i class="wi wi-info-sign"></i><strong>恭喜,您的数据表中已无冗余信息。</strong></p>
  74. </div>
  75. <form action="" method="post" class="form-horizontal form">
  76. {if !empty($diff)}
  77. <table class="table table-hover we7-table trim-container">
  78. <thead>
  79. <tr>
  80. <th style="width:400px;">表名称</th>
  81. <th >字段</th>
  82. <th >索引</th>
  83. </tr>
  84. </thead>
  85. <tbody>
  86. {loop $diff $row}
  87. <tr>
  88. <td class="tablename">{$row['name']}</td>
  89. <td>
  90. {loop $row['fields'] $field}
  91. <div style="height:50px;" id="field{$field}">
  92. <span>{$field}</span>
  93. <a href="javascript:;" data-type="field" title="删除" class="btn btn-default btn-sm" style="float:right">删除</a>
  94. </div>
  95. {/loop}
  96. </td>
  97. <td>
  98. {loop $row['indexes'] $index}
  99. <div style="height:50px;float:right" id="index{$index}">
  100. <span>{$index}</span>
  101. <a href="javascript:;" data-type="index" title="删除" class="btn btn-danger btn-sm" >删除</a>
  102. </div>
  103. {/loop}
  104. </td>
  105. </tr>
  106. {/loop}
  107. </tbody>
  108. </table>
  109. {/if}
  110. <script type="text/javascript">
  111. if ($(".tablename").text() == '') {
  112. $(".table-info").css('display', 'block');
  113. }
  114. $(".trim-container a").click(function() {
  115. if (!confirm('删除后将彻底改变数据库信息!')) {
  116. return false;
  117. }
  118. var type = $(this).attr('data-type');
  119. var data = $(this).prev().text();
  120. var table = $(this).parent().parent().parent().children("td.tablename").text();
  121. $.post('{php echo url('system/database/trim')}', {'type' : type, 'data' : data, 'table' : table}, function(status){
  122. if (status == 'success') {
  123. $('#'+type+data).remove();
  124. }
  125. });
  126. var fields = $(this).parent().parent().children("div");
  127. var indexes = $(this).parent().parent().siblings().children("div");
  128. if (fields.length <= 1 && indexes.length < 1) {
  129. $(this).parent().parent().parent().remove();
  130. }
  131. if ($(".tablename").text() == '') {
  132. $(".table-info").css('display', 'block');
  133. }
  134. });
  135. </script>
  136. </form>
  137. {/if}
  138. {if $do == 'optimize'}
  139. <div class="alert we7-page-alert">
  140. <i class="wi wi-info-sign"></i><strong>数据表优化可以去除数据文件中的碎片, 使记录排列紧密, 提高读写速度.</strong>
  141. </div>
  142. <form action="" method="post" class="form-horizontal form">
  143. {if !empty($optimize_table)}
  144. <table class="table we7-table table-hover site-list">
  145. <col width="30px"/>
  146. <col width="100px"/>
  147. <col width="50px"/>
  148. <col width="50px"/>
  149. <col width="80px"/>
  150. <col width="80px"/>
  151. <col width="80px"/>
  152. <tr>
  153. <th>操作</th>
  154. <th>表名</th>
  155. <th>表类型</th>
  156. <th>记录数</th>
  157. <th>数据尺寸</th>
  158. <th>索引尺寸</th>
  159. <th>碎片尺寸</th>
  160. </tr>
  161. {loop $optimize_table $row}
  162. <tr>
  163. <td><input type="checkbox" name="select[]" checked="checked" value="{$row['title']}"></td>
  164. <td>{$row['title']}</td>
  165. <td>{$row['type']}</td>
  166. <td>{$row['rows']}</td>
  167. <td>{$row['data']}</td>
  168. <td>{$row['index']}</td>
  169. <td>{$row['free']}</td>
  170. </tr>
  171. {/loop}
  172. <tr>
  173. <td colspan="7" class="text-left">
  174. <button type="submit" class="btn btn-primary span3" name="submit" value="提交">开始优化</button>
  175. <input type="hidden" name="token" value="{$_W['token']}" />
  176. </td>
  177. </tr>
  178. </table>
  179. {else}
  180. <div class="alert alert-success"><strong>没有要优化的数据表</strong></div>
  181. {/if}
  182. </form>
  183. {/if}
  184. {if $do == 'run'}
  185. <div class="alert we7-page-alert">
  186. <p><i class="wi wi-info-sign"></i>通过此功能可以直接在数据库中执行特定语句, 用于调试错误. 或者系统管理员特定排错. 注意, 这里运行的语句不会有任何返回结果.</p>
  187. <p><strong>注意: 此功能可能造成数据破坏, 请谨慎使用. 如果你不清楚他的功能, 请不要使用.</strong></p>
  188. </div>
  189. <form action="" method="post" class="we7-form" onsubmit="return confirm('请确保你已经了解这些语句的作用, 并自愿承担风险.');">
  190. <div class="form-group">
  191. <label class="control-label col-sm-1">SQL</label>
  192. <div class="form-controls col-sm-8">
  193. <textarea name="sql" class="form-control" rows="8" style="width:600px;"></textarea>
  194. <span class="help-block">多条语句请使用 ; 隔开</span>
  195. </div>
  196. </div>
  197. <div class="form-group">
  198. <label class="control-label"></label>
  199. <div class="form-controls">
  200. <button type="submit" class="btn btn-primary span3" name="submit" value="提交">运行SQL</button>
  201. <input type="hidden" name="token" value="{$_W['token']}" />
  202. </div>
  203. </div>
  204. </form>
  205. {/if}
  206. {if $do == 'scrap_table'}
  207. <div id="js-database" ng-controller="databaseCtrl" ng-cloak>
  208. <div class="alert we7-page-alert">
  209. <p><i class="wi wi-info-sign"></i>以下所列为已卸载和回收站的非本地开发模块,有可能其模块表还存在,请按需检测;</p>
  210. <p><strong>注意: 此功能会造成数据破坏, 请谨慎使用. 如果你不清楚他的功能, 请不要使用.</strong></p>
  211. </div>
  212. <table class="table we7-table table-hover site-list">
  213. <col width="70px"/>
  214. <col width=""/>
  215. <col width="180px"/>
  216. <tr>
  217. <th></th>
  218. <th>应用名</th>
  219. <th class="text-left">操作</th>
  220. </tr>
  221. <tr ng-show="moduleCloud" ng-repeat="module in moduleCloud">
  222. <td><img src="{{module.logo}}" width="40px"></td>
  223. <td><span ng-bind="module.title"></span></td>
  224. <td ng-show="module.loading && !module.loaded"><img src="./resource/images/loading.gif" width="25px"><span class="color-green"> 检测中...</span></td>
  225. <td ng-show="!module.loading"><a href="JavaScript:;" ng-click="loadData(module.name)" class="color-default">检测</a></td>
  226. <td ng-show="module.loaded" class="text-left">
  227. <a href="JavaScript:;" ng-click="showDetail(module.name)" class="color-default">查看文件 </a>
  228. <a href="JavaScript:;" ng-click="loadData(module.name)" class="color-default"> 再次检测</a>
  229. </td>
  230. </tr>
  231. <tr ng-show="!moduleCloud"><td colspan="3" class="text-center"><strong>没有废弃的数据表</strong></td></tr>
  232. </table>
  233. <div class="text-right">{$pager}</div>
  234. <div class="modal fade modal-type" tabindex="-1" role="dialog" id="scrap_table_detail">
  235. <div class="modal-dialog" role="document">
  236. <div class="modal-content">
  237. <div class="modal-header clearfix">
  238. 卸载模块废弃表列表
  239. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  240. </div>
  241. <div class="modal-body">
  242. <div class="form-group" ng-repeat="table in activeModule.scrap_table" ng-show="activeModule.scrap_table">
  243. <div class="we7-padding-left color-gray" ng-bind="table"></div>
  244. </div>
  245. <div class="form-group text-center" ng-show="!activeModule.scrap_table">
  246. <div class="we7-padding color-gray">暂无冗余表结构</div>
  247. </div>
  248. </div>
  249. <div class="modal-footer" ng-show="activeModule.scrap_table">
  250. <button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="deleteScrapTable(activeModule.name)">立即删除</button>
  251. <button type="button" class="btn btn-default" data-dismiss="modal">暂不处理</button>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. <script>
  258. angular.module('systemApp').value('config', {
  259. 'moduleCloud': {php echo !empty($module_cloud) ? json_encode($module_cloud) : 'null'},
  260. 'links': {
  261. 'loadData': "{php echo url('system/database/load_scrap_table_data')}",
  262. 'deleteScrapTable': "{php echo url('system/database/delete_scrap_table')}",
  263. },
  264. });
  265. angular.bootstrap($('#js-database'), ['systemApp']);
  266. </script>
  267. {/if}
  268. {template 'common/footer'}