Skip to content

Commit

Permalink
CRM-21773 Refactor relTables to support unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JKingsnorth committed Feb 22, 2018
1 parent 06f4969 commit d68970f
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ class CRM_Dedupe_Merger {
* @return array
*/
public static function relTables() {
static $relTables;

// Setting these merely prevents enotices - but it may be more appropriate not to add the user table below
// if the url can't be retrieved. A more standardised way to retrieve them is.
// CRM_Core_Config::singleton()->userSystem->getUserRecordUrl() - however that function takes a contact_id &
// we may need a different function when it is not known.
$title = $userRecordUrl = '';

$config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) {
$userRecordUrl = CRM_Utils_System::url('user/%ufid');
$title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
}
elseif ($config->userFramework == 'Joomla') {
$userRecordUrl = $config->userSystem->getVersion() > 1.5 ? $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . '%ufid' : $config->userFrameworkBaseURL . "index2.php?option=com_users&view=user&task=edit&id[]=" . '%ufid';
$title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
}

if (!isset(Civi::$statics[__CLASS__]['relTables'])) {

// Setting these merely prevents enotices - but it may be more appropriate not to add the user table below
// if the url can't be retrieved. A more standardised way to retrieve them is.
// CRM_Core_Config::singleton()->userSystem->getUserRecordUrl() - however that function takes a contact_id &
// we may need a different function when it is not known.
$title = $userRecordUrl = '';

$config = CRM_Core_Config::singleton();
if ($config->userSystem->is_drupal) {
$userRecordUrl = CRM_Utils_System::url('user/%ufid');
$title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
}
elseif ($config->userFramework == 'Joomla') {
$userRecordUrl = $config->userSystem->getVersion() > 1.5 ? $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . '%ufid' : $config->userFrameworkBaseURL . "index2.php?option=com_users&view=user&task=edit&id[]=" . '%ufid';
$title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
}

if (!$relTables) {
$relTables = array(
'rel_table_contributions' => array(
'title' => ts('Contributions'),
Expand Down Expand Up @@ -155,8 +155,12 @@ public static function relTables() {

// Allow hook_civicrm_merge() to adjust $relTables
CRM_Utils_Hook::merge('relTables', $relTables);

// Cache the results in a static variable
Civi::$statics[__CLASS__]['relTables'] = $relTables;
}
return $relTables;

return Civi::$statics[__CLASS__]['relTables'];
}

/**
Expand Down

0 comments on commit d68970f

Please sign in to comment.