X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FMailing%2FBAO%2FMailing.php;h=a2b20bcf32dd27d459df3020d808f00d6876a3e6;hb=2bb8b30263fe38bebabf10f1d0497a486cb74f5c;hp=8af7f776c0d210ae6178151f64fdb81d5e44e828;hpb=93a395c39b460beb7321d18b5319ed05f52881e1;p=civicrm-core.git diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 8af7f776c0..a2b20bcf32 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1080,15 +1080,18 @@ ORDER BY civicrm_email.is_bulkmail DESC 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] @@ -1098,16 +1101,13 @@ ORDER BY civicrm_email.is_bulkmail DESC $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']; @@ -1148,7 +1148,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $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 @@ -1191,7 +1191,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $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']); } @@ -1300,7 +1300,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $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]); @@ -1329,7 +1329,7 @@ ORDER BY civicrm_email.is_bulkmail DESC $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 = []; @@ -1396,7 +1396,7 @@ ORDER BY civicrm_email.is_bulkmail DESC } } else { - $data = CRM_Utils_Array::value("{$type}.{$token}", $contact); + $data = $contact["{$type}.{$token}"] ?? NULL; } return $data; } @@ -1442,7 +1442,7 @@ ORDER BY civicrm_email.is_bulkmail DESC * @return CRM_Mailing_DAO_Mailing */ public static function add(&$params, $ids = []) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('mailing_id', $ids)); + $id = $params['id'] ?? $ids['mailing_id'] ?? NULL; if (empty($params['id']) && !empty($ids)) { \Civi::log('Parameter $ids is no longer used by Mailing::add. Use the api or just pass $params', ['civi.tag' => 'deprecated']); @@ -1523,7 +1523,7 @@ ORDER BY civicrm_email.is_bulkmail DESC 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']); } @@ -2858,7 +2858,7 @@ ORDER BY civicrm_mailing.name"; // 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 @@ -2951,7 +2951,7 @@ ORDER BY civicrm_mailing.name"; $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'];