From 8372e6054a3f3eb159de85bc40cd81f023d5cbb1 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 9 Jan 2020 15:11:22 +1300 Subject: [PATCH] Remove unused and largely unreachable code. The removed lines can only be reached if a) CMS is Joomla or b) CMS is Drupal and NULL is not equal to NULL This seemed a little suspicious - especially since the merge screen still does display the value that should be but isn't calculated here. After digging I found it is duplicated here https://github.com/civicrm/civicrm-core/blob/bc77d7c0798081f999e6eca92d75fa874fd04e74/CRM/Contact/Form/Merge.php#L115 and that is the value used in the tpl here https://github.com/civicrm/civicrm-core/blob/1188c7a8512382b1cb588b6a1ea4b13aa9587bc9/templates/CRM/Contact/Form/Merge.tpl#L217 so these lines can be safely removed as redundant. I also signposted where I think the next cleanups should happen on this with code comments --- CRM/Contact/Form/Merge.php | 2 ++ CRM/Dedupe/Merger.php | 41 +++++--------------------------------- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/CRM/Contact/Form/Merge.php b/CRM/Contact/Form/Merge.php index 52690f03bb..326a035508 100644 --- a/CRM/Contact/Form/Merge.php +++ b/CRM/Contact/Form/Merge.php @@ -112,6 +112,7 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { $mainUfId = CRM_Core_BAO_UFMatch::getUFId($this->_cid); $mainUser = NULL; if ($mainUfId) { + // @todo also calculate & assign url here & get it out of getRowsElementsAndInfo as it is form layer functionality. $mainUser = $config->userSystem->getUser($this->_cid); $this->assign('mainUfId', $mainUfId); $this->assign('mainUfName', $mainUser ? $mainUser['name'] : NULL); @@ -149,6 +150,7 @@ class CRM_Contact_Form_Merge extends CRM_Core_Form { $otherUser = NULL; if ($otherUfId) { + // @todo also calculate & assign url here & get it out of getRowsElementsAndInfo as it is form layer functionality. $otherUser = $config->userSystem->getUser($this->_oid); $this->assign('otherUfId', $otherUfId); $this->assign('otherUfName', $otherUser ? $otherUser['name'] : NULL); diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index f6a2e4749e..642d6cd861 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -33,6 +33,7 @@ class CRM_Dedupe_Merger { $title = $userRecordUrl = ''; $config = CRM_Core_Config::singleton(); + // @todo - this user url stuff is only needed for the form layer - move to CRM_Contact_Form_Merge if ($config->userSystem->is_drupal) { $userRecordUrl = CRM_Utils_System::url('user/%ufid'); $title = ts('%1 User: %2; user id: %3', [ @@ -1275,30 +1276,6 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m } // End loop through each location block entity // add the related tables and unset the ones that don't sport any of the duplicate contact's info - $config = CRM_Core_Config::singleton(); - $mainUfId = CRM_Core_BAO_UFMatch::getUFId($mainId); - $mainUser = NULL; - if ($mainUfId) { - // d6 compatible - if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) { - $mainUser = user_load($mainUfId); - } - elseif ($config->userFramework == 'Joomla') { - $mainUser = JFactory::getUser($mainUfId); - } - } - $otherUfId = CRM_Core_BAO_UFMatch::getUFId($otherId); - $otherUser = NULL; - if ($otherUfId) { - // d6 compatible - if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) { - $otherUser = user_load($otherUfId); - } - elseif ($config->userFramework == 'Joomla') { - $otherUser = JFactory::getUser($otherUfId); - } - } - $mergeHandler = new CRM_Dedupe_MergeHandler((int) $mainId, (int) $otherId); $relTables = $mergeHandler->getTablesRelatedToTheMergePair(); foreach ($relTables as $name => $null) { @@ -1307,18 +1284,10 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m $relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']); $relTables[$name]['other_url'] = str_replace('$cid', $otherId, $relTables[$name]['url']); - if ($name == 'rel_table_users') { - $relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']); - $relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']); - $find = ['$ufid', '$ufname']; - if ($mainUser) { - $replace = [$mainUfId, $mainUser->name]; - $relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']); - } - if ($otherUser) { - $replace = [$otherUfId, $otherUser->name]; - $relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']); - } + if ($name === 'rel_table_users') { + // @todo - this user url stuff is only needed for the form layer - move to CRM_Contact_Form_Merge + $relTables[$name]['main_url'] = str_replace('%ufid', CRM_Core_BAO_UFMatch::getUFId($otherId), $relTables[$name]['url']); + $relTables[$name]['other_url'] = str_replace('%ufid', CRM_Core_BAO_UFMatch::getUFId($otherId), $relTables[$name]['url']); } if ($name == 'rel_table_memberships') { //Enable 'add new' checkbox if main contact does not contain any membership similar to duplicate contact. -- 2.25.1