LP#1749475 Rethink double-duty of SendEmail reactor collab/dbwells/lp1749475_rebase_fixup
authorDan Wells <dbw2@calvin.edu>
Thu, 21 Feb 2019 23:24:19 +0000 (18:24 -0500)
committerDan Wells <dbw2@calvin.edu>
Wed, 5 Jun 2019 16:19:42 +0000 (12:19 -0400)
commit4c760ba4b8a44f854527534389f0d2057058d5cc
treec4ad572b64f555cff96b8837296dd7ac0ab3c81e
parent42e2b281cfd4b715359a8660bee0bd8f13eaa120
LP#1749475 Rethink double-duty of SendEmail reactor

Previously, we were trying to use the same reactor, SendEmail to both
generate email previews and also to generate and send emails.  This
behavior was meant to be controlled via $user_data.

This plan is problematic, particularly for grouped events.  It is
possible for events processed by the same hook/definition to have
user_data specifying different behavior, but then for the these events
to be grouped and processed together, creating a random outcome.

We start to see this issue already in our attempts to process $user_data
safely.  We notice this variable can be either an array for grouped
events, or a hash for ungrouped, or empty for cases where it isn't
required.  We could work around that situation with layers of error
checking, but still would end up with an arbitrary value.

Since very little of SendEmail is needed to actual generate the preview,
perhaps it makes the most sense, and is more clear, if we have a
separate reactor for doing the previews.  This commit does that.

Unfortunately, in doing so, we expose another weakness; event
definitions cannot share a template.  If we want the old hook to keep
functioning, we need to duplicate the new template in the old hook and
create an entirely new "preview" hook.  This invites maintenance
problems, but still better than predictability problems.  However, in
this case, we'll just overwrite the old hook, then emulate its behavior
at the API layer.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/PreviewEmail.pm [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm
Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.AT-def-groups.sql