From a81ec19a294af82a5f77e462731be945be5891bb Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 13 Feb 2013 15:52:54 -0500 Subject: [PATCH] LP#1124498 Patron notification via email for card expiration The attached code creates an action/trigger event which notifies a patron, via email, that their card is about to expire. There are two portions to this code: Signed-off-by: Michael Peters Signed-off-by: Josh Stompro Signed-off-by: Michele Morgan Signed-off-by: Ben Shum --- .../action_trigger_filters.json.example | 6 ++ .../XXXX.30day.expiration.prenotice.sql | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.30day.expiration.prenotice.sql diff --git a/Open-ILS/examples/action_trigger_filters.json.example b/Open-ILS/examples/action_trigger_filters.json.example index d24759d157..96c13d4a0a 100644 --- a/Open-ILS/examples/action_trigger_filters.json.example +++ b/Open-ILS/examples/action_trigger_filters.json.example @@ -9,6 +9,12 @@ ] } }, + "expire" : { + "context_org":"home_ou", + "filter" : + { "active":"t", + "deleted":"f" } + }, "hold_request.shelf_expires_soon" : { "context_org": "pickup_lib", "filter": { diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.30day.expiration.prenotice.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.30day.expiration.prenotice.sql new file mode 100644 index 0000000000..4b0c3959e2 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.30day.expiration.prenotice.sql @@ -0,0 +1,56 @@ +BEGIN; + +--create hook for actor.usr.expire_date +INSERT INTO action_trigger.hook (key, core_type, description, passive) + VALUES ('expire', 'au', 'Card is expired', 't'); + + --SQL to create event definition for 30 day card pre-expiration notice +--Inactive, owned by top of org tree by default. Modify to suit needs. +--Can set reactor to 'ProcessTemplate' for testing. Will generate emails in DB, but not actually send. + +INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, template) + VALUES ('t', '1', '30 Day Card Expiration Courtesy Notice', 'expire', 'NOOP_True', 'SendEmail', '-30 days', 'expire_date', 'usr', '-29 days', + $$ +[%- USE date -%] +[%- user = target -%] +[%- lib = target.home_ou -%] +To: [%- params.recipient_email || user.email %] +From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +Reply-To: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +Errors-To: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %] +Subject: Courtesy Notice - Library Card Expiration in 30 days + +Dear [% user.first_given_name %] [% user.family_name %], + +Our records indicate your library card is due to expire in 30 days. Please visit your local library at your convenience to renew your card in order to avoid a disruption in access to library service. + +Sincerely, +[% lib.name %] + +Contact your library for more information: + +[% lib.name %] +[%- SET addr = lib.mailing_address -%] +[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %] +[% lib.mailing_address.street1 %] [% lib.mailing_address.street2 %] +[% lib.mailing_address.city %], [% lib.mailing_address.state %] +[% lib.mailing_address.post_code %] +[% lib.phone %] + +$$); + +--get current value in sequence +SELECT currval('action_trigger.event_definition_id_seq'); + +--send from email address parameter +INSERT INTO action_trigger.event_params (event_def, param, value) + VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'sender_email', 'evergreen@example.org'); + +--insert environment values +INSERT INTO action_trigger.environment (event_def, path) + VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address'); + +INSERT INTO action_trigger.environment (event_def, path) + VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'home_ou.billing_address'); + +COMMIT; -- 2.43.2