Merge pull request #3580 from monishdeb/CRM-14701
[civicrm-core.git] / CRM / Core / Invoke.php
index 96583f77dacfe2ddbfe785f2d0399685b12151e6..b06fd360e8d82b926fe5dbc9ff59f31107425d54 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -50,7 +50,9 @@ class CRM_Core_Invoke {
   static function invoke($args) {
     try {
       return self::_invoke($args);
-    } catch (Exception $e) {
+    }
+
+    catch (Exception $e) {
       return CRM_Core_Error::handleUnhandledException($e);
     }
   }
@@ -68,7 +70,36 @@ class CRM_Core_Invoke {
         self::hackStandalone($args);
         $item = self::getItem($args);
         return self::runItem($item);
-      } catch (Exception $e) {
+      }
+      catch (CRM_Core_EXCEPTION $e) {
+        $params = $e->getErrorData();
+        $message = $e->getMessage();
+        if (isset($params['legacy_status_bounce'])) {
+          //@todo remove this- see comments on
+          //https://github.com/eileenmcnaughton/civicrm-core/commit/ae686b09e2c987091612bb25ba0a58e520a203e7
+          CRM_Core_Error::statusBounce($params['message']);
+        }
+        else {
+          $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']);
+          }
+        }
+      }
+      catch (Exception $e) {
         // Recall: CRM_Core_Config is initialized before calling CRM_Core_Invoke
         $config = CRM_Core_Config::singleton();
         return CRM_Core_Error::handleUnhandledException($e);
@@ -387,22 +418,6 @@ class CRM_Core_Invoke {
       $session = CRM_Core_Session::singleton();
       $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'reset=1'));
 
-      $buttonType = CRM_Utils_Array::value('_qf_Edit_cancel', $_POST);
-      // CRM-5849: we should actually check the button *type*, but we get the *value*, potentially translated;
-      // we should keep both English and translated checks just to make sure we also handle untranslated Cancels
-      if ($buttonType == 'Cancel' or $buttonType == ts('Cancel')) {
-        $cancelURL = CRM_Utils_Request::retrieve('cancelURL',
-          'String',
-          CRM_Core_DAO::$_nullObject,
-          FALSE,
-          NULL,
-          $_POST
-        );
-        if ($cancelURL) {
-          CRM_Utils_System::redirect($cancelURL);
-        }
-      }
-
       if ($secondArg == 'edit') {
         $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit',
           ts('Create Profile'),
@@ -425,8 +440,13 @@ class CRM_Core_Invoke {
       }
     }
 
-    $page = new CRM_Profile_Page_Listings();
-    return $page->run();
+    if ($secondArg == 'view' || empty($secondArg)) {
+      $page = new CRM_Profile_Page_Listings();
+      return $page->run();
+    }
+
+    CRM_Utils_System::permissionDenied();
+    return;
   }
 
   /**
@@ -447,18 +467,21 @@ class CRM_Core_Invoke {
     $config = CRM_Core_Config::singleton();
     $config->clearModuleList();
 
+    // also cleanup all caches
+    $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
+
     CRM_Core_Menu::store();
 
     // also reset navigation
     CRM_Core_BAO_Navigation::resetNavigation();
 
-    // also cleanup all caches
-    $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
-
     // also cleanup module permissions
     $config->cleanupPermissions();
 
-    CRM_Core_BAO_SETTING::updateSettingsFromMetaData();
+    // also rebuild word replacement cache
+    CRM_Core_BAO_WordReplacement::rebuild();
+
+    CRM_Core_BAO_Setting::updateSettingsFromMetaData();
     CRM_Core_Resources::singleton()->resetCacheCode();
 
     // also rebuild triggers if requested explicitly
@@ -468,7 +491,7 @@ class CRM_Core_Invoke {
     ) {
       CRM_Core_DAO::triggerRebuild();
     }
-
+    CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE);
     CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
   }
 }