CRM-15683 Tim's proposed changes
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 9 Dec 2014 00:25:07 +0000 (13:25 +1300)
committerTim Otten <totten@civicrm.org>
Thu, 1 Jan 2015 18:28:16 +0000 (10:28 -0800)
CRM/Core/LegacyErrorHandler.php [new file with mode: 0644]
CRM/Utils/Hook.php
Civi/Core/Container.php

diff --git a/CRM/Core/LegacyErrorHandler.php b/CRM/Core/LegacyErrorHandler.php
new file mode 100644 (file)
index 0000000..fff6d20
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+class CRM_Core_LegacyErrorHandler {
+  static function handledException($e) {
+    if ($e instanceof CRM_Core_Exception) {
+      $params = $e->getErrorData();
+      $message = $e->getMessage();
+      $session = CRM_Core_Session::singleton();
+      $session->setStatus(
+        $message,
+        CRM_Utils_Array::value('message_title', $params),
+        CRM_Utils_Array::value('message_type', $params, 'error')
+      );
+
+      // @todo remove this code - legacy redirect path is an interim measure for moving redirects out of BAO
+      // to somewhere slightly more acceptable. they should not be part of the exception class & should
+      // be managed @ the form level - if you find a form that is triggering this piece of code
+      // you should log a ticket for it to be removed with details about the form you were on.
+      if (!empty($params['legacy_redirect_path'])) {
+        if (CRM_Utils_System::isDevelopment()) {
+          // here we could set a message telling devs to log it per above
+        }
+        CRM_Utils_System::redirect($params['legacy_redirect_path'], $params['legacy_redirect_query']);
+      }
+    }
+  }
+}
index f7f0c012228f74e4482f456042d9d3c743222dcc..6787614073f887879f0b4843d61a73f67443c6e7 100644 (file)
@@ -1461,7 +1461,10 @@ 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');
+    self::singleton()->invoke(1, $exception, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,'civicrm_unhandled_exception');
+    // == 4.5+ ==
+   $event = new \Civi\Core\Event\UnhandledExceptionEvent(self::$_nullObject, $exception);
+    \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("unhandled_exception", $event);
   }
 
   /**
index 2a8464547f0c45cfcf4dec4cc7438fc2bbe6230a..9db59203d970aa31845353d29fd4f45972567782 100644 (file)
@@ -96,6 +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');
     return $dispatcher;
   }