Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commits for review: Add php Error Reporting Functionality to PMA #1207

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7bdad8e
Add script that will report all the errors of current-script-run. Thi…
JayNakrani May 9, 2014
b137255
Include error reporitng script at the end of index.php. Corrosponding…
JayNakrani May 9, 2014
0cc6c30
Add standard pma code for the library files. Add comments explaining …
JayNakrani May 11, 2014
44ee4d8
Add another parameter to existing js error reporting code.
JayNakrani May 23, 2014
74f61dc
Report errors based on user preference. All the cases taken care of.
JayNakrani May 23, 2014
80d86e0
Add appropriate msgs & js functions to handle user actions.
JayNakrani May 23, 2014
0f46e06
Fix Syntax errors.
JayNakrani May 24, 2014
e956817
Make "Ignore All" button work on login page.
JayNakrani May 25, 2014
29345e1
Remove unnecessary file.
JayNakrani May 26, 2014
0215f1a
Send only(without HTML) error message string.
JayNakrani May 27, 2014
d08ef1d
Send only backtrace (not displayBacktrace). Change getBacktrace to re…
JayNakrani May 28, 2014
56ee831
Fix failing existing PHPUnit tests.
JayNakrani Jun 3, 2014
27bd1f3
Remove unnecessary code. A deliberate error & local error-reporting-s…
JayNakrani Jun 3, 2014
628280b
Improve Error Message.
JayNakrani Jun 3, 2014
c6e582f
Include error reporting script at the end of all the 'relevant' scripts.
JayNakrani Jun 3, 2014
0ec4a2d
Stop false alarms (displaying prompts-reporting form and reporting fo…
JayNakrani Jun 5, 2014
bef9527
Move error reporting code to a separate function 'PMA_Error_Handler::…
JayNakrani Jun 7, 2014
0491058
Remove included 'common_error_reporting.php' script and its inclusion…
JayNakrani Jun 7, 2014
d25a83c
Make automatic php error report submission ('sendErrorReport'='always…
JayNakrani Jun 7, 2014
8e66074
Display appropriate msg while automatically submitting php error report.
JayNakrani Jun 7, 2014
1fd02dc
Fix coding style issues.
JayNakrani Jun 8, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions browse_foreigners.php
Expand Up @@ -63,4 +63,5 @@
);

$response->addHtml($html);

?>
1 change: 1 addition & 0 deletions db_create.php
Expand Up @@ -133,4 +133,5 @@
include_once '' . $cfg['DefaultTabDatabase'];
}
}

?>
1 change: 1 addition & 0 deletions db_printview.php
Expand Up @@ -177,4 +177,5 @@
echo PMA_Util::getButton();

echo "<div id='PMA_disable_floating_menubar'></div>\n";

?>
1 change: 1 addition & 0 deletions db_qbe.php
Expand Up @@ -129,4 +129,5 @@
}

$response->addHTML($db_qbe->getSelectionForm($cfgRelation));

?>
1 change: 1 addition & 0 deletions db_search.php
Expand Up @@ -60,4 +60,5 @@
);
$response->addHTML($db_search->getSelectionForm($url_params));
$response->addHTML($db_search->getResultDivs());

?>
232 changes: 165 additions & 67 deletions error_report.php
Expand Up @@ -10,86 +10,184 @@

$response = PMA_Response::getInstance();

