Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367395 )

Change subject: CRM-20759 (follow up fix) Primary address is 'distributed' over 
several ID
......................................................................

CRM-20759 (follow up fix) Primary address is 'distributed' over several ID

Upstream: https://github.com/civicrm/civicrm-core/pull/10738

This wasn't picked up originally in the test as it was only using one field of 
the primary type.

The old code was indexing by 'addressCnt' (checking that the location type id 
was different each time). I
have switched to index by location_type_id - we should only have one address 
per location type per contact.

I also removed the code that sets 'is_primary' if we are importing the first 
address for a contact.
That has been handled by the BAO for some time

Bug: T169025

Change-Id: I13cd3b8f6e258bf6bf222eb433e47b8ca867df7f
---
M CRM/Contact/Import/Parser/Contact.php
1 file changed, 4 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/95/367395/1

diff --git a/CRM/Contact/Import/Parser/Contact.php 
b/CRM/Contact/Import/Parser/Contact.php
index b93ac56..2ca2e2b 100644
--- a/CRM/Contact/Import/Parser/Contact.php
+++ b/CRM/Contact/Import/Parser/Contact.php
@@ -2464,17 +2464,6 @@
         $params['address'] = array();
       }
 
-      $addressCnt = 1;
-      foreach ($params['address'] as $cnt => $addressBlock) {
-        if (CRM_Utils_Array::value('location_type_id', $values) ==
-          CRM_Utils_Array::value('location_type_id', $addressBlock)
-        ) {
-          $addressCnt = $cnt;
-          break;
-        }
-        $addressCnt++;
-      }
-
       if (!array_key_exists('Address', $fields)) {
         $fields['Address'] = CRM_Core_DAO_Address::fields();
       }
@@ -2527,7 +2516,7 @@
         $values = $newValues;
       }
 
-      _civicrm_api3_store_values($fields['Address'], $values, 
$params['address'][$addressCnt]);
+      _civicrm_api3_store_values($fields['Address'], $values, 
$params['address'][$values['location_type_id']]);
 
       $addressFields = array(
         'county',
@@ -2544,7 +2533,7 @@
           if (!array_key_exists('address', $params)) {
             $params['address'] = array();
           }
-          $params['address'][$addressCnt][$field] = $values[$field];
+          $params['address'][$values['location_type_id']][$field] = 
$values[$field];
         }
       }
 
@@ -2553,14 +2542,9 @@
           $primary = civicrm_api3('Address', 'get', array('return' => 
'location_type_id', 'contact_id' => $params['id'], 'is_primary' => 1, 
'sequential' => 1));
         }
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
-        $params['address'][$addressCnt]['location_type_id'] = (isset($primary) 
&& $primary['count']) ? $primary['values'][0]['location_type_id'] : 
$defaultLocationType->id;
-        $params['address'][$addressCnt]['is_primary'] = 1;
+        $params['address'][$values['location_type_id']]['location_type_id'] = 
(isset($primary) && $primary['count']) ? 
$primary['values'][0]['location_type_id'] : $defaultLocationType->id;
+        $params['address'][$values['location_type_id']]['is_primary'] = 1;
 
-      }
-
-      if ($addressCnt == 1) {
-
-        $params['address'][$addressCnt]['is_primary'] = TRUE;
       }
       return TRUE;
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/367395
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I13cd3b8f6e258bf6bf222eb433e47b8ca867df7f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to