From 4b57bc9f2b1fa63555e588f6ad9c3c079725af4d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 8 Dec 2014 11:20:33 +1300 Subject: [PATCH] CRM-15678 hookable invalid page handling Conflicts: CRM/Contribute/Form/ContributionBase.php --- .../InactiveContributionPageException.php | 20 +++++++++++++++++++ CRM/Contribute/Form/ContributionBase.php | 6 +++--- CRM/Core/Error.php | 5 +++++ CRM/Utils/Hook.php | 6 ++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 CRM/Contribute/Exception/InactiveContributionPageException.php diff --git a/CRM/Contribute/Exception/InactiveContributionPageException.php b/CRM/Contribute/Exception/InactiveContributionPageException.php new file mode 100644 index 0000000000..2c8273dcb0 --- /dev/null +++ b/CRM/Contribute/Exception/InactiveContributionPageException.php @@ -0,0 +1,20 @@ +id = $id; + CRM_Core_Error::debug_log_message('inactive contribution page access attempted - page number ' . $id); + } + + public function getID() { + return $this->id; + } +} diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index a417718610..31919c8314 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -199,9 +199,11 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { /** * Set variables up before form is built * + * @throws CRM_Contribution_Exception_InactiveContributionPageException * @return void */ public function preProcess() { + $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); @@ -298,10 +300,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); - // check if form is active if (empty($this->_values['is_active'])) { - // form is inactive, die a fatal death - CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); + throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id); } // also check for billing informatin diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 8e3b01f5f4..41aba6b00a 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -396,6 +396,11 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @static */ public static function handleUnhandledException($exception) { + try { + CRM_Utils_Hook::unhandledException($exception); + } catch (Exception $other) { + // if the exception-handler generates an exception, then that sucks! oh, well. carry on. + } $config = CRM_Core_Config::singleton(); $vars = array( 'message' => $exception->getMessage(), diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 13984585b6..f7f0c01222 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1457,6 +1457,12 @@ abstract class CRM_Utils_Hook { ); } + /** + * @param CRM_Core_Exception Exception $exception + */ + static function unhandledException($exception) { + self::singleton()->invoke(1, $exception, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_unhandled_exception'); + } /** * This hook is called for declaring managed entities via API -- 2.25.1