[MediaWiki-commits] [Gerrit] wikimedia...crm[deployment]: Fix to prevent duplicate Home addresses resulting in no prim...

2016-09-21 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Fix to prevent duplicate Home addresses resulting in no primary 
on merge.
..


Fix to prevent duplicate Home addresses resulting in no primary on merge.

Bug: T145873
Change-Id: Icee9aab5179e6e42cbedd2fa615072053834962b
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 42 insertions(+), 1 deletion(-)

Approvals:
  Eileen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 21d09d9..376d3e8 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -2281,8 +2281,9 @@
   // In the test this should always be true - but keep the check in case
   // something changes that we need to detect.
   if ($lastDonorID != $mainId) {
-$higherPriorityLocationBlocks = 
$migrationInfo['other_details']['location_blocks'];
+$higherPriorityLocationBlocks = 
_wmf_civicrm_clean_duplicate_location_from_merge_blocks($migrationInfo['other_details']['location_blocks']);
 $lowerPriorityLocationBlocks = 
$migrationInfo['main_details']['location_blocks'];
+
 foreach ($higherPriorityLocationBlocks as $blockType => $blocks) {
   foreach ($blocks as $block) {
 if (empty($lowerPriorityLocationBlocks[$blockType])) {
@@ -2317,6 +2318,46 @@
 }
 
 /**
+ * Clean up any instances of 2 identical home addresses before processing.
+ *
+ * It's not valid to have 2 addresses of the same location type in CiviCRM.
+ * However, they seem to still be coming in so for now ensure they don't cause
+ * issues when deduping, with the is_primary flag being lost.
+ *
+ * T145873
+ *
+ * @param array $blocks
+ *   An array of locations associated with a contact. These are keyed by entity
+ *   (email, address, phone) and under that an array of db entries.
+ *
+ * @return array
+ *   Blocks, possibly with some removed.
+ */
+function _wmf_civicrm_clean_duplicate_location_from_merge_blocks($blocks) {
+  foreach ($blocks as $entity => $locationBlocks) {
+$locations = array();
+$primaryID = NULL;
+foreach ($locationBlocks as $index => $locationBlock) {
+  $locations[$locationBlock['location_type_id']][$index] = 
$locationBlock['id'];
+  if ($locationBlock['is_primary']) {
+$primaryID = $locationBlock['id'];
+  }
+}
+foreach ($locations as $locationsOfType) {
+  if (count($locationsOfType) > 1) {
+// We have a duplicate.
+foreach ($locationsOfType as $index => $locationID) {
+  if ($locationID <> $primaryID) {
+unset($blocks[$entity][$index]);
+  }
+}
+  }
+}
+  }
+  return $blocks;
+}
+
+/**
  * Add the calculated fields to the migration info when merging.
  *
  * The contributions have already been merged so we can query the DB for this 
info. We

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icee9aab5179e6e42cbedd2fa615072053834962b
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen 
Gerrit-Reviewer: Awight 
Gerrit-Reviewer: Cdentinger 
Gerrit-Reviewer: Eileen 
Gerrit-Reviewer: Ejegg 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] wikimedia...crm[deployment]: Fix to prevent duplicate Home addresses resulting in no prim...

2016-09-21 Thread Eileen (Code Review)
Eileen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312152

Change subject: Fix to prevent duplicate Home addresses resulting in no primary 
on merge.
..

Fix to prevent duplicate Home addresses resulting in no primary on merge.

Bug: T145873
Change-Id: Icee9aab5179e6e42cbedd2fa615072053834962b
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 42 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/52/312152/1

diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 21d09d9..376d3e8 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -2281,8 +2281,9 @@
   // In the test this should always be true - but keep the check in case
   // something changes that we need to detect.
   if ($lastDonorID != $mainId) {
-$higherPriorityLocationBlocks = 
$migrationInfo['other_details']['location_blocks'];
+$higherPriorityLocationBlocks = 
_wmf_civicrm_clean_duplicate_location_from_merge_blocks($migrationInfo['other_details']['location_blocks']);
 $lowerPriorityLocationBlocks = 
$migrationInfo['main_details']['location_blocks'];
+
 foreach ($higherPriorityLocationBlocks as $blockType => $blocks) {
   foreach ($blocks as $block) {
 if (empty($lowerPriorityLocationBlocks[$blockType])) {
@@ -2317,6 +2318,46 @@
 }
 
 /**
+ * Clean up any instances of 2 identical home addresses before processing.
+ *
+ * It's not valid to have 2 addresses of the same location type in CiviCRM.
+ * However, they seem to still be coming in so for now ensure they don't cause
+ * issues when deduping, with the is_primary flag being lost.
+ *
+ * T145873
+ *
+ * @param array $blocks
+ *   An array of locations associated with a contact. These are keyed by entity
+ *   (email, address, phone) and under that an array of db entries.
+ *
+ * @return array
+ *   Blocks, possibly with some removed.
+ */
+function _wmf_civicrm_clean_duplicate_location_from_merge_blocks($blocks) {
+  foreach ($blocks as $entity => $locationBlocks) {
+$locations = array();
+$primaryID = NULL;
+foreach ($locationBlocks as $index => $locationBlock) {
+  $locations[$locationBlock['location_type_id']][$index] = 
$locationBlock['id'];
+  if ($locationBlock['is_primary']) {
+$primaryID = $locationBlock['id'];
+  }
+}
+foreach ($locations as $locationsOfType) {
+  if (count($locationsOfType) > 1) {
+// We have a duplicate.
+foreach ($locationsOfType as $index => $locationID) {
+  if ($locationID <> $primaryID) {
+unset($blocks[$entity][$index]);
+  }
+}
+  }
+}
+  }
+  return $blocks;
+}
+
+/**
  * Add the calculated fields to the migration info when merging.
  *
  * The contributions have already been merged so we can query the DB for this 
info. We

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icee9aab5179e6e42cbedd2fa615072053834962b
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen 

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