diff options
author | Christian Foellmann <foellmann@foe-services.de> | 2014-12-23 14:48:13 +0300 |
---|---|---|
committer | Christian Foellmann <foellmann@foe-services.de> | 2014-12-23 14:48:13 +0300 |
commit | 2bfb20e57418ebf396149782be9f98e868fe8608 (patch) | |
tree | a5ec4011410970603d3f462a535a5a359057fa77 /libraries/Error_Handler.class.php | |
parent | 20f1bf77c8281efc675a14e0f6bf52f657dabd9a (diff) |
UPDATE 4.3.34.3.3
Diffstat (limited to 'libraries/Error_Handler.class.php')
-rw-r--r-- | libraries/Error_Handler.class.php | 168 |
1 files changed, 158 insertions, 10 deletions
diff --git a/libraries/Error_Handler.class.php b/libraries/Error_Handler.class.php index 7cd6442a22..5cffd9880f 100644 --- a/libraries/Error_Handler.class.php +++ b/libraries/Error_Handler.class.php @@ -95,9 +95,21 @@ class PMA_Error_Handler } /** + * returns the errors occurred in the current run only. + * Does not include the errors save din the SESSION + * + * @return array of current errors + */ + public function getCurrentErrors() + { + return $this->errors; + } + + /** * Error handler - called when errors are triggered/occurred * * This calls the addError() function, escaping the error string + * Ignores the errors wherever Error Control Operator (@) is used. * * @param integer $errno error number * @param string $errstr error string @@ -108,6 +120,10 @@ class PMA_Error_Handler */ public function handleError($errno, $errstr, $errfile, $errline) { + // check if Error Control Operator (@) was used. + if (error_reporting() == 0) { + return; + } $this->addError($errstr, $errno, $errfile, $errline, true); } @@ -168,7 +184,6 @@ class PMA_Error_Handler // FATAL error, display it and exit $this->dispFatalError($error); exit; - break; } } @@ -192,14 +207,11 @@ class PMA_Error_Handler * * @param string $errorInfo error message * @param integer $errorNumber error number - * @param string $file file name - * @param integer $line line number * * @return void */ - public function triggerError($errorInfo, $errorNumber = null, - $file = null, $line = null - ) { + public function triggerError($errorInfo, $errorNumber = null) + { // we could also extract file and line from backtrace // and call handleError() directly trigger_error($errorInfo, $errorNumber); @@ -285,7 +297,8 @@ class PMA_Error_Handler public function getDispErrors() { $retval = ''; - if ($GLOBALS['cfg']['Error_Handler']['display']) { + // display errors if SendErrorReports is set to 'ask'. + if ($GLOBALS['cfg']['SendErrorReports'] != 'never') { foreach ($this->getErrors() as $error) { if ($error instanceof PMA_Error) { if (! $error->isDisplayed()) { @@ -301,6 +314,46 @@ class PMA_Error_Handler } else { $retval .= $this->getDispUserErrors(); } + // if preference is not 'never' and + // there are 'actual' errors to be reported + if ($GLOBALS['cfg']['SendErrorReports'] != 'never' + && $this->countErrors() != $this->countUserErrors() + ) { + // add report button. + $retval .= '<form method="post" action="error_report.php"' + . ' id="pma_report_errors_form"'; + if ($GLOBALS['cfg']['SendErrorReports'] == 'always') { + // in case of 'always', generate 'invisible' form. + $retval .= ' style="display:none;"'; + } + $retval .= '>' + . '<input type="hidden" name="token" value="' + . $_SESSION[' PMA_token '] + . '"/>' + . '<input type="hidden" name="exception_type" value="php"/>' + . '<input type="hidden" name="send_error_report" value="1" />' + . '<input type="submit" value="' + . __('Report') + . '" id="pma_report_errors" style="float: right; margin: 20px;">' + . '<input type="checkbox" name="always_send"' + . ' id="always_send_checkbox" value="true"/>' + . '<label for="always_send_checkbox">' + . __('Automatically send report next time') + . '</label>' + . '</form>'; + + if ($GLOBALS['cfg']['SendErrorReports'] == 'ask') { + // add ignore buttons + $retval .= '<input type="submit" value="' + . __('Ignore') + . '" id="pma_ignore_errors_bottom"' + . ' style="float: right; margin: 20px;">'; + } + $retval .= '<input type="submit" value="' + . __('Ignore All') + . '" id="pma_ignore_all_errors_bottom"' + . ' style="float: right; margin: 20px;">'; + } return $retval; } @@ -340,7 +393,7 @@ class PMA_Error_Handler /** * return count of errors * - * @return integer number of errors occoured + * @return integer number of errors occurred */ public function countErrors() { @@ -350,7 +403,7 @@ class PMA_Error_Handler /** * return count of user errors * - * @return integer number of user errors occoured + * @return integer number of user errors occurred */ public function countUserErrors() { @@ -393,7 +446,7 @@ class PMA_Error_Handler */ public function countDisplayErrors() { - if ($GLOBALS['cfg']['Error_Handler']['display']) { + if ($GLOBALS['cfg']['SendErrorReports'] != 'never') { return $this->countErrors(); } else { return $this->countUserErrors(); @@ -409,5 +462,100 @@ class PMA_Error_Handler { return (bool) $this->countDisplayErrors(); } + + /** + * Deletes previously stored errors in SESSION. + * Saves current errors in session as previous errors. + * Required to save current errors in case 'ask' + * + * @return void + */ + public function savePreviousErrors() + { + unset($_SESSION['prev_errors']); + $_SESSION['prev_errors'] = $GLOBALS['error_handler']->getCurrentErrors(); + } + + /** + * Function to check if there are any errors to be prompted. + * Needed because user warnings raised are + * also collected by global error handler. + * This distinguishes between the actual errors + * and user errors raised to warn user. + * + *@return boolean true if there are errors to be "prompted", false otherwise + */ + public function hasErrorsForPrompt() + { + return ( + $GLOBALS['cfg']['SendErrorReports'] != 'never' + && $this->countErrors() != $this->countUserErrors() + ); + } + + /** + * Function to report all the collected php errors. + * Must be called at the end of each script + * by the $GLOBALS['error_handler'] only. + * + * @return void + */ + + public function reportErrors() + { + // if there're no actual errors, + if (!$this->hasErrors() + || $this->countErrors() == $this->countUserErrors() + ) { + // then simply return. + return; + } + // Delete all the prev_errors in session & store new prev_errors in session + $this->savePreviousErrors(); + $response = PMA_Response::getInstance(); + $jsCode = ''; + if ($GLOBALS['cfg']['SendErrorReports'] == 'always') { + if ($response->isAjax()) { + // set flag for automatic report submission. + $response->addJSON('_sendErrorAlways', '1'); + } else { + // send the error reports asynchronously & without asking user + $jsCode .= '$("#pma_report_errors_form").submit();' + . 'PMA_ajaxShowMessage( + PMA_messages["phpErrorsBeingSubmitted"], false + );'; + // js code to appropriate focusing, + $jsCode .= '$("html, body").animate({ + scrollTop:$(document).height() + }, "slow");'; + } + } elseif ($GLOBALS['cfg']['SendErrorReports'] == 'ask') { + //ask user whether to submit errors or not. + if (!$response->isAjax()) { + // js code to show appropriate msgs, event binding & focusing. + $jsCode = 'PMA_ajaxShowMessage(PMA_messages["phpErrorsFound"]);' + . '$("#pma_ignore_errors_popup").bind("click", function() { + PMA_ignorePhpErrors() + });' + . '$("#pma_ignore_all_errors_popup").bind("click", + function() { + PMA_ignorePhpErrors(false) + });' + . '$("#pma_ignore_errors_bottom").bind("click", function() { + PMA_ignorePhpErrors() + });' + . '$("#pma_ignore_all_errors_bottom").bind("click", + function() { + PMA_ignorePhpErrors(false) + });' + . '$("html, body").animate({ + scrollTop:$(document).height() + }, "slow");'; + } + } + // The errors are already sent from the response. + // Just focus on errors division upon load event. + $response->getFooter()->getScripts()->addCode($jsCode); + } } ?> |