Merge pull request #21264 from civicrm/5.41
[civicrm-core.git] / CRM / Core / BAO / MessageTemplate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 use Civi\Api4\MessageTemplate;
19
20 require_once 'Mail/mime.php';
21
22 /**
23 * Class CRM_Core_BAO_MessageTemplate.
24 */
25 class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate {
26
27 /**
28 * Fetch object based on array of properties.
29 *
30 * @param array $params
31 * (reference ) an assoc array of name/value pairs.
32 * @param array $defaults
33 * (reference ) an assoc array to hold the flattened values.
34 *
35 * @return CRM_Core_DAO_MessageTemplate
36 */
37 public static function retrieve(&$params, &$defaults) {
38 $messageTemplates = new CRM_Core_DAO_MessageTemplate();
39 $messageTemplates->copyValues($params);
40 if ($messageTemplates->find(TRUE)) {
41 CRM_Core_DAO::storeValues($messageTemplates, $defaults);
42 return $messageTemplates;
43 }
44 return NULL;
45 }
46
47 /**
48 * Update the is_active flag in the db.
49 *
50 * @param int $id
51 * Id of the database record.
52 * @param bool $is_active
53 * Value we want to set the is_active field.
54 *
55 * @return bool
56 * true if we found and updated the object, else false
57 */
58 public static function setIsActive($id, $is_active) {
59 return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_MessageTemplate', $id, 'is_active', $is_active);
60 }
61
62 /**
63 * Add the Message Templates.
64 *
65 * @param array $params
66 * Reference array contains the values submitted by the form.
67 *
68 *
69 * @return object
70 * @throws \CiviCRM_API3_Exception
71 * @throws \Civi\API\Exception\UnauthorizedException
72 */
73 public static function add(&$params) {
74 // System Workflow Templates have a specific wodkflow_id in them but normal user end message templates don't
75 // If we have an id check to see if we are update, and need to check if original is a system workflow or not.
76 $systemWorkflowPermissionDeniedMessage = 'Editing or creating system workflow messages requires edit system workflow message templates permission or the edit message templates permission';
77 $userWorkflowPermissionDeniedMessage = 'Editing or creating user driven workflow messages requires edit user-driven message templates or the edit message templates permission';
78 if (!empty($params['check_permissions'])) {
79 if (!CRM_Core_Permission::check('edit message templates')) {
80 if (!empty($params['id'])) {
81 $details = civicrm_api3('MessageTemplate', 'getSingle', ['id' => $params['id']]);
82 if (!empty($details['workflow_id']) || !empty($details['workflow_name'])) {
83 if (!CRM_Core_Permission::check('edit system workflow message templates')) {
84 throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
85 }
86 }
87 elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
88 throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $userWorkflowPermissionDeniedMessage]));
89 }
90 }
91 else {
92 if (!empty($params['workflow_id']) || !empty($params['workflow_name'])) {
93 if (!CRM_Core_Permission::check('edit system workflow message templates')) {
94 throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
95 }
96 }
97 elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
98 throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $userWorkflowPermissionDeniedMessage]));
99 }
100 }
101 }
102 }
103 $hook = empty($params['id']) ? 'create' : 'edit';
104 CRM_Utils_Hook::pre($hook, 'MessageTemplate', CRM_Utils_Array::value('id', $params), $params);
105
106 if (!empty($params['file_id']) && is_array($params['file_id']) && count($params['file_id'])) {
107 $fileParams = $params['file_id'];
108 unset($params['file_id']);
109 }
110
111 // The workflow_id and workflow_name should be sync'd. But what mix of inputs do we have to work with?
112 switch ((empty($params['workflow_id']) ? '' : 'id') . (empty($params['workflow_name']) ? '' : 'name')) {
113 case 'id':
114 $params['workflow_name'] = array_search($params['workflow_id'], self::getWorkflowNameIdMap());
115 break;
116
117 case 'name':
118 $params['workflow_id'] = self::getWorkflowNameIdMap()[$params['workflow_name']] ?? NULL;
119 break;
120
121 case 'idname':
122 $map = self::getWorkflowNameIdMap();
123 if ($map[$params['workflow_name']] != $params['workflow_id']) {
124 throw new CRM_Core_Exception("The workflow_id and workflow_name are mismatched. Note: You only need to submit one or the other.");
125 }
126 break;
127
128 case '':
129 // OK, don't care.
130 break;
131
132 default:
133 throw new \RuntimeException("Bad code");
134 }
135
136 $messageTemplates = new CRM_Core_DAO_MessageTemplate();
137 $messageTemplates->copyValues($params);
138 $messageTemplates->save();
139
140 if (!empty($fileParams)) {
141 $params['file_id'] = $fileParams;
142 CRM_Core_BAO_File::filePostProcess(
143 $params['file_id']['location'],
144 NULL,
145 'civicrm_msg_template',
146 $messageTemplates->id,
147 NULL,
148 TRUE,
149 $params['file_id'],
150 'file_id',
151 $params['file_id']['type']
152 );
153 }
154
155 CRM_Utils_Hook::post($hook, 'MessageTemplate', $messageTemplates->id, $messageTemplates);
156 return $messageTemplates;
157 }
158
159 /**
160 * Delete the Message Templates.
161 *
162 * @param int $messageTemplatesID
163 *
164 * @throws \CRM_Core_Exception
165 */
166 public static function del($messageTemplatesID) {
167 // make sure messageTemplatesID is an integer
168 if (!CRM_Utils_Rule::positiveInteger($messageTemplatesID)) {
169 throw new CRM_Core_Exception(ts('Invalid Message template'));
170 }
171
172 // Set mailing msg template col to NULL
173 $query = "UPDATE civicrm_mailing
174 SET msg_template_id = NULL
175 WHERE msg_template_id = %1";
176
177 $params = [1 => [$messageTemplatesID, 'Integer']];
178 CRM_Core_DAO::executeQuery($query, $params);
179
180 $messageTemplates = new CRM_Core_DAO_MessageTemplate();
181 $messageTemplates->id = $messageTemplatesID;
182 $messageTemplates->delete();
183 CRM_Core_Session::setStatus(ts('Selected message template has been deleted.'), ts('Deleted'), 'success');
184 }
185
186 /**
187 * Get the Message Templates.
188 *
189 *
190 * @param bool $all
191 *
192 * @param bool $isSMS
193 *
194 * @return array
195 */
196 public static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
197 $msgTpls = [];
198
199 $messageTemplates = new CRM_Core_DAO_MessageTemplate();
200 $messageTemplates->is_active = 1;
201 $messageTemplates->is_sms = $isSMS;
202
203 if (!$all) {
204 $messageTemplates->workflow_id = 'NULL';
205 }
206 $messageTemplates->find();
207 while ($messageTemplates->fetch()) {
208 $msgTpls[$messageTemplates->id] = $messageTemplates->msg_title;
209 }
210 asort($msgTpls);
211 return $msgTpls;
212 }
213
214 /**
215 * @param int $contactId
216 * @param $email
217 * @param int $messageTemplateID
218 * @param $from
219 *
220 * @return bool|NULL
221 * @throws \CRM_Core_Exception
222 */
223 public static function sendReminder($contactId, $email, $messageTemplateID, $from) {
224 CRM_Core_Error::deprecatedWarning('CRM_Core_BAO_MessageTemplate::sendReminder is deprecated and will be removed in a future version of CiviCRM');
225
226 $messageTemplates = new CRM_Core_DAO_MessageTemplate();
227 $messageTemplates->id = $messageTemplateID;
228
229 $domain = CRM_Core_BAO_Domain::getDomain();
230 $result = NULL;
231 $hookTokens = [];
232
233 if ($messageTemplates->find(TRUE)) {
234 $body_text = $messageTemplates->msg_text;
235 $body_html = $messageTemplates->msg_html;
236 $body_subject = $messageTemplates->msg_subject;
237 if (!$body_text) {
238 $body_text = CRM_Utils_String::htmlToText($body_html);
239 }
240
241 $params = [['contact_id', '=', $contactId, 0, 0]];
242 [$contact] = CRM_Contact_BAO_Query::apiQuery($params);
243
244 //CRM-4524
245 $contact = reset($contact);
246
247 if (!$contact || is_a($contact, 'CRM_Core_Error')) {
248 return NULL;
249 }
250
251 //CRM-5734
252
253 // get tokens to be replaced
254 $tokens = array_merge(CRM_Utils_Token::getTokens($body_text),
255 CRM_Utils_Token::getTokens($body_html),
256 CRM_Utils_Token::getTokens($body_subject));
257
258 // get replacement text for these tokens
259 $returnProperties = ["preferred_mail_format" => 1];
260 if (isset($tokens['contact'])) {
261 foreach ($tokens['contact'] as $key => $value) {
262 $returnProperties[$value] = 1;
263 }
264 }
265 [$details] = CRM_Utils_Token::getTokenDetails([$contactId],
266 $returnProperties,
267 NULL, NULL, FALSE,
268 $tokens,
269 'CRM_Core_BAO_MessageTemplate');
270 $contact = reset($details);
271
272 // call token hook
273 $hookTokens = [];
274 CRM_Utils_Hook::tokens($hookTokens);
275 $categories = array_keys($hookTokens);
276
277 // do replacements in text and html body
278 $type = ['html', 'text'];
279 foreach ($type as $key => $value) {
280 $bodyType = "body_{$value}";
281 if ($$bodyType) {
282 CRM_Utils_Token::replaceGreetingTokens($$bodyType, NULL, $contact['contact_id']);
283 $$bodyType = CRM_Utils_Token::replaceDomainTokens($$bodyType, $domain, TRUE, $tokens, TRUE);
284 $$bodyType = CRM_Utils_Token::replaceContactTokens($$bodyType, $contact, FALSE, $tokens, FALSE, TRUE);
285 $$bodyType = CRM_Utils_Token::replaceComponentTokens($$bodyType, $contact, $tokens, TRUE);
286 $$bodyType = CRM_Utils_Token::replaceHookTokens($$bodyType, $contact, $categories, TRUE);
287 }
288 }
289 $html = $body_html;
290 $text = $body_text;
291
292 $smarty = CRM_Core_Smarty::singleton();
293 foreach ([
294 'text',
295 'html',
296 ] as $elem) {
297 $$elem = $smarty->fetch("string:{$$elem}");
298 }
299
300 // do replacements in message subject
301 $messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, FALSE, $tokens);
302 $messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, TRUE, $tokens);
303 $messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $tokens, TRUE);
304 $messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, TRUE);
305
306 $messageSubject = $smarty->fetch("string:{$messageSubject}");
307
308 // set up the parameters for CRM_Utils_Mail::send
309 $mailParams = [
310 'groupName' => 'Scheduled Reminder Sender',
311 'from' => $from,
312 'toName' => $contact['display_name'],
313 'toEmail' => $email,
314 'subject' => $messageSubject,
315 ];
316 if (!$html || $contact['preferred_mail_format'] == 'Text' ||
317 $contact['preferred_mail_format'] == 'Both'
318 ) {
319 // render the &amp; entities in text mode, so that the links work
320 $mailParams['text'] = str_replace('&amp;', '&', $text);
321 }
322 if ($html && ($contact['preferred_mail_format'] == 'HTML' ||
323 $contact['preferred_mail_format'] == 'Both'
324 )
325 ) {
326 $mailParams['html'] = $html;
327 }
328
329 $result = CRM_Utils_Mail::send($mailParams);
330 }
331
332 return $result;
333 }
334
335 /**
336 * Revert a message template to its default subject+text+HTML state.
337 *
338 * @param int $id id of the template
339 *
340 * @throws \CRM_Core_Exception
341 */
342 public static function revert($id) {
343 $diverted = new CRM_Core_BAO_MessageTemplate();
344 $diverted->id = (int) $id;
345 $diverted->find(1);
346
347 if ($diverted->N != 1) {
348 throw new CRM_Core_Exception(ts('Did not find a message template with id of %1.', [1 => $id]));
349 }
350
351 $orig = new CRM_Core_BAO_MessageTemplate();
352 $orig->workflow_id = $diverted->workflow_id;
353 $orig->is_reserved = 1;
354 $orig->find(1);
355
356 if ($orig->N != 1) {
357 throw new CRM_Core_Exception(ts('Message template with id of %1 does not have a default to revert to.', [1 => $id]));
358 }
359
360 $diverted->msg_subject = $orig->msg_subject;
361 $diverted->msg_text = $orig->msg_text;
362 $diverted->msg_html = $orig->msg_html;
363 $diverted->pdf_format_id = is_null($orig->pdf_format_id) ? 'null' : $orig->pdf_format_id;
364 $diverted->save();
365 }
366
367 /**
368 * Render a message template.
369 *
370 * This method is very similar to `sendTemplate()` - accepting most of the same arguments
371 * and emitting similar hooks. However, it specifically precludes the possibility of
372 * sending a message. It only renders.
373 *
374 * @param $params
375 * Mixed render parameters. See sendTemplate() for more details.
376 * @return array
377 * Rendered message, consistent of 'subject', 'text', 'html'
378 * Ex: ['subject' => 'Hello Bob', 'text' => 'It\'s been so long since we sent you an automated notification!']
379 * @throws \API_Exception
380 * @throws \CRM_Core_Exception
381 * @see sendTemplate()
382 */
383 public static function renderTemplate($params) {
384 $forbidden = ['from', 'toName', 'toEmail', 'cc', 'bcc', 'replyTo'];
385 $intersect = array_intersect($forbidden, array_keys($params));
386 if (!empty($intersect)) {
387 throw new \CRM_Core_Exception(sprintf("renderTemplate() received forbidden fields (%s)",
388 implode(',', $intersect)));
389 }
390
391 $mailContent = [];
392 // sendTemplate has had an obscure feature - if you omit `toEmail`, then it merely renders.
393 // At some point, we may want to invert the relation between renderTemplate/sendTemplate, but for now this is a smaller patch.
394 [$sent, $mailContent['subject'], $mailContent['text'], $mailContent['html']] = static::sendTemplate($params);
395 return $mailContent;
396 }
397
398 /**
399 * Send an email from the specified template based on an array of params.
400 *
401 * @param array $params
402 * A string-keyed array of function params, see function body for details.
403 *
404 * @return array
405 * Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
406 * @throws \CRM_Core_Exception
407 * @throws \API_Exception
408 */
409 public static function sendTemplate($params) {
410 $defaults = [
411 // option value name of the template
412 'valueName' => NULL,
413 // ID of the template
414 'messageTemplateID' => NULL,
415 // content of the message template
416 // Ex: ['msg_subject' => 'Hello {contact.display_name}', 'msg_html' => '...', 'msg_text' => '...']
417 // INTERNAL: 'messageTemplate' is currently only intended for use within civicrm-core only. For downstream usage, future updates will provide comparable public APIs.
418 'messageTemplate' => NULL,
419 // contact id if contact tokens are to be replaced
420 'contactId' => NULL,
421 // additional template params (other than the ones already set in the template singleton)
422 'tplParams' => [],
423 // additional token params (passed to the TokenProcessor)
424 // INTERNAL: 'tokenContext' is currently only intended for use within civicrm-core only. For downstream usage, future updates will provide comparable public APIs.
425 'tokenContext' => [],
426 // the From: header
427 'from' => NULL,
428 // the recipient’s name
429 'toName' => NULL,
430 // the recipient’s email - mail is sent only if set
431 'toEmail' => NULL,
432 // the Cc: header
433 'cc' => NULL,
434 // the Bcc: header
435 'bcc' => NULL,
436 // the Reply-To: header
437 'replyTo' => NULL,
438 // email attachments
439 'attachments' => NULL,
440 // whether this is a test email (and hence should include the test banner)
441 'isTest' => FALSE,
442 // filename of optional PDF version to add as attachment (do not include path)
443 'PDFFilename' => NULL,
444 // Disable Smarty?
445 'disableSmarty' => FALSE,
446 ];
447 $params = array_merge($defaults, $params);
448
449 // Core#644 - handle Email ID passed as "From".
450 if (isset($params['from'])) {
451 $params['from'] = CRM_Utils_Mail::formatFromAddress($params['from']);
452 }
453
454 CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
455 if (!is_int($params['messageTemplateID']) && !is_null($params['messageTemplateID'])) {
456 CRM_Core_Error::deprecatedWarning('message template id should be an integer');
457 $params['messageTemplateID'] = (int) $params['messageTemplateID'];
458 }
459 $mailContent = self::loadTemplate((string) $params['valueName'], $params['isTest'], $params['messageTemplateID'] ?? NULL, $params['groupName'] ?? '', $params['messageTemplate'], $params['subject'] ?? NULL);
460
461 $params['tokenContext'] = array_merge([
462 'smarty' => (bool) !$params['disableSmarty'],
463 'contactId' => $params['contactId'],
464 ], $params['tokenContext']);
465 $rendered = CRM_Core_TokenSmarty::render(CRM_Utils_Array::subset($mailContent, ['text', 'html', 'subject']), $params['tokenContext'], $params['tplParams']);
466 if (isset($rendered['subject'])) {
467 $rendered['subject'] = trim(preg_replace('/[\r\n]+/', ' ', $rendered['subject']));
468 }
469 $nullSet = ['subject' => NULL, 'text' => NULL, 'html' => NULL];
470 $mailContent = array_merge($nullSet, $mailContent, $rendered);
471
472 // send the template, honouring the target user’s preferences (if any)
473 $sent = FALSE;
474
475 // create the params array
476 $params['subject'] = $mailContent['subject'];
477 $params['text'] = $mailContent['text'];
478 $params['html'] = $mailContent['html'];
479
480 if ($params['toEmail']) {
481 $contactParams = [['email', 'LIKE', $params['toEmail'], 0, 1]];
482 [$contact] = CRM_Contact_BAO_Query::apiQuery($contactParams);
483
484 $prefs = array_pop($contact);
485
486 if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] === 'HTML') {
487 $params['text'] = NULL;
488 }
489
490 if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] === 'Text') {
491 $params['html'] = NULL;
492 }
493
494 $config = CRM_Core_Config::singleton();
495 if (isset($params['isEmailPdf']) && $params['isEmailPdf'] == 1) {
496 $pdfHtml = CRM_Contribute_BAO_ContributionPage::addInvoicePdfToEmail($params['contributionId'], $params['contactId']);
497 if (empty($params['attachments'])) {
498 $params['attachments'] = [];
499 }
500 $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $mailContent['format']);
501 }
502 $pdf_filename = '';
503 if ($config->doNotAttachPDFReceipt &&
504 $params['PDFFilename'] &&
505 $params['html']
506 ) {
507 if (empty($params['attachments'])) {
508 $params['attachments'] = [];
509 }
510 $params['attachments'][] = CRM_Utils_Mail::appendPDF($params['PDFFilename'], $params['html'], $mailContent['format']);
511 if (isset($params['tplParams']['email_comment'])) {
512 $params['html'] = $params['tplParams']['email_comment'];
513 $params['text'] = strip_tags($params['tplParams']['email_comment']);
514 }
515 }
516
517 $sent = CRM_Utils_Mail::send($params);
518
519 if ($pdf_filename) {
520 unlink($pdf_filename);
521 }
522 }
523
524 return [$sent, $mailContent['subject'], $mailContent['text'], $mailContent['html']];
525 }
526
527 /**
528 * Create a map between workflow_name and workflow_id.
529 *
530 * @return array
531 * Array(string $workflowName => int $workflowId)
532 */
533 protected static function getWorkflowNameIdMap() {
534 // There's probably some more clever way to do this, but this seems simple.
535 return CRM_Core_DAO::executeQuery('SELECT cov.name as name, cov.id as id FROM civicrm_option_group cog INNER JOIN civicrm_option_value cov on cov.option_group_id=cog.id WHERE cog.name LIKE %1', [
536 1 => ['msg_tpl_workflow_%', 'String'],
537 ])->fetchMap('name', 'id');
538 }
539
540 /**
541 * Load the specified template.
542 *
543 * @param string $workflowName
544 * @param bool $isTest
545 * @param int|null $messageTemplateID
546 * @param string $groupName
547 * @param array|null $messageTemplateOverride
548 * Optionally, record with msg_subject, msg_text, msg_html.
549 * If omitted, the record will be loaded from workflowName/messageTemplateID.
550 * @param string|null $subjectOverride
551 * This option is the older, wonkier version of $messageTemplate['msg_subject']...
552 *
553 * @return array
554 * @throws \API_Exception
555 * @throws \CRM_Core_Exception
556 */
557 protected static function loadTemplate(string $workflowName, bool $isTest, int $messageTemplateID = NULL, $groupName = NULL, ?array $messageTemplateOverride = NULL, ?string $subjectOverride = NULL): array {
558 $base = ['msg_subject' => NULL, 'msg_text' => NULL, 'msg_html' => NULL, 'pdf_format_id' => NULL];
559 if (!$workflowName && !$messageTemplateID) {
560 throw new CRM_Core_Exception(ts("Message template's option value or ID missing."));
561 }
562
563 $apiCall = MessageTemplate::get(FALSE)
564 ->addSelect('msg_subject', 'msg_text', 'msg_html', 'pdf_format_id', 'id')
565 ->addWhere('is_default', '=', 1);
566
567 if ($messageTemplateID) {
568 $apiCall->addWhere('id', '=', (int) $messageTemplateID);
569 }
570 else {
571 $apiCall->addWhere('workflow_name', '=', $workflowName);
572 }
573 $messageTemplate = array_merge($base, $apiCall->execute()->first() ?: [], $messageTemplateOverride ?: []);
574 if (empty($messageTemplate['id']) && empty($messageTemplateOverride)) {
575 if ($messageTemplateID) {
576 throw new CRM_Core_Exception(ts('No such message template: id=%1.', [1 => $messageTemplateID]));
577 }
578 throw new CRM_Core_Exception(ts('No message template with workflow name %1.', [1 => $workflowName]));
579 }
580
581 $mailContent = [
582 'subject' => $messageTemplate['msg_subject'],
583 'text' => $messageTemplate['msg_text'],
584 'html' => $messageTemplate['msg_html'],
585 'format' => $messageTemplate['pdf_format_id'],
586 // Workflow name is the field in the message templates table that denotes the
587 // workflow the template is used for. This is intended to eventually
588 // replace the non-standard option value/group implementation - see
589 // https://github.com/civicrm/civicrm-core/pull/17227 and the longer
590 // discussion on https://github.com/civicrm/civicrm-core/pull/17180
591 'workflow_name' => $workflowName,
592 // Note messageTemplateID is the id but when present we also know it was specifically requested.
593 'messageTemplateID' => $messageTemplateID,
594 // Group name & valueName are deprecated parameters. At some point it will not be passed out.
595 // https://github.com/civicrm/civicrm-core/pull/17180
596 'groupName' => $groupName,
597 'valueName' => $workflowName,
598 ];
599
600 CRM_Utils_Hook::alterMailContent($mailContent);
601
602 // add the test banner (if requested)
603 if ($isTest) {
604 $testText = MessageTemplate::get(FALSE)
605 ->setSelect(['msg_subject', 'msg_text', 'msg_html'])
606 ->addWhere('workflow_name', '=', 'test_preview')
607 ->addWhere('is_default', '=', TRUE)
608 ->execute()->first();
609
610 $mailContent['subject'] = $testText['msg_subject'] . $mailContent['subject'];
611 $mailContent['text'] = $testText['msg_text'] . $mailContent['text'];
612 $mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testText['msg_html']}", $mailContent['html']);
613 }
614
615 if (!empty($subjectOverride)) {
616 CRM_Core_Error::deprecatedWarning('CRM_Core_BAO_MessageTemplate: $params[subject] is deprecated. Use $params[messageTemplate][msg_subject] instead.');
617 $mailContent['subject'] = $subjectOverride;
618 }
619
620 return $mailContent;
621 }
622
623 }