Problem Definition

The DefaultSmsProvider::send() is dispatching the SmsEvents::MESSAGE_OUTGOING_POST_PROCESSand SmsEvents::MESSAGE_POST_PROCESS multiple times for each invocation of the ::send() method. This is not consistent with the other post process events in ::queue() and ::incoming() where the post process is invoked once per method call.

Resolution

Move the event dispatching code outside the foreach loop so it runs only once.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

almaudoh created an issue. See original summary.

dpi’s picture

Status: Needs review » Needs work
Issue tags: +Needs documentation, +Needs tests

I slept on this one since I couldn't remember my rationale for doing this. But now I remember!:

They are executed within the loop because if a subsequent (second, third, etc) $plugin::send execution fails then ALL of the post process events will not be executed. The plugin methods are allowed to throw exceptions, and the exceptions are intentionally permitted to bubble outside of the provider methods.

This aspect should have been documented and tests added. My bad.

---

There's no downside to running the post process events multiple times. So long as the post process event is only invoked on each message once.

The reason ::send is special is because messages can be chunked into multiple messages beforehand. Gateway plugins used may also vary at that point.

This does not apply to ::incoming because they cant be chunked. And the messages can only come from one gateway.

It does apply to ::queue if the direction is outgoing.

---

Hopefully that helps. Again, my fault