Just discovered the PEAR_Error handling function in index.php. Duh.

Renamed the Action functions to throw an exception like it. I still
think it probably makes sense to have the callback defined in both
places for finer control.
This commit is contained in:
Zach Copley 2009-02-11 22:08:20 -08:00
parent 9f035e2847
commit 616bdd43a9
3 changed files with 24 additions and 19 deletions

View File

@ -489,7 +489,7 @@ class EmailsettingsAction extends AccountSettingsAction
}
/**
* Check old fashioned PEAR_Error msgs coming from DB_DataObject
* Handle old fashioned PEAR_Error msgs coming from DB_DataObject
*
* In this case email don't exist in the DB yet, so DB_DataObject
* throws an error. Overrided from Action.
@ -499,13 +499,13 @@ class EmailsettingsAction extends AccountSettingsAction
* @return nothing
*/
function checkDB_DataObjectError($error) {
function handleError($error) {
if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
// Do nothing.
} else {
parent::checkDB_DataObjectError($error);
parent::handleError($error);
}
}

View File

@ -229,7 +229,7 @@ class RegisterAction extends Action
}
/**
* Check old fashioned PEAR_Error msgs coming from DB_DataObject
* Handle old fashioned PEAR_Error msgs coming from DB_DataObject
*
* In this case nickname and email don't exist in the DB yet,
* so DB_DataObject throws an error. Overrided from Action.
@ -239,13 +239,13 @@ class RegisterAction extends Action
* @return nothing
*/
function checkDB_DataObjectError($error) {
function handleError($error) {
if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
// Do nothing.
} else {
parent::checkDB_DataObjectError($error);
parent::handleError($error);
}
}

View File

@ -82,16 +82,10 @@ class Action extends HTMLOutputter // lawsuit
*/
function prepare($argarray)
{
// This is for checking PEAR_Errors raised by DB_DataObject.
// Setting this to PEAR_ERROR_CALLBACK because setting
// to PEAR_ERROR_EXCEPTION does't work to allow PEAR_Errors
// to be handled as PHP5 exceptions, and PEAR_ERROR_RETURN
// does not cause DB_DataObject to actually return PEAR_Errors
// that can be checked with PEAR::isError() -- instead
// they just disappear into the ether, and can only be checked for
// after the fact. -- Zach
// For PEAR_Errors comming from DB_DataObject
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK,
array($this, "checkDB_DataObjectError"));
array($this, "handleError"));
$this->args =& common_copy_args($argarray);
return true;
@ -856,7 +850,7 @@ class Action extends HTMLOutputter // lawsuit
}
/**
* Check old fashioned PEAR_Error msgs coming from DB_DataObject
* Handle old fashioned PEAR_Error msgs coming from DB_DataObject
*
* Logs the DB_DataObject error. Override to do something else.
*
@ -865,9 +859,20 @@ class Action extends HTMLOutputter // lawsuit
* @return nothing
*/
function checkDB_DataObjectError($error) {
common_log(LOG_ERR, $error->getMessage());
// XXX: throw an exception here? --Zach
function handleError($error) {
common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
$msg = sprintf(_('The database for %s isn\'t responding correctly, '.
'so the site won\'t work properly. '.
'The site admins probably know about the problem, '.
'but you can contact them at %s to make sure. '.
'Otherwise, wait a few minutes and try again.'),
common_config('site', 'name'),
common_config('site', 'email'));
$dac = new DBErrorAction($msg, 500);
$dac->showPage();
exit(-1);
}
/**