CRM-15678 hookable invalid page handling
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 7 Dec 2014 22:20:33 +0000 (11:20 +1300)
committerTim Otten <totten@civicrm.org>
Thu, 1 Jan 2015 18:28:16 +0000 (10:28 -0800)
Conflicts:
CRM/Contribute/Form/ContributionBase.php

CRM/Contribute/Exception/InactiveContributionPageException.php [new file with mode: 0644]
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Error.php
CRM/Utils/Hook.php

diff --git a/CRM/Contribute/Exception/InactiveContributionPageException.php b/CRM/Contribute/Exception/InactiveContributionPageException.php
new file mode 100644 (file)
index 0000000..2c8273d
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: eileen
+ * Date: 8/12/2014
+ * Time: 10:33 AM
+ */
+
+class CRM_Contribute_Exception_InactiveContributionPageException extends Exception{
+  private $id;
+  public function __construct($message, $id) {
+    parent::__construct(ts($message));
+    $this->id = $id;
+    CRM_Core_Error::debug_log_message('inactive contribution page access attempted - page number ' . $id);
+  }
+
+  public function getID() {
+    return $this->id;
+  }
+}
index a417718610eeb9e9564e40e7bbe16d01637f7a37..31919c8314ace3f28778b55b2ee8c41447f6a38d 100644 (file)
@@ -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
index 8e3b01f5f45c31d911ce5d5b578a43e52bfd17a3..41aba6b00a5dc5eee0349a19c8064c9b0bd46c0e 100644 (file)
@@ -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(),
index 13984585b6ea9797f44b010c488779db50c108a0..f7f0c012228f74e4482f456042d9d3c743222dcc 100644 (file)
@@ -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