Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] clean up merge array. #15970

Merged
merged 1 commit into from
Dec 2, 2019
Merged

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Nov 27, 2019

Overview

Code cleanup - no actual change

Before

Code build 2 arrays then uses one to prune the other before merging them. The first array gets precedence

After

Code builds one array, as a property, only setting not-already-set values to achieve the same precedence.

Technical Details

This code has been doing my head in because it is just like 'construct complex array & then another
complex array & iterate them together in nasty ways.

However, after another round of misery I'm pretty sure that this cleanup works. Basically the whole removed
section of code amounts to 'the array built in the first pass takes precedence over the one in the
second pass'. By using a property & only setting the array values when not-yet-set we can
allow the second pass to not clobber the first while populating it rather than as follow up wrangling

@monishdeb I think this gets us closer to readable code which I want before adding more logic complexity in as I find the mergeSameAddress stuff really bad.

Comments

Code is currently unreachable due to https://lab.civicrm.org/dev/core/issues/1421

But testMergeSameAddress passes through it with this patch

--- a/CRM/Export/BAO/ExportProcessor.php
+++ b/CRM/Export/BAO/ExportProcessor.php
@@ -1007,8 +1007,8 @@ class CRM_Export_BAO_ExportProcessor {
         elseif ($field == 'provider_id' || $field == 'im_provider') {
           $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
         }
-        elseif (strstr($field, 'master_id')) {
-          // @todo - why not just $field === 'master_id'  - what else would it be?
+        elseif (strstr($field, '-master_id')) {
+          // master_id is likely for wrangling but Home-master_id is tested as being converted.
           $masterAddressId = $iterationDAO->$field ?? NULL;
           // get display name of contact that address is shared.
           $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId);

Note the tests need a couple of minor tweaks to still pass after that is merged. We would also get the change of behaviour described in https://lab.civicrm.org/dev/core/issues/1421 so it's cleanup before fixes here

@civibot
Copy link

civibot bot commented Nov 27, 2019

(Standard links)

This code has been doing my head in because it is just like 'construct complex array & then another
complex array & iterate them together in nasty ways.

However, after another round of misery I'm pretty sure that this cleanup works. Basically the whole removed
section of code amounts to 'the array built in the first pass takes precedence over the one in the
second pass'. By using a property & only setting the array values when not-yet-set we can
allow the second pass to not clobber the first while populating it rather than as follow up wrangling
@monishdeb
Copy link
Member

Tested working fine.

@monishdeb monishdeb merged commit 7eab71d into civicrm:master Dec 2, 2019
@eileenmcnaughton eileenmcnaughton deleted the ex_easy branch December 2, 2019 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants