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

replaceOrgTokens: Remove broken code #19543

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,20 @@ public static function getDomainTokenReplacement($token, $domain, $html = FALSE,
/**
* Replace all the org-level tokens in $str
*
* @fixme: This function appears to be broken, as it depends on
* @fixme: This function appears to be broken, as it depended on
* nonexistant method: CRM_Core_BAO_CustomValue::getContactValues()
* Marking as deprecated until this is fixed
* Marking as deprecated until this is clarified.
*
* @deprecated
* - the above hard-breakage was there from 2015 to 2021 and
* no error was ever reported on it -does that mean
* 1) the code is never hit because the only function that
* calls this function is never called or
* 2) it was called but never required to resolve any tokens
* or more specifically custom field tokens
*
* The handling for custom fields with the removed token has
* now been removed.
*
* @param string $str
* The string with tokens to be replaced.
Expand All @@ -330,17 +340,16 @@ public static function getDomainTokenReplacement($token, $domain, $html = FALSE,
* @return string
* The processed string
*/
public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) {
public static function replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) {
self::$_tokens['org']
= array_merge(
array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')),
['address', 'display_name', 'checksum', 'contact_id']
);

$cv = NULL;
foreach (self::$_tokens['org'] as $token) {
// print "Getting token value for $token<br/><br/>";
if ($token == '') {
if ($token === '') {
continue;
}

Expand All @@ -354,23 +363,11 @@ public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmar

$value = NULL;

if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) {
// only generate cv if we need it
if ($cv === NULL) {
$cv = CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']);
}
foreach ($cv as $cvFieldID => $value) {
if ($cvFieldID == $cfID) {
$value = CRM_Core_BAO_CustomField::displayValue($value, $cfID);
break;
}
}
}
elseif ($token == 'checksum') {
if ($token === 'checksum') {
$cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']);
$value = "cs={$cs}";
}
elseif ($token == 'address') {
elseif ($token === 'address') {
// Build the location values array

$loc = [];
Expand Down