diff --git a/framework/router.class.php b/framework/router.class.php index eaa4b64b7d..a4e284cac3 100755 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -38,7 +38,30 @@ class router extends baseRouter if($moduleName == 'common') { $productProject = false; - if($this->dbh and !empty($this->config->db->name)) $productProject = $this->dbh->query('SELECT value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productProject'")->fetch(); + if($this->dbh and !empty($this->config->db->name)) + { + try + { + $productProject = $this->dbh->query('SELECT value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productProject'")->fetch(); + } + catch (PDOException $exception) + { + $repairCode = '|1034|1035|1194|1195|1459|'; + $errorInfo = $exception->errorInfo; + $errorCode = $errorInfo[1]; + $errorMsg = $errorInfo[2]; + $message = $exception->getMessage(); + if(strpos($repairCode, "|$errorCode|") !== false or ($errorCode == '1016' and strpos($errorMsg, 'errno: 145') !== false) or strpos($message, 'repair') !== false) + { + global $config; + if(isset($config->framework->autoRepairTable) and $config->framework->autoRepairTable) + { + header("location: " . $config->webRoot . 'checktable.php'); + exit; + } + } + } + } $productCommon = $projectCommon = 0; if($productProject) diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index 5c6343402f..567fc3569e 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -1311,7 +1311,7 @@ class baseDAO if(strpos($this->repairCode, "|$errorCode|") !== false or ($errorCode == '1016' and strpos($errorMsg, 'errno: 145') !== false) or strpos($message, 'repair') !== false) { global $config; - if(isset($config->framework->autoRepairTable) and $config->framework->autoRepairTable) die(js::locate(helper::createLink('misc', 'checkTable'), 'top')); + if(isset($config->framework->autoRepairTable) and $config->framework->autoRepairTable) die(js::locate($config->webRoot . 'checktable.php', 'top')); $message .= ' ' . $this->lang->repairTable; } $sql = $this->sqlobj->get(); diff --git a/www/checktable.php b/www/checktable.php new file mode 100644 index 0000000000..62f607d9ca --- /dev/null +++ b/www/checktable.php @@ -0,0 +1,106 @@ + +webRoot; +$themeRoot = $webRoot . "theme/"; + +$type = !isset($_GET['type']) ? 'check' : $_GET['type']; +if($type != 'check' and $type != 'repair') die(); +if(!isset($_SESSION['checkFileName'])) +{ + $checkFileName = dirname(__FILE__) . DS . uniqid('repair_') . '.txt'; + $_SESSION['checkFileName'] = $checkFileName; +} + +$checkFileName = $_SESSION['checkFileName']; + +$status = ''; +if(!file_exists($checkFileName) or (time() - filemtime($checkFileName)) > 60 * 10) $status = 'createFile'; + +$lang = new stdclass(); +$lang->misc = new stdclass(); +include '../module/misc/lang/zh-cn.php'; +if($status == 'createFile') +{ + $lang->user = new stdclass(); + $lang->projectCommon = ''; + include '../module/user/lang/zh-cn.php'; +} +else +{ + $dsn = "mysql:host={$config->db->host}; port={$config->db->port}; dbname={$config->db->name}"; + $dbh = new PDO($dsn, $config->db->user, $config->db->password, array(PDO::ATTR_PERSISTENT => $config->db->persistant)); + $dbh->exec("SET NAMES {$config->db->encoding}"); + + $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $tables = array(); + $stmt = $dbh->query("show full tables"); + while($table = $stmt->fetch(PDO::FETCH_ASSOC)) + { + $tableName = $table["Tables_in_{$config->db->name}"]; + $tableType = strtolower($table['Table_type']); + if($tableType == 'base table') + { + $tableStatus = $dbh->query("$type table $tableName")->fetch(); + $tables[$tableName] = strtolower($tableStatus->Msg_text); + } + } + $status = 'check'; +} +?> + + + + + + + ' type='text/css' media='screen' /> + + +
misc->repairTable;?>
+
+ +
+ user->noticeResetFile, $_SESSION['checkFileName']);?> +
+

' class='btn'>

+ +
+ + + + + + + + + + + $tableStatus):?> + + + + + + + + + + + + + +
misc->tableName?>misc->tableStatus?>
'>myisamchk -r -f {$tableName}.MYI进行修复。"?>
' class='btn btn-primary'>misc->needRepair?>
+
+ +
+ +