Skip to content

Commit

Permalink
CRM-19690 - Enable FlexMailer (if present)
Browse files Browse the repository at this point in the history
FlexMailer (https://github.com/civicrm/org.civicrm.flexmailer/) is a
refactoring of the email-delivery logic from the Mailing BAOs.  The primary
goal is to make the email-delivery logic more extensible by exposing a
better set of events for extension-authors.  Sadly, the original code is a
bit toxic (originally lacking in tests; thick with many features; using some
quirky dataflows), which means:

 1. Any refactoring of it poses a high risk.
 2. The refactoring should ideally be done with iteration/validation as
    an optional extension.

This patch aims to be the bare-minimum core patch required to facilitate a
better 'leap by extension'.  The main priorities are:

 1. Minimize risk -- no impact on existing users who can continue using existing logic.
 2. Enable iteration/testing/deployment of an optional extension in real-world scenarios.
 3. Keep any core hacks clear and isolated - don't rashly commit to new, public APIs.
  • Loading branch information
totten committed Jan 18, 2017
1 parent 720633b commit 2cdf7a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CRM/Mailing/BAO/MailingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ public static function runJobs($testParams = NULL, $mode = NULL) {
}

// Compose and deliver each child job
$isComplete = $job->deliver($mailer, $testParams);
if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_DELIVER')) {
$isComplete = Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_DELIVER, array($job, $mailer, $testParams));
}
else {
$isComplete = $job->deliver($mailer, $testParams);
}

CRM_Utils_Hook::post('create', 'CRM_Mailing_DAO_Spool', $job->id, $isComplete);

Expand Down Expand Up @@ -483,6 +488,10 @@ public function queue($testParams = NULL) {
* @return void
*/
public function deliver(&$mailer, $testParams = NULL) {
if (\Civi::settings()->get('experimentalFlexMailerEngine')) {
throw new \RuntimeException("Cannot use legacy deliver() when experimentalFlexMailerEngine is enabled");
}

$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(TRUE);
Expand Down
8 changes: 8 additions & 0 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function createContainer() {
"CRM_Mailing_Tokens"
));//->addTag('kernel.event_subscriber');

if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SERVICES')) {
\Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_SERVICES, array($container));
}

return $container;
}

Expand Down Expand Up @@ -162,6 +166,10 @@ public function createEventDispatcher($container) {
$dispatcher->addSubscriberService('crm_mailing_tokens', 'CRM_Mailing_Tokens');
$dispatcher->addSubscriberService('crm_mailing_action_tokens', 'CRM_Mailing_ActionTokens');

if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_LISTENERS')) {
\Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_LISTENERS, array($dispatcher));
}

return $dispatcher;
}

Expand Down

0 comments on commit 2cdf7a3

Please sign in to comment.