From: Daniƫl <9696905+DanielvV@users.noreply.github.com> Date: Fri, 29 Sep 2017 17:06:57 +0000 (+0200) Subject: CRM-21214 - Fix address sharing - rewrite X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e60b6e52c574a1cc9e0982a06318a2c47f72663e;p=civicrm-core.git CRM-21214 - Fix address sharing - rewrite Rewrite `processSharedAddress()` a littlebit and add clear comments. 'null' is not needed here, breaks my code. --- diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 024ef85042..38d556e9e3 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -800,7 +800,7 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i * Function handles shared contact address processing. * In this function we just modify submitted values so that new address created for the user * has same address as shared contact address. We copy the address so that search etc will be - * much efficient. + * much more efficient. * * @param array $address * This is associated array which contains submitted form values. @@ -810,20 +810,20 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i return; } - // Sharing contact address during create mode is pretty straight forward. - // In update mode we should check following: - // - We should check if user has uncheck shared contact address - // - If yes then unset the master_id or may be just delete the address that copied master - // Normal update process will automatically create new address with submitted values + // In create mode sharing a contact's address is pretty straight forward. + // In update mode we should check if the user stops sharing. If yes: + // - Set the master_id to an empty value + // Normal update process will automatically create new address with submitted values - // 1. loop through entire subnitted address array - $masterAddress = array(); + // 1. loop through entire submitted address array $skipFields = array('is_primary', 'location_type_id', 'is_billing', 'master_id'); foreach ($address as & $values) { - // 2. check if master id exists, if not continue - if (empty($values['master_id']) || empty($values['use_shared_address'])) { - // we should unset master id when use uncheck share address for existing address - $values['master_id'] = 'null'; + // 2. check if "Use another contact's address" is checked, if not continue + // Additionally, if master_id is set (address was shared), set master_id to empty value. + if (empty($values['use_shared_address'])) { + if (!empty($values['master_id'])) { + $values['master_id'] = ''; + } continue; }