Changeset View
Changeset View
Standalone View
Standalone View
core/kernel/utility/logger.php
Show First 20 Lines • Show All 921 Lines • ▼ Show 20 Line(s) | |||||
$this->_handlers[$is_exception ? self::LL_CRITICAL : self::LL_ERROR]->add($handler); | $this->_handlers[$is_exception ? self::LL_CRITICAL : self::LL_ERROR]->add($handler); | ||||
} | } | ||||
/** | /** | ||||
* SQL Error Handler | * SQL Error Handler | ||||
* | * | ||||
* When not debug mode, then fatal database query won't break anything. | * When not debug mode, then fatal database query won't break anything. | ||||
* | * | ||||
* @param int $code | * @param integer $code Error code. | ||||
* @param string $msg | * @param string $msg Error message. | ||||
* @param string $sql | * @param string $sql SQL query. | ||||
* @return bool | * @param boolean|null $throw_exception Throw an exception. | ||||
* @access public | * | ||||
* @throws RuntimeException | * @return boolean | ||||
* @throws RuntimeException In CLI mode or while in the Debug Mode. | |||||
*/ | */ | ||||
public function handleSQLError($code, $msg, $sql) | public function handleSQLError($code, $msg, $sql, $throw_exception = null) | ||||
{ | { | ||||
$error_msg = self::shortenMessage(self::DB_ERROR_PREFIX . ' #' . $code . ' - ' . $msg . '. SQL: ' . trim($sql)); | $error_msg = self::shortenMessage(self::DB_ERROR_PREFIX . ' #' . $code . ' - ' . $msg . '. SQL: ' . trim($sql)); | ||||
if ( $throw_exception === true ) { | |||||
throw new RuntimeException($error_msg); | |||||
} | |||||
if ( isset($this->Application->Debugger) ) { | if ( isset($this->Application->Debugger) ) { | ||||
if ( kUtil::constOn('DBG_SQL_FAILURE') && !defined('IS_INSTALL') ) { | if ( kUtil::constOn('DBG_SQL_FAILURE') && !defined('IS_INSTALL') ) { | ||||
throw new RuntimeException($error_msg); | throw new RuntimeException($error_msg); | ||||
} | } | ||||
else { | |||||
// To show trace above the warning message. | |||||
$this->Application->Debugger->appendTrace(); | $this->Application->Debugger->appendTrace(); | ||||
} | } | ||||
} | |||||
if ( PHP_SAPI === 'cli' ) { | if ( PHP_SAPI === 'cli' ) { | ||||
throw new RuntimeException($error_msg); | throw new RuntimeException($error_msg); | ||||
} | } | ||||
// Next line also trigger attached error handlers. | // Next line also trigger attached error handlers. | ||||
trigger_error($error_msg, E_USER_WARNING); | trigger_error($error_msg, E_USER_WARNING); | ||||
▲ Show 20 Lines • Show All 582 Lines • Show Last 20 Lines |