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

Fix values passed to tokenValues hook #16623

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CRM/Contact/Form/Task/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public function postProcess($params = NULL) {
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts, TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, $primaryLocationOnly);
$messageToken = CRM_Utils_Token::getTokens($mailingFormat);

// $details[0] is an array of [ contactID => contactDetails ]
// also get all token values
CRM_Utils_Hook::tokenValues($details[0],
$this->_contactIds,
Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/Form/Task/LabelCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public static function getRows($contactIDs, $locationTypeID, $respectDoNotMail,
$details = $query->apiQuery($params, $returnProperties, NULL, NULL, 0, $numberofContacts);

$messageToken = CRM_Utils_Token::getTokens($mailingFormat);
// $details[0] is an array of [ contactID => contactDetails ]
$details = $details[0];
$tokenFields = CRM_Contact_Form_Task_LabelCommon::getTokenData($details);

Expand Down
12 changes: 6 additions & 6 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,15 +1080,18 @@ public function compose(
elseif ($contactId === 0) {
//anonymous user
$contact = [];
CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id);
CRM_Utils_Hook::tokenValues($contact, [$contactId], $job_id);
}
else {
$params = [['contact_id', '=', $contactId, 0, 0]];
list($contact) = CRM_Contact_BAO_Query::apiQuery($params);
// $contact is an array of [ contactID => contactDetails ]

//CRM-4524
$contact = reset($contact);
// also call the hook to get contact details
CRM_Utils_Hook::tokenValues($contact, [$contactId], $job_id);

// Don't send if contact doesn't exist
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
CRM_Core_Error::debug_log_message(ts('CiviMail will not send email to a non-existent contact: %1',
[1 => $contactId]
Expand All @@ -1098,9 +1101,6 @@ public function compose(
$res = NULL;
return $res;
}

// also call the hook to get contact details
CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id);
}

$pTemplates = $this->getPreparedTemplates();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Page/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function run() {
$mailing->getFlattenedTokens(),
get_class($this)
);

// $details[0] is an array of [ contactID => contactDetails ]
$mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail,
TRUE, $details[0][$session->get('userID')], $attachments
);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public static function alterAdminPanel(&$panels) {
* tokens returned by the 'tokens' hook
*
* @param array $details
* The array to store the token values indexed by contactIDs (unless it a single).
* The array to store the token values indexed by contactIDs.
* @param array $contactIDs
* An array of contactIDs.
* @param int $jobID
Expand Down
8 changes: 3 additions & 5 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ public static function getTokenDetails(
}

$details = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, NULL, NULL, 0, count($contactIDs), TRUE, FALSE, TRUE, CRM_Contact_BAO_Query::MODE_CONTACTS, NULL, TRUE);

$contactDetails = &$details[0];

foreach ($contactIDs as $contactID) {
Expand Down Expand Up @@ -1263,8 +1262,9 @@ public static function getTokenDetails(
}
}

// $contactDetails = &$details[0] = is an array of [ contactID => contactDetails ]
// also call a hook and get token details
CRM_Utils_Hook::tokenValues($details[0],
CRM_Utils_Hook::tokenValues($contactDetails,
$contactIDs,
$jobID,
$tokens,
Expand All @@ -1291,9 +1291,7 @@ public static function getTokenDetails(
* @return array
* contactDetails with hooks swapped out
*/
public static function getAnonymousTokenDetails($contactIDs = [
0,
],
public static function getAnonymousTokenDetails($contactIDs = [0],
$returnProperties = NULL,
$skipOnHold = TRUE,
$skipDeceased = TRUE,
Expand Down
7 changes: 2 additions & 5 deletions Civi/Token/TokenCompatSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ public function onEvaluate(TokenValueEvent $e) {
$contact = array_merge($contact, $row->context['tmpTokenParams']);
}

$contactArray = !is_array($contactId) ? [$contactId => $contact] : $contact;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason for $contactId to arrive in array format here so this looks fine to me. Objections if any @eileenmcnaughton @totten ?


// Note: This is a small contract change from the past; data should be missing
// less randomly.
$contactArray = [$contactId => $contact];
\CRM_Utils_Hook::tokenValues($contactArray,
(array) $contactId,
[$contactId],
empty($row->context['mailingJobId']) ? NULL : $row->context['mailingJobId'],
$messageTokens,
$row->context['controller']
Expand Down