From 698e7b0e1d11d58624cf66430cbecc442592078a 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 --- .../InactiveContributionPageException.php | 20 +++++++++++++++++++ CRM/Contribute/Form/ContributionBase.php | 8 ++++---- CRM/Core/Error.php | 5 +++++ CRM/Utils/Hook.php | 6 ++++++ 4 files changed, 35 insertions(+), 4 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 36a6913f85..29b3102ab5 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -190,10 +190,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { /** * Function to set variables up before form is built * + * @throws CRM_Contribution_Exception_InactiveContributionPageException * @return void * @access public */ public function preProcess() { + $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); @@ -279,10 +281,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 (!CRM_Utils_Array::value('is_active', $this->_values)) { - // form is inactive, die a fatal death - CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); + if (empty($this->_values['is_active'])) { + 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 72ee467553..5a54b3b80d 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -351,6 +351,11 @@ class CRM_Core_Error extends PEAR_ErrorStack { * @acess 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 a1b4994eb4..793e5a25ce 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1295,6 +1295,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