-
-
Notifications
You must be signed in to change notification settings - Fork 827
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 Mailing_Event_BAO_Reply to use token processor #24446
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,23 +194,17 @@ public static function send($queue_id, &$mailing, &$bodyTxt, $replyto, &$bodyHTM | |
* @param string $replyto | ||
* Optional reply-to from the reply. | ||
*/ | ||
private static function autoRespond(&$mailing, $queue_id, $replyto) { | ||
$config = CRM_Core_Config::singleton(); | ||
|
||
$contacts = CRM_Contact_DAO_Contact::getTableName(); | ||
$email = CRM_Core_DAO_Email::getTableName(); | ||
$queue = CRM_Mailing_Event_DAO_Queue::getTableName(); | ||
|
||
$eq = new CRM_Core_DAO(); | ||
$eq->query( | ||
"SELECT $contacts.preferred_mail_format as format, | ||
$email.email as email, | ||
$queue.job_id as job_id, | ||
$queue.hash as hash | ||
FROM $contacts | ||
INNER JOIN $queue ON $queue.contact_id = $contacts.id | ||
INNER JOIN $email ON $queue.email_id = $email.id | ||
WHERE $queue.id = " . CRM_Utils_Type::escape($queue_id, 'Integer') | ||
private static function autoRespond(&$mailing, $queue_id, $replyto): void { | ||
|
||
$eq = CRM_Core_DAO::executeQuery( | ||
'SELECT civicrm_email.email as email, | ||
civicrm_mailing_event_queue.job_id as job_id, | ||
civicrm_mailing_event_queuee.hash as hash | ||
civicrm_email.contact_id | ||
FROM civicrm_contact | ||
INNER JOIN civicrm_mailing_event_queue ON civicrm_mailing_event_queue.contact_id = civicrm_contact.id | ||
INNER JOIN civicrm_email ON civicrm_mailing_event_queue.email_id = civicrm_email.id | ||
WHERE civicrm_mailing_event_queue.id = ' . CRM_Utils_Type::escape($queue_id, 'Integer') | ||
); | ||
$eq->fetch(); | ||
|
||
|
@@ -220,47 +214,32 @@ private static function autoRespond(&$mailing, $queue_id, $replyto) { | |
$component->id = $mailing->reply_id; | ||
$component->find(TRUE); | ||
|
||
$domain = CRM_Core_BAO_Domain::getDomain(); | ||
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); | ||
[$domainEmailName, $domainEmailAddress] = CRM_Core_BAO_Domain::getNameAndEmail(); | ||
|
||
$params = [ | ||
'subject' => $component->subject, | ||
'toEmail' => $to, | ||
'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", | ||
'replyTo' => CRM_Core_BAO_Domain::getNoReplyEmailAddress(), | ||
'returnPath' => CRM_Core_BAO_Domain::getNoReplyEmailAddress(), | ||
]; | ||
|
||
// TODO: do we need reply tokens? | ||
$html = $component->body_html; | ||
if ($component->body_text) { | ||
$text = $component->body_text; | ||
} | ||
else { | ||
$text = CRM_Utils_String::htmlToText($component->body_html); | ||
} | ||
|
||
$bao = new CRM_Mailing_BAO_Mailing(); | ||
$bao->body_text = $text; | ||
$bao->body_html = $html; | ||
$tokens = $bao->getTokens(); | ||
|
||
if ($eq->format == 'HTML' || $eq->format == 'Both') { | ||
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); | ||
$html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, NULL, $tokens['html']); | ||
} | ||
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { | ||
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); | ||
$text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, NULL, $tokens['text']); | ||
} | ||
$params['html'] = $html; | ||
$params['text'] = $text; | ||
$html = CRM_Utils_Token::replaceMailingTokens($component->body_html, $mailing, NULL, $component->body_html); | ||
$text = CRM_Utils_Token::replaceMailingTokens($component->body_text, $mailing, NULL, $component->body_text); | ||
|
||
CRM_Mailing_BAO_Mailing::addMessageIdHeader($params, 'a', $eq->job_id, $queue_id, $eq->hash); | ||
if (CRM_Core_BAO_MailSettings::includeMessageId()) { | ||
$params['messageId'] = $params['Message-ID']; | ||
} | ||
CRM_Utils_Mail::send($params); | ||
\CRM_Core_BAO_MessageTemplate::sendTemplate([ | ||
'envelope' => $params, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eileenmcnaughton I'm not seeing how envelope key is being used I would have thought that this should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah - that function is horrible - really confusing. We really need a sane api wrapper for it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well writing the unit test helped me prove that thing works so yeh bloody confusing that is for sure |
||
'tokenContext' => ['contactId' => $eq->contact_id], | ||
// Template view options | ||
'messageTemplate' => [ | ||
'msg_subject' => $component->subject, | ||
'msg_text' => $html, | ||
'msg_html' => $text, | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton missing a comma at the end of this one and also a typo in the table name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks - will try to get to back to this before the rc is cut - otherwise will revert #24235 or do a temp patch on that