3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
11 namespace Civi\FlexMailer\Listener
;
13 use Civi\FlexMailer\Event\RunEvent
;
17 * @package Civi\FlexMailer\Listener
19 * FlexMailer is in incubation -- it's a heavily reorganized version
20 * of the old MailingJob::deliver*() functions. It hasn't been tested as
21 * thoroughly and may not have perfect parity.
23 * During incubation, we want to mostly step-aside -- for traditional
24 * mailings, simply continue using the old system.
29 * @param \CRM_Mailing_BAO_Mailing $mailing
32 public static function isFlexmailPreferred($mailing) {
33 if ($mailing->sms_provider_id
) {
37 // Use FlexMailer for new-style email blasts (with custom `template_type`).
38 if ($mailing->template_type
&& $mailing->template_type
!== 'traditional') {
42 switch (\Civi
::settings()->get('flexmailer_traditional')) {
44 // Transitional support for old hidden setting "experimentalFlexMailerEngine" (bool)
45 // TODO: Remove this. Maybe after Q4 2019.
46 // TODO: Change this to default to flexmailer
47 return (bool) \Civi
::settings()->get('experimentalFlexMailerEngine');
56 throw new \
RuntimeException("Unrecognized value for setting 'flexmailer_traditional'");
61 * Abdicate; defer to the old system during delivery.
63 * @param \Civi\FlexMailer\Event\RunEvent $e
65 public function onRun(RunEvent
$e) {
66 if (self
::isFlexmailPreferred($e->getMailing())) {
67 // OK, we'll continue running.
71 // Nope, we'll abdicate.
72 $e->stopPropagation();
73 $isDelivered = $e->getJob()->deliver(
74 $e->context
['deprecatedMessageMailer'],
75 $e->context
['deprecatedTestParams']
77 $e->setCompleted($isDelivered);
81 * Abdicate; defer to the old system when checking completeness.
83 * @param \Civi\FlexMailer\Event\CheckSendableEvent $e
85 public function onCheckSendable($e) {
86 if (self
::isFlexmailPreferred($e->getMailing())) {
87 // OK, we'll continue running.
91 $e->stopPropagation();
92 $errors = \CRM_Mailing_BAO_Mailing
::checkSendable($e->getMailing());
93 if (is_array($errors)) {
94 foreach ($errors as $key => $message) {
95 $e->setError($key, $message);;