Remove some static caches that are crashing tests
authoreileen <emcnaughton@wikimedia.org>
Thu, 25 Jul 2019 09:50:18 +0000 (21:50 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 26 Jul 2019 22:35:01 +0000 (10:35 +1200)
CRM/Contact/Import/Parser.php
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index ba205617155379d71b906e0156e95b77768d923f..0a85acd50c9f6c18b15b854ad59483e78af299fd 100644 (file)
@@ -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 {
index 5981a5fab58bf90c04878a168a6d96a102a3969a..f8b543c6c5d8fd3505d6e1c43bcf73d2f3627570 100644 (file)
@@ -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, [
index 5f3094da2056c3f10f0fcc76bdfe5a2a9d5bc046..ff4e11c6c9ef64bfc2624ea51031de8124525174 100644 (file)
@@ -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';