From 6d8d4c916ef016d8657bb105188a0223c83cdd96 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 2 Dec 2019 11:10:14 +1100 Subject: [PATCH] Catch CiviCRM APIv3 Error if custom field no longer exists in the database --- CRM/Contact/BAO/Query.php | 9 +++++++-- tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 4cfc7b2e84..d705dda02e 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -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; } diff --git a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php index cbb319d782..387df107bc 100644 --- a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php +++ b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php @@ -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); } /** -- 2.25.1