From 167c03f71675788f53773a519fc4ad43ac27c724 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 22 Jun 2017 11:30:54 -0400 Subject: [PATCH] JBAS-1728 SCKO SQL deploy/revert repairs * Fix syntax errors on revert script * Fix formatting of email so the 'Subject:' line starts at the front of the line, which is required for it to appear as a subject in email. * Minor reformatting for eye-ease. Signed-off-by: Bill Erickson --- .../sql/schema/deploy/selfcheck-email-receipts.sql | 108 ++++++++++----------- .../sql/schema/revert/selfcheck-email-receipts.sql | 28 +++--- 2 files changed, 62 insertions(+), 74 deletions(-) diff --git a/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql b/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql index 981a9d43f9..58965b6e19 100644 --- a/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql +++ b/KCLS/sql/schema/deploy/selfcheck-email-receipts.sql @@ -5,76 +5,68 @@ BEGIN; DO $$ BEGIN IF evergreen.insert_on_deploy() THEN - INSERT INTO action_trigger.hook ( - key, - core_type, - description, - passive - ) VALUES ( - 'email.selfcheck.checkout', - 'circ', - 'Formats circ objects for self-checkout email.', - TRUE - ); - INSERT INTO action_trigger.event_definition ( - active, - owner, - name, - hook, - validator, - reactor, - group_field, - template ) - VALUES ( - TRUE, - 1, - 'Email Self-Checkout Receipt', - 'email.selfcheck.checkout', - 'NOOP_True', - 'SendEmail', - 'usr', - $email_receipt_template$ +INSERT INTO action_trigger.hook ( + key, + core_type, + description, + passive + ) VALUES ( + 'email.selfcheck.checkout', + 'circ', + 'Formats circ objects for self-checkout email.', + TRUE +); + +INSERT INTO action_trigger.event_definition ( + active, owner, name, hook, validator, reactor, group_field, template ) +VALUES ( + TRUE, + 1, + 'Email Self-Checkout Receipt', + 'email.selfcheck.checkout', + 'NOOP_True', + 'SendEmail', + 'usr', + $email_receipt_template$ [%- USE date -%] [%- user = target.0.usr -%] To: [%- params.recipient_email || user.email %] From: [%- params.sender_email || helpers.get_org_setting(target.0.circ_lib.id, 'org.bounced_emails') || lib.email || default_sender %] - Subject: Checkout Receipt +Subject: Checkout Receipt - Dear [% user.first_given_name %], +Dear [% user.first_given_name %], - You checked out the following items: +You checked out the following items: [% FOR circ IN target %] - [%- copy_details = helpers.get_copy_bib_basics(circ.target_copy.id) -%] - Title: [% copy_details.title %] - Author: [% copy_details.author %] - Call Number: [% circ.target_copy.call_number.label %] - Barcode: [% circ.target_copy.barcode %] - Due Date: [% date.format(helpers.format_date(circ.due_date), '%m/%d/%Y') %] - Library: [% circ.circ_lib.name %] + [%- copy_details = helpers.get_copy_bib_basics(circ.target_copy.id) -%] + [% loop.count %]. Title: [% copy_details.title %] + Author: [% copy_details.author %] + Call Number: [% circ.target_copy.call_number.label %] + Barcode: [% circ.target_copy.barcode %] + Due Date: [% date.format(helpers.format_date(circ.due_date), '%m/%d/%Y') %] + Library: [% circ.circ_lib.name %] - [% END %] - $email_receipt_template$); +[% END %] - +$email_receipt_template$ +); - INSERT INTO action_trigger.environment ( - event_def, - path - ) VALUES ( - currval('action_trigger.event_definition_id_seq'), - 'target_copy.call_number' - ), ( - currval('action_trigger.event_definition_id_seq'), - 'target_copy.location' - ), ( - currval('action_trigger.event_definition_id_seq'), - 'usr' - ), ( - currval('action_trigger.event_definition_id_seq'), - 'circ_lib' - ); +INSERT INTO action_trigger.environment (event_def, path) VALUES + ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.call_number' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'target_copy.location' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'usr' + ), ( + currval('action_trigger.event_definition_id_seq'), + 'circ_lib' + ); END IF; diff --git a/KCLS/sql/schema/revert/selfcheck-email-receipts.sql b/KCLS/sql/schema/revert/selfcheck-email-receipts.sql index 981ead13cc..f8518475a6 100644 --- a/KCLS/sql/schema/revert/selfcheck-email-receipts.sql +++ b/KCLS/sql/schema/revert/selfcheck-email-receipts.sql @@ -2,24 +2,20 @@ BEGIN; -DO $$ -BEGIN - IF evergreen.insert_on_deploy() THEN +DELETE FROM action_trigger.event WHERE event_def IN ( + select id from action_trigger.event_definition + where hook='email.selfcheck.checkout' +); - DELETE FROM action_trigger.environment WHERE event_def = - (SELECT id FROM action_trigger.event_definition - WHERE active and hook = 'email.selfcheck.checkout'); +DELETE FROM action_trigger.environment WHERE event_def IN ( + SELECT id FROM action_trigger.event_definition + WHERE hook = 'email.selfcheck.checkout' +); - DELETE FROM action_trigger.event WHERE event_def=(select id from action_trigger.event_definition where active and hook='email.selfcheck.checkout'); +DELETE FROM action_trigger.event_definition + WHERE hook = 'email.selfcheck.checkout'; - DELETE FROM action_trigger.event_definition - - DELETE FROM action_trigger.hook WHERE key = 'email.selfcheck.checkout'; - WHERE active and - hook = 'email.selfcheck.checkout' AND - name = 'Email Self-Checkout Receipt'; - - END IF; -- insert-on-deploy -END $$; +DELETE FROM action_trigger.hook + WHERE key = 'email.selfcheck.checkout'; COMMIT; -- 2.11.0