Catch CiviCRM APIv3 Error if custom field no longer exists in the database
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 2 Dec 2019 00:10:14 +0000 (11:10 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 2 Dec 2019 00:10:14 +0000 (11:10 +1100)
CRM/Contact/BAO/Query.php
tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php

index 4cfc7b2e84ed7566f656880b5dded591a6cb6637..d705dda02e5df429abd2239ecea415fb2f07cf40 100644 (file)
@@ -4786,8 +4786,13 @@ civicrm_relationship.start_date > {$today}
     if (($customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName)) == FALSE) {
       return FALSE;
     }
-    if ('Date' == civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldID, 'return' => 'data_type'])) {
-      return TRUE;
+    try {
+      $customFieldDataType = civicrm_api3('CustomField', 'getvalue', ['id' => $customFieldID, 'return' => 'data_type']);
+      if ('Date' == $customFieldDataType) {
+        return TRUE;
+      }
+    }
+    catch (CiviCRM_API3_Exception $e) {
     }
     return FALSE;
   }
index cbb319d782f94154fd3d0e873d8897001d99d8c3..387df107bc424769a6f034db19a4ca933a05c689 100644 (file)
@@ -97,8 +97,9 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase {
 
     $this->checkArrayEquals($defaults, $formValues);
     $this->callAPISuccess('CustomField', 'delete', ['id' => $this->ids['CustomField']['int']]);
+    unset($this->ids['CustomField']['int']);
     $defaults = $sg->setDefaultValues();
-    print_r($defaults);
+    $this->checkArrayEquals($defaults, $formValues);
   }
 
   /**