if (isset($_REQUEST['send_error_report'])
&& $_REQUEST['send_error_report'] == true
if (isset($_REQUEST['exception_type'])
&& $_REQUEST['exception_type'] == 'js'
) {
$server_response = PMA_sendErrorReport(PMA_getReportData(false));
if (isset($_REQUEST['send_error_report'])
&& $_REQUEST['send_error_report'] == true
) {
$server_response = PMA_sendErrorReport(PMA_getReportData(false, 'js'));

if ($server_response === false) {
$success = false;
} else {
$decoded_response = json_decode($server_response, true);
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
}
if ($server_response === false) {
$success = false;
} else {
$decoded_response = json_decode($server_response, true);
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
}

if (isset($_REQUEST['automatic'])
&& $_REQUEST['automatic'] === "true"
) {
if ($success) {
$response->addJSON(
'message',
PMA_Message::error(
__(
'An error has been detected and an error report has been '
. 'automatically submitted based on your settings.'
if (isset($_REQUEST['automatic'])
&& $_REQUEST['automatic'] === "true"
) {
if ($success) {
$response->addJSON(
'message',
PMA_Message::error(
__(
'An error has been detected and an error report has been '
. 'automatically submitted based on your settings.'
)
. '<br />'
. __('You may want to refresh the page.')
)
. '<br />'
. __('You may want to refresh the page.')
)
);
);
} else {
$response->addJSON(
'message',
PMA_Message::error(
__(
'An error has been detected and an error report has been '
. 'generated but failed to be sent.'
)
. ' '
. __(
'If you experience any '
. 'problems please submit a bug report manually.'
)
. '<br />'
. __('You may want to refresh the page.')
)
);
}
} else {
$response->addJSON(
'message',
PMA_Message::error(
__(
'An error has been detected and an error report has been '
. 'generated but failed to be sent.'
if ($success) {
$response->addJSON(
'message',
PMA_Message::success(
__('Thank you for submitting this report.')
. '<br />'
. __('You may want to refresh the page.')
)
. ' '
. __(
'If you experience any '
. 'problems please submit a bug report manually.'
);
} else {
$response->addJSON(
'message',
PMA_Message::error(
__('Thank you for submitting this report.')
. ' '
. __('Unfortunately the submission failed.')
. ' '
. __(
'If you experience any '
. 'problems please submit a bug report manually.'
)
. '<br />'
. __('You may want to refresh the page.')
)
. '<br />'
. __('You may want to refresh the page.')
)
);
);
}
if (isset($_REQUEST['always_send'])
&& $_REQUEST['always_send'] === "true"
) {
PMA_persistOption("SendErrorReports", "always", "ask");
}
}
} elseif (! empty($_REQUEST['get_settings'])) {
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
} else {
if ($success) {
$response->addJSON(
'message',
PMA_Message::success(
__('Thank you for submitting this report.')
. '<br />'
. __('You may want to refresh the page.')
)
);
$response->addHTML(PMA_getErrorReportForm());
}
} elseif (isset($_REQUEST['exception_type'])
&& $_REQUEST['exception_type'] == 'php'
) {
if (isset($_REQUEST['send_error_report'])
&& $_REQUEST['send_error_report'] == '1'
) {
/**
* Prevent inifnite error submission.
* Happens in case error submissions fails.
* If reporting is done in some time interval,
* just clear them & clear json data too.
*/
if (isset($_SESSION['prev_error_subm_time'])
&& isset($_SESSION['error_subm_count'])
&& $_SESSION['error_subm_count'] >= 3 // max 4 attempts
&& ($_SESSION['prev_error_subm_time']-time()) <= 3000 // in 3 seconds
) {
$_SESSION['error_subm_count'] = 0;
$_SESSION['prev_errors'] = '';
$response = PMA_Response::getInstance();
$response->addJSON('_stopErrorReportLoop', '1');
} else {
$response->addJSON(
'message',
PMA_Message::error(
__('Thank you for submitting this report.')
. ' '
. __('Unfortunately the submission failed.')
. ' '
. __(
'If you experience any '
. 'problems please submit a bug report manually.'
)
. '<br />'
. __('You may want to refresh the page.')
)
$_SESSION['prev_error_subm_time'] = time();
$_SESSION['error_subm_count'] = (
(isset($_SESSION['error_subm_count']))
? ($_SESSION['error_subm_count']+1)
: (0)
);
}
if (isset($_REQUEST['always_send'])
&& $_REQUEST['always_send'] === "true"
) {
PMA_persistOption("SendErrorReports", "always", "ask");

$reportData = PMA_getReportData(false, 'php');
// report if and only if there were 'actual' errors.
if ($reportData) {
$server_response = PMA_sendErrorReport($reportData);
if ($server_response === false) {
$success = false;
} else {
$decoded_response = json_decode($server_response, true);
$success = !empty($decoded_response) ? $decoded_response["success"] : false;
}

if ($GLOBALS['cfg']['SendErrorReports'] == 'ask') {
if ($success) {
$errSubmitMsg = PMA_Message::error(
__('Thank You for subitting error report!!')
. '<br/>'
. __('Report has been succesfully submitted.')
);
} else {
$errSubmitMsg = PMA_Message::error(
__('Thank You for subitting error report!!')
. '<br/>'
. __(' Unfortunately submission failed.')
. '<br/>'
. __(' If you experience any problems please submit a bug report manually.')
);
}
} elseif ($GLOBALS['cfg']['SendErrorReports'] == 'always') {
if ($success) {
$errSubmitMsg = PMA_Message::error(
__(
'An error has been detected on the server'
. ' and an error report has been '
. 'automatically submitted based on your settings.'
)
);
} else {
$errSubmitMsg = PMA_Message::error(
__(
'An error has been detected and an error report has been '
. 'generated but failed to be sent.'
)
. '<br/>'
. __('If you experience any problems please submit a bug report manually.')
);
}
}

if ($response->isAjax()) {
$response->addJSON('_errSubmitMsg', $errSubmitMsg);
} else {
$jsCode = 'PMA_ajaxShowMessage("<div class=\"error\">'
. $errSubmitMsg
. '</div>", false);';
$response->getFooter()->getScripts()->addCode($jsCode);
}
}
}
} elseif (! empty($_REQUEST['get_settings'])) {
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
// clear previous errors & save new ones.
$GLOBALS['error_handler']->savePreviousErrors();
} else {
$response->addHTML(PMA_getErrorReportForm());
die('Oops, something went wrong!!');
}

?>
1 change: 1 addition & 0 deletions file_echo.php
Expand Up @@ -68,4 +68,5 @@
}
echo file_get_contents($_FILES['file']['tmp_name']);
}

?>
1 change: 1 addition & 0 deletions gis_data_editor.php
Expand Up @@ -421,4 +421,5 @@ function escape($variable)

PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
ob_end_clean();

?>
1 change: 1 addition & 0 deletions import.php
Expand Up @@ -665,4 +665,5 @@
$active_page = $goto;
include '' . $goto;
}

?>
1 change: 1 addition & 0 deletions import_status.php
Expand Up @@ -98,4 +98,5 @@
} else {
PMA_importAjaxStatus($_GET["id"]);
}

?>
1 change: 1 addition & 0 deletions index.php
Expand Up @@ -662,4 +662,5 @@ function PMA_printListItem($name, $listId = null, $url = null,
}
echo '</li>';
}

?>
19 changes: 19 additions & 0 deletions js/ajax.js
Expand Up @@ -325,11 +325,30 @@ var AJAX = {
}

$('#pma_errors').remove();

var msg = '';
if(data._errSubmitMsg){
msg = data._errSubmitMsg;
}
if (data._errors) {
$('<div/>', {id : 'pma_errors'})
.insertAfter('#selflink')
.append(data._errors);
// In case of 'sendErrorReport'='always'
// submit the hidden error reporting form.
if (data._sendErrorAlways == '1'
&& data._stopErrorReportLoop != '1'
) {
$("#pma_report_errors_form").submit();
PMA_ajaxShowMessage(PMA_messages['phpErrorsBeingSubmitted'], false);
} else if (data._promptPhpErrors) {
// otherwise just prompt user if it is set so.
msg = msg + PMA_messages['phpErrorsFound'];
// scroll to bottom where all the erros are displayed.
$('html, body').animate({scrollTop:$(document).height()}, 'slow');
}
}
PMA_ajaxShowMessage(msg, false);

if (typeof AJAX._callback === 'function') {
AJAX._callback.call();
Expand Down
6 changes: 4 additions & 2 deletions js/error_report.js
Expand Up @@ -22,7 +22,8 @@ var ErrorReport = {
$.get("error_report.php", {
ajax_request: true,
token: PMA_commonParams.get('token'),
get_settings: true
get_settings: true,
exception_type: 'js'
}, function (data) {
if (!data.success === true) {
PMA_ajaxShowMessage(data.error, false);
Expand Down Expand Up @@ -226,7 +227,8 @@ var ErrorReport = {
"token": PMA_commonParams.get('token'),
"exception": exception,
"current_url": window.location.href,
"microhistory": ErrorReport._get_microhistory()
"microhistory": ErrorReport._get_microhistory(),
"exception_type": 'js'
};
if (typeof AJAX.cache.pages[AJAX.cache.current - 1] !== 'undefined') {
report_data.scripts = AJAX.cache.pages[AJAX.cache.current - 1].scripts.map(
Expand Down
21 changes: 21 additions & 0 deletions js/functions.js
Expand Up @@ -4160,3 +4160,24 @@ function checkNumberOfFields() {

return true;
}

/**
* Ignore the displayed php errors.
* Simply removes the displayed errors.
*
*/
function PMA_ignorePhpErrors(clearPrevErrors){
if (typeof clearPrevErrors === "undefined" || clearPrevErrors === null) {
str = false;
}
// send AJAX request to error_report.php with send_error_report=0, exception_type=php & token.
// It clears the prev_errors stored in session.
if(clearPrevErrors){
$('#pma_report_errors_form input[name="send_error_report"]').val(0); // change send_error_report to '0'
$('#pma_report_errors_form').submit();
}

// remove dislayed errors
$('#pma_errors').fadeOut( "slow");
$('#pma_errors').remove();
}