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]
$res = NULL;
return $res;
}
-
- // also call the hook to get contact details
- CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id);
}
$pTemplates = $this->getPreparedTemplates();
$pEmails = [];
foreach ($pTemplates as $type => $pTemplate) {
- $html = ($type == 'html') ? TRUE : FALSE;
+ $html = $type == 'html';
$pEmails[$type] = [];
$pEmail = &$pEmails[$type];
$template = &$pTemplates[$type]['template'];
$message = new Mail_mime("\n");
- $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY ? TRUE : FALSE;
+ $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY;
if ($useSmarty) {
$smarty = CRM_Core_Smarty::singleton();
// also add the contact tokens to the template
$mailParams['attachments'] = $attachments;
- $mailParams['Subject'] = CRM_Utils_Array::value('subject', $pEmails);
+ $mailParams['Subject'] = $pEmails['subject'] ?? NULL;
if (is_array($mailParams['Subject'])) {
$mailParams['Subject'] = implode('', $mailParams['Subject']);
}
$mailing->templates[$type] = CRM_Utils_Token::replaceDomainTokens(
$mailing->templates[$type],
$domain,
- $type == 'html' ? TRUE : FALSE,
+ $type == 'html',
$tokens[$type]
);
$mailing->templates[$type] = CRM_Utils_Token::replaceMailingTokens($mailing->templates[$type], $mailing, NULL, $tokens[$type]);
$token = $token_a['token'];
$data = $token;
- $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY ? TRUE : FALSE;
+ $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY;
if ($type == 'embedded_url') {
$embed_data = [];
}
}
else {
- $data = CRM_Utils_Array::value("{$type}.{$token}", $contact);
+ $data = $contact["{$type}.{$token}"] ?? NULL;
}
return $data;
}
public static function create(&$params, $ids = []) {
if (empty($params['id']) && (array_filter($ids) !== [])) {
- $params['id'] = isset($ids['mailing_id']) ? $ids['mailing_id'] : $ids['id'];
+ $params['id'] = $ids['mailing_id'] ?? $ids['id'];
\Civi::log('Parameter $ids is no longer used by Mailing::create. Use the api or just pass $params', ['civi.tag' => 'deprecated']);
}
// format the params
$params['offset'] = ($params['page'] - 1) * $params['rp'];
$params['rowCount'] = $params['rp'];
- $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
+ $params['sort'] = $params['sortBy'] ?? NULL;
$params['caseId'] = NULL;
// get contact mailings
$params['version'] = 3;
$params['offset'] = ($params['page'] - 1) * $params['rp'];
$params['limit'] = $params['rp'];
- $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
+ $params['sort'] = $params['sortBy'] ?? NULL;
$result = civicrm_api('MailingContact', 'get', $params);
return $result['values'];