From a0c6165f6e6bf529909b64f1c6ec73f71c27f261 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 25 Jul 2019 21:50:18 +1200 Subject: [PATCH] Remove some static caches that are crashing tests --- CRM/Contact/Import/Parser.php | 18 +++++++-------- CRM/Contact/Import/Parser/Contact.php | 8 +++---- .../CRM/Contact/Import/Parser/ContactTest.php | 22 +++++++------------ 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index ba20561715..0a85acd50c 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -1000,9 +1000,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { // Note // Custom - // Cache the various object fields - static $fields = []; - // first add core contact values since for other Civi modules they are not added $contactFields = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($contactFields, $values, $params); @@ -1016,6 +1013,10 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { return TRUE; } + // Cache the various object fields + // @todo - remove this after confirming this is just a compilation of other-wise-cached fields. + static $fields = []; + if (isset($values['individual_prefix'])) { if (!empty($params['prefix_id'])) { $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); @@ -1164,18 +1165,15 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { } // Check for custom field values - - if (empty($fields['custom'])) { - $fields['custom'] = &CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), - FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE - ); - } + $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), + FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE + ); foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { // check if it's a valid custom field id - if (!array_key_exists($customFieldID, $fields['custom'])) { + if (!array_key_exists($customFieldID, $customFields)) { return civicrm_api3_create_error('Invalid custom field ID'); } else { diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 5981a5fab5..f8b543c6c5 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -477,6 +477,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { * * @return bool * the result of this processing + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { $config = CRM_Core_Config::singleton(); @@ -505,10 +508,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { 'contact_type' => $this->_contactType, ]; - static $contactFields = NULL; - if ($contactFields == NULL) { - $contactFields = CRM_Contact_DAO_Contact::import(); - } + $contactFields = CRM_Contact_DAO_Contact::import(); //check if external identifier exists in database if (!empty($params['external_identifier']) && (!empty($params['id']) || in_array($onDuplicate, [ diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 5f3094da20..ff4e11c6c9 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -519,20 +519,16 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { */ public function testImportFill() { // Create a custom field group for testing. - $custom_group_name = 'importFillGroup'; - $results = $this->callAPISuccess('customGroup', 'get', ['title' => $custom_group_name]); - if ($results['count'] == 0) { - $api_params = [ - 'title' => $custom_group_name, - 'extends' => 'Individual', - 'is_active' => TRUE, - ]; - $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params); - } + $this->createCustomGroup([ + 'title' => 'importFillGroup', + 'extends' => 'Individual', + 'is_active' => TRUE, + ]); + $customGroupID = $this->ids['CustomGroup']['importFillGroup']; // Add two custom fields. $api_params = [ - 'custom_group_id' => $customGroup['id'], + 'custom_group_id' => $customGroupID, 'label' => 'importFillField1', 'html_type' => 'Select', 'data_type' => 'String', @@ -545,7 +541,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $customField1 = $result['id']; $api_params = [ - 'custom_group_id' => $customGroup['id'], + 'custom_group_id' => $customGroupID, 'label' => 'importFillField2', 'html_type' => 'Select', 'data_type' => 'String', @@ -560,8 +556,6 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { // Now set up values. $original_gender = 'Male'; $original_custom1 = 'foo'; - $original_job_title = ''; - $original_custom2 = ''; $original_email = 'test-import-fill@example.org'; $import_gender = 'Female'; -- 2.25.1