[MediaWiki-commits] [Gerrit] wikimedia...crm[master]: Blank addresses, finally deal with ones with more than one d...
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/343806 ) 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/tests/phpunit/MergeTest.php M sites/all/modules/wmf_civicrm/update_restore_addresses.php 2 files changed, 46 insertions(+), 10 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php index 7e449c1..f9ef27e 100644 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php +++ b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php @@ -1247,6 +1247,34 @@ } /** + * Test recovery where a blank email has overwritten a non-blank email on merge. + * + * In this case an email existed during merge that held no data. It was used + * on the merge, but now we want the lost data. It underwent 2 merges. + */ + public function testRepairBlankedAddressOnMergeDoubleWhammy() { +$this->prepareForBlankAddressTests(); +$contact3 = $this->breedDuck( + array('api.address.create' => array( +'street_address' => '25 Ducky Way', +'country_id' => 'US', +'contact_id' => $this->contactID, +'location_type_id' => 'Main', + ))); +$this->replicateBlankedAddress(); + +$address = $this->callAPISuccessGetSingle('Address', array('contact_id' => $this->contactID)); +$this->assertTrue(empty($address['street_address'])); + +wmf_civicrm_fix_blanked_address($address['id']); +$address = $this->callAPISuccessGetSingle('Address', array('contact_id' => $this->contactID)); +$this->assertEquals('25 Mousey Way', $address['street_address']); + +$this->cleanupFromBlankAddressRepairTests(); + } + + + /** * Test recovery where an always-blank email has been transferred to another contact on merge. * * We have established the address was always blank and still exists. Lets diff --git a/sites/all/modules/wmf_civicrm/update_restore_addresses.php b/sites/all/modules/wmf_civicrm/update_restore_addresses.php index 1b3e0bf..e207559 100644 --- a/sites/all/modules/wmf_civicrm/update_restore_addresses.php +++ b/sites/all/modules/wmf_civicrm/update_restore_addresses.php @@ -75,7 +75,9 @@ $deletedAddresses = array(); foreach ($logEntries as $logEntryID => $logEntry) { -if ($logEntryID > 0); +if ($logEntryID === 0) { + continue; +} // Fetch all the address changes that happened during the most recent merge action. $logs = civicrm_api3('Logging', 'get', array( 'tables' => array('civicrm_address'), @@ -88,12 +90,6 @@ } } $updates = array(); - - // Q. What do we do if more than one address was deleted during the merged? - // A. Chicken out. - if (count($deletedAddresses) > 1) { -return; - } /** * Some checks / precautions. @@ -155,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/343806 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I12c97ebd639eb134a5dea83c49f8c0ce747df12c Gerrit-PatchSet: 5 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Eileen Gerrit-Re
[MediaWiki-commits] [Gerrit] wikimedia...crm[master]: Blank addresses, finally deal with ones with more than one d...
Eileen has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/343806 ) 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/tests/phpunit/MergeTest.php M sites/all/modules/wmf_civicrm/update_restore_addresses.php 2 files changed, 43 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/06/343806/1 diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php index 7e449c1..f9ef27e 100644 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php +++ b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php @@ -1247,6 +1247,34 @@ } /** + * Test recovery where a blank email has overwritten a non-blank email on merge. + * + * In this case an email existed during merge that held no data. It was used + * on the merge, but now we want the lost data. It underwent 2 merges. + */ + public function testRepairBlankedAddressOnMergeDoubleWhammy() { +$this->prepareForBlankAddressTests(); +$contact3 = $this->breedDuck( + array('api.address.create' => array( +'street_address' => '25 Ducky Way', +'country_id' => 'US', +'contact_id' => $this->contactID, +'location_type_id' => 'Main', + ))); +$this->replicateBlankedAddress(); + +$address = $this->callAPISuccessGetSingle('Address', array('contact_id' => $this->contactID)); +$this->assertTrue(empty($address['street_address'])); + +wmf_civicrm_fix_blanked_address($address['id']); +$address = $this->callAPISuccessGetSingle('Address', array('contact_id' => $this->contactID)); +$this->assertEquals('25 Mousey Way', $address['street_address']); + +$this->cleanupFromBlankAddressRepairTests(); + } + + + /** * Test recovery where an always-blank email has been transferred to another contact on merge. * * We have established the address was always blank and still exists. Lets diff --git a/sites/all/modules/wmf_civicrm/update_restore_addresses.php b/sites/all/modules/wmf_civicrm/update_restore_addresses.php index 1b3e0bf..19576de 100644 --- a/sites/all/modules/wmf_civicrm/update_restore_addresses.php +++ b/sites/all/modules/wmf_civicrm/update_restore_addresses.php @@ -89,12 +89,6 @@ } $updates = array(); - // Q. What do we do if more than one address was deleted during the merged? - // A. Chicken out. - if (count($deletedAddresses) > 1) { -return; - } - /** * Some checks / precautions. * - how many times has this address been changed? @@ -155,11 +149,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, array_keys($deletedAddressDetails, 1)); +} +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/343806 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I12c97ebd639eb134a5dea83c49f8c0ce747df12c Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Eileen ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits