From d89b6daa5adceed4565e49ad443da6a051d4a9e9 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Mon, 27 Oct 2014 02:56:11 +0000 Subject: [PATCH] * finish task #2043,2094,2098. --- lib/dao/dao.class.php | 42 ++++++++++++++++++++++++++++----- module/common/lang/en.php | 1 + module/common/lang/zh-cn.php | 1 + module/extension/css/common.css | 1 + module/extension/model.php | 11 +++++---- module/mail/control.php | 2 +- module/upgrade/model.php | 5 +++- 7 files changed, 51 insertions(+), 12 deletions(-) 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

"; + $errorInfo = $e->errorInfo; + $errorCode = $errorInfo[1]; + if(strpos($ignoreCode, "|$errorCode|") === false) $return->error .= '

' . $e->getMessage() . "
THE SQL IS: $sql

"; } } if($return->error) $return->result = 'fail'; diff --git a/module/mail/control.php b/module/mail/control.php index 237ed78a6d..e69d38b4c3 100755 --- a/module/mail/control.php +++ b/module/mail/control.php @@ -161,7 +161,7 @@ class mail extends control if($_POST) { - $this->mail->send($this->post->to, $this->lang->mail->subject, $this->lang->mail->content,"", true); + $this->mail->send($this->post->to, $this->lang->mail->subject, $this->lang->mail->content, "", true); if($this->mail->isError()) { $this->view->error = $this->mail->getError(); diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 2c591b8149..bd38384936 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -622,6 +622,7 @@ class upgradeModel extends model public function execSQL($sqlFile) { $mysqlVersion = $this->loadModel('install')->getMysqlVersion(); + $ignoreCode = '|1050|1060|1062|1091|1169|'; /* Read the sql file to lines, remove the comment lines, then join theme by ';'. */ $sqls = explode("\n", file_get_contents($sqlFile)); @@ -652,7 +653,9 @@ class upgradeModel extends model } catch (PDOException $e) { - self::$errors[] = $e->getMessage() . "

The sql is: $sql

"; + $errorInfo = $e->errorInfo; + $errorCode = $errorInfo[1]; + if(strpos($ignoreCode, "|$errorCode|") === false) self::$errors[] = $e->getMessage() . "

The sql is: $sql

"; } } }