[REF] Remove checks as to whether entityShortName is in the component array
authoreileen <emcnaughton@wikimedia.org>
Fri, 18 Sep 2020 05:14:00 +0000 (17:14 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 21 Sep 2020 00:42:51 +0000 (12:42 +1200)
If entityShortName is not in components then formTaskClassName will never be set & later down the attempt to use
that variable in formTaskClassName::preProcessCommon MUST fail - ergo it is always in components.

To make it really explicit I added the exception & hard-coded list as I think it would be easy to revisit this
later without that

CRM/Export/Form/Select.php

index 8710d85236677c157857b793adbd4296b7d91886..cb95ff243bc842450c70022d0359ae2d4c4507bd 100644 (file)
@@ -76,28 +76,28 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task {
     $this->_componentIds = [];
     $this->_componentClause = NULL;
 
-    // we need to determine component export
-    $components = CRM_Export_BAO_Export::getComponents();
-
     // FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts
     // FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName
     $entityShortname = $this->getEntityShortName();
 
-    if (in_array($entityShortname, $components)) {
-      $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT');
-      $formTaskClassName = "CRM_{$entityShortname}_Form_Task";
-      $taskClassName = "CRM_{$entityShortname}_Task";
-      if (isset($formTaskClassName::$entityShortname)) {
-        $this::$entityShortname = $formTaskClassName::$entityShortname;
-        if (isset($formTaskClassName::$tableName)) {
-          $this::$tableName = $formTaskClassName::$tableName;
-        }
-      }
-      else {
-        $this::$entityShortname = $entityShortname;
-        $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($this->getDAOName()));
+    if (!in_array($entityShortname, ['Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'], TRUE)) {
+      // This is never reached - the exception here is just to clarify that entityShortName MUST be one of the above
+      // to save future refactorers & reviewers from asking that question.
+      throw new CRM_Core_Exception('Unreachable code');
+    }
+    $this->_exportMode = constant('CRM_Export_Form_Select::' . strtoupper($entityShortname) . '_EXPORT');
+    $formTaskClassName = "CRM_{$entityShortname}_Form_Task";
+    $taskClassName = "CRM_{$entityShortname}_Task";
+    if (isset($formTaskClassName::$entityShortname)) {
+      $this::$entityShortname = $formTaskClassName::$entityShortname;
+      if (isset($formTaskClassName::$tableName)) {
+        $this::$tableName = $formTaskClassName::$tableName;
       }
     }
+    else {
+      $this::$entityShortname = $entityShortname;
+      $this::$tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(CRM_Core_DAO_AllCoreTables::getFullName($this->getDAOName()));
+    }
 
     // get the submitted values based on search
     if ($this->_action == CRM_Core_Action::ADVANCED) {
@@ -110,7 +110,7 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task {
       $values = $this->controller->exportValues('Custom');
     }
     else {
-      if (in_array($entityShortname, $components) && $entityShortname !== 'Contact') {
+      if ($entityShortname !== 'Contact') {
         $values = $this->controller->exportValues('Search');
       }
       else {