CRM-15683 - Add UnhandledExceptionEvent. Fixup LegacyErrorHandler.
authorTim Otten <totten@civicrm.org>
Thu, 11 Dec 2014 00:10:00 +0000 (16:10 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 1 Jan 2015 18:28:17 +0000 (10:28 -0800)
CRM/Core/LegacyErrorHandler.php
CRM/Utils/Hook.php
Civi/Core/Container.php
Civi/Core/Event/UnhandledExceptionEvent.php [new file with mode: 0644]

index fff6d204bf811b8398bd243f0238d50ada4a02c0..b10026ac6b908fb5784282e288c9e450a644aaf9 100644 (file)
@@ -1,7 +1,12 @@
 <?php
 
 class CRM_Core_LegacyErrorHandler {
-  static function handledException($e) {
+  /**
+   * @param \Civi\Core\Event\UnhandledExceptionEvent $event
+   * @throws Exception
+   */
+  static function handleException($event) {
+    $e = $event->exception;
     if ($e instanceof CRM_Core_Exception) {
       $params = $e->getErrorData();
       $message = $e->getMessage();
@@ -24,4 +29,5 @@ class CRM_Core_LegacyErrorHandler {
       }
     }
   }
+
 }
index 6787614073f887879f0b4843d61a73f67443c6e7..7e97befac040b0c317fc0d37b087971ce4ca339d 100644 (file)
@@ -1459,12 +1459,18 @@ abstract class CRM_Utils_Hook {
 
   /**
    * @param CRM_Core_Exception Exception $exception
+   * @param mixed $request reserved for future use
    */
-  static function unhandledException($exception) {
-    self::singleton()->invoke(1, $exception, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,'civicrm_unhandled_exception');
+  static function unhandledException($exception, $request = NULL) {
+    self::singleton()->invoke(2, $exception, $request, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,'civicrm_unhandled_exception');
+    // == 4.4 ==
+    //$event = new stdClass();
+    //$event->exception = $exception;
+    //CRM_Core_LegacyErrorHandler::handleException($event);
+
     // == 4.5+ ==
-   $event = new \Civi\Core\Event\UnhandledExceptionEvent(self::$_nullObject, $exception);
-    \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("unhandled_exception", $event);
+    $event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
+    \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
   }
 
   /**
index 9db59203d970aa31845353d29fd4f45972567782..4ee59208a92ee929b784cf491decc8b9522fa3c2 100644 (file)
@@ -96,7 +96,7 @@ class Container {
     $dispatcher->addListener('DAO::post-insert', array('\CRM_Core_BAO_RecurringEntity', 'triggerInsert'));
     $dispatcher->addListener('DAO::post-update', array('\CRM_Core_BAO_RecurringEntity', 'triggerUpdate'));
     $dispatcher->addListener('DAO::post-delete', array('\CRM_Core_BAO_RecurringEntity', 'triggerDelete'));
-    $dispatcher->addListener('hook_civicrm_unhandled_exception', array('CRM_Core_LegacyErrorHandler', 'handleException');
+    $dispatcher->addListener('hook_civicrm_unhandled_exception', array('CRM_Core_LegacyErrorHandler', 'handleException'));
     return $dispatcher;
   }
 
diff --git a/Civi/Core/Event/UnhandledExceptionEvent.php b/Civi/Core/Event/UnhandledExceptionEvent.php
new file mode 100644 (file)
index 0000000..f2f5b45
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+namespace Civi\Core\Event;
+
+/**
+ * Class AuthorizeEvent
+ * @package Civi\API\Event
+ */
+class UnhandledExceptionEvent extends \Symfony\Component\EventDispatcher\Event {
+
+  /**
+   * @var \Exception
+   */
+  public $exception;
+
+  /**
+   * @var mixed reserved for future use
+   */
+  public $request;
+
+  function __construct($e, $request) {
+    $this->request = $request;
+    $this->exception = $e;
+  }
+}