Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Upgrade flexmailer symfony code to run on v3.4 and 4.4 as per core PR… #57

Merged
merged 3 commits into from
May 28, 2020

Conversation

seamuslee001
Copy link
Contributor

… #13780

ping @MikeyMJCO @totten @KarinG

`CIVICRM_FLEXMAILER_HACK_LISTENERS` and `registerListeners()` function were
used in older versions to wire-up Flexmailer's dispatchers.  This is now
accomplished via public API, `hook_civicrm_container` - seems to work, no
reason to go back.

Note: I was confused by two things:

1. The previous calls didn't look like they should work.

2. Somehow, the API override still worked - even though there was no obvious callpath to `addSubscriberService()`
   It turns out that `registerApiProvider()` handles registration with the dispatcher, so `addSubscriberService()`
   isn't actually used.
src/Services.php Outdated
$dispatcher->addListenerService($listenerSpec[0], $listenerSpec[1], $listenerSpec[2]);
$dispatcher->addSubscriberService('civi_flexmailer_api_overrides', 'Civi\FlexMailer\API\Overrides');
$dispatcher->addListener($listenerSpec[0], [new SercviceClosureArgument(new Reference($listenerSpec[1][0])), $listenerSpec[1][1]], $listenerSpec[2]);
$dispatcher->addSubscriber(new Reference('civi_flexmailer_api_overrides'));
Copy link
Member

@totten totten May 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, so this example change is much clearer than the upstream docs. 👍 I'm not certain that these lines work per se (more in a sec), but it was enlightening to read.

Digging in on this PR/function was a bit of rabbit hole...

  • Neither the upstream docs, changelog, deprecation PR, nor docs issue provide an example snippet or reference to the alternative helpers. Kudos to you for figuring a work-a-like in Symfony 4.x's class model.
  • There's a typo in the class name (Sercvice). Digging into this revealed that the function registerListeners() is never actually called. It's leftover from some alpha/beta hackery and was disabled (17f142e) when hook_civicrm_container became more reliable. This also explains things worked despite some more flaws in the old variant of registerListeners().
  • How does civi_flexmailer_api_overrides work at all? Well, it does. ✅ It's because there's a call to registerApiProvider(), and that is what really handles registration.

In core's #17380, we ultimately preserved `addListenerService()`, so this doesn't have to be removed.
@totten
Copy link
Member

totten commented May 28, 2020

Since the core PR restored addListenerService(), I've updated/simplified those bits. The calls to setPublic() seem to be backward/forward compatible. Re-ran the test suite, and it passes on core@5.13. :)

@totten totten merged commit 1c85909 into civicrm:master May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants