From c3ea05e1e032fc9f8978e5a3a6b49a5b9b37f698 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 17 Sep 2020 15:49:12 +1200 Subject: [PATCH] [Ref] Move determination about location type to the getDAOForLocationEntity function This seems more legible than the metadata trick.... --- CRM/Dedupe/MergeHandler.php | 40 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/CRM/Dedupe/MergeHandler.php b/CRM/Dedupe/MergeHandler.php index e12cd7519d..77d112b8ea 100644 --- a/CRM/Dedupe/MergeHandler.php +++ b/CRM/Dedupe/MergeHandler.php @@ -208,17 +208,13 @@ class CRM_Dedupe_MergeHandler { $locationBlocks = CRM_Dedupe_Merger::getLocationBlockInfo(); $migrationInfo = $this->getMigrationInfo(); // For the block which belongs to other-contact, link the location block to main-contact - $otherBlockDAO = $this->getDAOForLocationEntity($name); + $otherBlockDAO = $this->getDAOForLocationEntity($name, $this->getSelectedLocationType($name, $blkCount)); $otherBlockDAO->contact_id = $this->getToKeepID(); // Get the ID of this block on the 'other' contact, otherwise skip $otherBlockDAO->id = $otherBlockId; // Add/update location and type information from the form, if applicable - if ($locationBlocks[$name]['hasLocation']) { - $locTypeId = $migrationInfo['location_blocks'][$name][$blkCount]['locTypeId'] ?? NULL; - $otherBlockDAO->location_type_id = $locTypeId; - } if ($locationBlocks[$name]['hasType']) { $typeTypeId = $migrationInfo['location_blocks'][$name][$blkCount]['typeTypeId'] ?? NULL; $otherBlockDAO->{$locationBlocks[$name]['hasType']} = $typeTypeId; @@ -231,25 +227,35 @@ class CRM_Dedupe_MergeHandler { * * @param string $entity * + * @param null $locationTypeID + * * @return CRM_Core_DAO_Address|CRM_Core_DAO_Email|CRM_Core_DAO_IM|CRM_Core_DAO_Phone|CRM_Core_DAO_Website * @throws \CRM_Core_Exception */ - public function getDAOForLocationEntity($entity) { + public function getDAOForLocationEntity($entity, $locationTypeID = NULL) { switch ($entity) { case 'email': - return new CRM_Core_DAO_Email(); + $dao = new CRM_Core_DAO_Email(); + $dao->location_type_id = $locationTypeID; + return $dao; case 'address': - return new CRM_Core_DAO_Address(); + $dao = new CRM_Core_DAO_Address(); + $dao->location_type_id = $locationTypeID; + return $dao; case 'phone': - return new CRM_Core_DAO_Phone(); + $dao = new CRM_Core_DAO_Phone(); + $dao->location_type_id = $locationTypeID; + return $dao; case 'website': return new CRM_Core_DAO_Website(); case 'im': - return new CRM_Core_DAO_IM(); + $dao = new CRM_Core_DAO_IM(); + $dao->location_type_id = $locationTypeID; + return $dao; default: // Mostly here, along with the switch over a more concise format, to help IDEs understand the possibilities. @@ -257,4 +263,18 @@ class CRM_Dedupe_MergeHandler { } } + /** + * Get the selected location type for the given location block. + * + * This will retrieve any user selection if they specified which location to move a block to. + * + * @param string $entity + * @param int $blockIndex + * + * @return int|null + */ + protected function getSelectedLocationType($entity, $blockIndex) { + return $this->getMigrationInfo()['location_blocks'][$entity][$blockIndex]['locTypeId'] ?? NULL; + } + } -- 2.25.1