jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343811 )

Change subject: Blank addresses, finally deal with ones with more than one 
deleted.
......................................................................


Blank addresses, finally deal with ones with more than one deleted.

In this last round we are not doing a lot of qualitative analysis to choose 
between multiple deleted addresses
as there is low return. We do exclude restoring addresses that are a subset of 
the remaining addresses on the contact.

 Bug: T159408

Change-Id: I12c97ebd639eb134a5dea83c49f8c0ce747df12c
---
M sites/all/modules/wmf_civicrm/update_restore_addresses.php
1 file changed, 26 insertions(+), 17 deletions(-)

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



diff --git a/sites/all/modules/wmf_civicrm/update_restore_addresses.php 
b/sites/all/modules/wmf_civicrm/update_restore_addresses.php
index d76a85b..e207559 100644
--- a/sites/all/modules/wmf_civicrm/update_restore_addresses.php
+++ b/sites/all/modules/wmf_civicrm/update_restore_addresses.php
@@ -72,27 +72,24 @@
       return;
     }
   }
-  $logs = array();
+
+  $deletedAddresses = array();
   foreach ($logEntries as $logEntryID => $logEntry) {
+    if ($logEntryID === 0) {
+      continue;
+    }
     // Fetch all the address changes that happened during the most recent 
merge action.
-    $logsRows = civicrm_api3('Logging', 'get', array(
+    $logs = civicrm_api3('Logging', 'get', array(
       'tables' => array('civicrm_address'),
       'log_conn_id' => $logEntries[$logEntryID]['log_conn_id']
     ));
-    $logs += $logsRows['values'];
-  }
-  $updates = array();
-  $deletedAddresses = array();
-  foreach ($logs as $log) {
-    if ($log['action'] == 'Delete') {
-      $deletedAddresses[$log['id']][$log['field']] = $log['from'];
+    foreach ($logs['values'] as $log) {
+      if ($log['action'] == 'Delete') {
+        $deletedAddresses[$log['id']][$log['field']] = $log['from'];
+      }
     }
   }
-  // Q. What do we do if more than one address was deleted during the merged?
-  // A. Chicken out.
-  if (count($deletedAddresses) > 1) {
-    return;
-  }
+  $updates = array();
 
   /**
    * Some checks / precautions.
@@ -154,11 +151,23 @@
     // 2) it was transferred from one contact to another during the
     // merge.
     // But... was another address deleted to make way for it?
-    // If more than one address was deleted in this merge we will chicken out.
+    // If more than one address was deleted we will select the last
+    // one which is close enough to latest for this last round.
     if (count($deletedAddresses) > 1)  {
-      return;
+      foreach ($deletedAddresses as $deletedAddress) {
+        $deletedAddressDetails = array_intersect_key($deletedAddress, 
array_fill_keys($dataFields, 1));
+        foreach ($addresses['values'] as $address) {
+          $addressDetails = array_intersect_key($address, 
$deletedAddressDetails);
+          if ($deletedAddressDetails === $addressDetails) {
+            // This is our last check. Basically $addressDetails holds a 
subset of the
+            // address keys that matches those present in the deleted address 
Details. If it exactly matches
+            // the deleted address then let's ignore the deleted address & 
move on.
+            continue;
+          }
+          $updates = $deletedAddressDetails;
+        }
+      }
     }
-    $updates = array();
   }
 
   if (empty($updates)) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I12c97ebd639eb134a5dea83c49f8c0ce747df12c
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>
Gerrit-Reviewer: Eileen <emcnaugh...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to