diff --git a/lib/dao/dao.class.php b/lib/dao/dao.class.php index a029bf23d2..ad120989d0 100755 --- a/lib/dao/dao.class.php +++ b/lib/dao/dao.class.php @@ -114,6 +114,14 @@ class dao */ public $method; + /** + * The sql code of need repair table. + * + * @var string + * @access public + */ + public $repairCode = '|1034|1035|1194|1195|1459|'; + /** * The queries executed. Every query will be saved in this array. * @@ -269,7 +277,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "
The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } $sql = 'SELECT FOUND_ROWS() as recTotal;'; @@ -500,7 +508,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } } @@ -541,7 +549,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } $pager->setRecTotal($row->recTotal); @@ -572,7 +580,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } } @@ -768,7 +776,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } } else @@ -981,7 +989,7 @@ class dao } catch (PDOException $e) { - $this->app->triggerError($e->getMessage() . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + $this->sqlError($e); } foreach($rawFields as $rawField) @@ -1028,6 +1036,28 @@ class dao } return $fields; } + + /** + * Process SQL error by code. + * + * @param object $exception + * @access public + * @return void + */ + public function sqlError($exception) + { + $errorInfo = $exception->errorInfo; + $errorCode = $errorInfo[1]; + $errorMsg = $errorInfo[2]; + $message = $exception->getMessage(); + if(strpos($this->repairCode, "|$errorCode|") !== false or + ($errorCode == '1016' and strpos($errorMsg, 'errno: 145') !== false)) + { + $message .= ' ' . $this->lang->repairTable; + } + $sql = $this->sqlobj->get(); + $this->app->triggerError($message . "The sql is: $sql
", __FILE__, __LINE__, $exit = true); + } } /** diff --git a/module/common/lang/en.php b/module/common/lang/en.php index 1b31e2f3f2..a430e7d08f 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -61,6 +61,7 @@ $lang->addFiles = 'Add Files'; $lang->files = 'Files '; $lang->pasteText = 'Paste text'; $lang->timeout = 'Timed out, please check the network, or retry!'; +$lang->repairTable = 'The table may be damaged, you can perform bin/checkdb on the command line to try to repair!'; $lang->duplicate = '%s has the same title'; $lang->unfold = '+'; $lang->fold = '-'; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index bc49a03104..2674c6aae0 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -61,6 +61,7 @@ $lang->addFiles = '上传了附件 '; $lang->files = '附件 '; $lang->pasteText = '粘贴文本 '; $lang->timeout = '连接超时,请检查网络环境,或重试!'; +$lang->repairTable = '数据库表可能损坏,需要修复,可以在命令行执行bin目录下的checkdb尝试修复!'; $lang->duplicate = '已有相同标题的%s'; $lang->unfold = '+'; $lang->fold = '-'; diff --git a/module/extension/css/common.css b/module/extension/css/common.css index 0036253ef1..38df857d73 100644 --- a/module/extension/css/common.css +++ b/module/extension/css/common.css @@ -1,2 +1,3 @@ .alert-link:hover {text-decoration: underline;} .alert {width: 100%; display: table;} +code{padding-left:0px;} diff --git a/module/extension/model.php b/module/extension/model.php index 3f128a62b1..6ea7b12b3a 100644 --- a/module/extension/model.php +++ b/module/extension/model.php @@ -480,9 +480,9 @@ class extensionModel extends model } if($return->errors) $return->result = 'fail'; - $return->mkdirCommands = str_replace('/', DIRECTORY_SEPARATOR, $return->mkdirCommands); + $return->mkdirCommands = '' . str_replace('/', DIRECTORY_SEPARATOR, $return->mkdirCommands) . '';
$return->errors .= $this->lang->extension->executeCommands . $return->mkdirCommands;
- if(PHP_OS == 'Linux') $return->errors .= $return->chmodCommands;
+ if(PHP_OS == 'Linux') $return->errors .= '' . $return->chmodCommands . '';
return $return;
}
@@ -707,6 +707,7 @@ class extensionModel extends model
$return = new stdclass();
$return->result = 'ok';
$return->error = '';
+ $ignoreCode = '|1050|1060|1062|1091|1169|';
$dbFile = $this->getDBFile($extension, $method);
if(!file_exists($dbFile)) return $return;
@@ -724,9 +725,11 @@ class extensionModel extends model
{
$this->dbh->query($sql);
}
- catch (PDOException $e)
+ catch(PDOException $e)
{
- $return->error .= '' . $e->getMessage() . "
THE SQL IS: $sql
' . $e->getMessage() . "
THE SQL IS: $sql
The sql is: $sql
"; + $errorInfo = $e->errorInfo; + $errorCode = $errorInfo[1]; + if(strpos($ignoreCode, "|$errorCode|") === false) self::$errors[] = $e->getMessage() . "The sql is: $sql
"; } } }