60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
class ToolsController extends BaseController {
|
|
|
|
function __construct()
|
|
{
|
|
if (SERVER_ENV == _ONLINE) {
|
|
die("can't create GMController");
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function clearDB()
|
|
{
|
|
global $g_conf_mysql_cluster;
|
|
foreach ($g_conf_mysql_cluster as $mysql_conf) {
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
$tables = $conn->execQueryAsArray('show tables;');
|
|
foreach ($tables as $table) {
|
|
$tblName = $table[0];
|
|
$conn->execScript("DELETE FROM {$tblName};",
|
|
arary());
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getSysTime()
|
|
{
|
|
echo phpcommon\timestamp_to_datetime(phpcommon\getNowTime());
|
|
}
|
|
|
|
public function setSysTime()
|
|
{
|
|
if (!defined('GLOBAL_TIME_OFFSET_KEY')) {
|
|
die('不支持设置系统时间');
|
|
return;
|
|
}
|
|
$newtime = strtotime($_REQUET['newtime']);
|
|
if ($newtime <= 0) {
|
|
die('时间格式错误');
|
|
return;
|
|
}
|
|
$time_offset = $newtime - phpcommon\getRealTime();
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => '127.0.0.1',
|
|
'port' => 6379,
|
|
'passwd' => ''
|
|
|
|
));
|
|
$r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset);
|
|
}
|
|
|
|
}
|