diff --git a/module/admin/control.php b/module/admin/control.php index d41b844766..e9c7b00a89 100755 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -354,6 +354,39 @@ class admin extends control $this->display(); } + /** + * 更新度量库表的索引。 + * Upgrade metriclib table index. + * + * @param int $key + * @access public + * @return void + */ + public function metriclib(int $key = 0) + { + $sql = $this->config->admin->metriclib->updateSQLs[$key] ?? ''; + if($sql) + { + set_time_limit(0); + session_write_close(); + + try + { + $this->dbh->exec($sql); + + if(isset($this->config->admin->metriclib->updateSQLs[++$key])) return $this->send(['result' => 'success', 'key' => $key]); + return $this->send(['result' => 'success']); + } + catch(PDOException $e) + { + return $this->sendError($e->getMessage()); + } + } + + $this->view->title = $this->lang->metriclib->common; + $this->display(); + } + /** * 更换表引擎为InnoDB。 * Ajax change table engine. diff --git a/module/admin/js/metriclib.ui.js b/module/admin/js/metriclib.ui.js new file mode 100644 index 0000000000..2090f7b598 --- /dev/null +++ b/module/admin/js/metriclib.ui.js @@ -0,0 +1,28 @@ +/** + * Update metriclib table structure. + */ +function updateMetriclib(key) +{ + $('#updateSQLs > #sql' + key).removeClass('hidden'); + $('#startUpdate').remove(); + + $.getJSON($.createLink('admin', 'metriclib', 'key=' + key), function(resp) + { + if(resp.result == 'success') + { + $('#sql' + key).addClass('text-success').find('.icon').toggleClass('animate-spin icon-spinner-indicator icon-check'); + if(resp.key) + { + updateMetriclib(resp.key); + } + else + { + $('#updated').removeClass('hidden'); + } + } + else + { + zui.Modal.alert(resp.message).then(() => {loadCurrentPage()}); + } + }); +} diff --git a/module/admin/ui/metriclib.html.php b/module/admin/ui/metriclib.html.php new file mode 100644 index 0000000000..9001fec774 --- /dev/null +++ b/module/admin/ui/metriclib.html.php @@ -0,0 +1,55 @@ + + * @package admin + * @link https://www.zentao.net + */ +namespace zin; + +$sqls = []; +foreach($config->admin->metriclib->updateSQLs as $key => $sql) +{ + $sqls[] = div + ( + setID('sql' . $key), + setClass('hidden'), + icon(setClass('icon icon-spinner-indicator mr-2 animate-spin')), + $sql + ); +} + +panel +( + setClass('m-auto w-2/3'), + set::title($lang->admin->metricLib), + set::headingClass('justify-start border-b'), + div + ( + setClass('mb-4'), + $lang->admin->metriclib->tips + ), + div + ( + setID('updateSQLs'), + setClass('mb-4'), + $sqls, + div + ( + setID('updated'), + setClass('text-success hidden'), + icon(setClass('icon icon-check mr-2')), + $lang->admin->metriclib->updated + ) + ), + a + ( + setID('startUpdate'), + setClass('btn primary'), + on::click('updateMetriclib(1)'), + $lang->admin->metriclib->startUpdate + ) +); \ No newline at end of file