JBAS-1728 SCKO SQL deploy/revert repairs
authorBill Erickson <berickxx@gmail.com>
Thu, 22 Jun 2017 15:30:54 +0000 (11:30 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
* 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 <berickxx@gmail.com>
KCLS/sql/schema/deploy/selfcheck-email-receipts.sql
KCLS/sql/schema/revert/selfcheck-email-receipts.sql

index 981a9d4..58965b6 100644 (file)
@@ -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;
index 981ead1..f851847 100644 (file)
@@ -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;