]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.data.hold_buckets.sql
LP#1838995: (follow-up) adjust ID for new permission
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.data.hold_buckets.sql
1
2 BEGIN;
3
4 CREATE TABLE action.batch_hold_event (
5     id          SERIAL  PRIMARY KEY,
6     staff       INT     NOT NULL REFERENCES actor.usr (id) ON UPDATE CASCADE ON DELETE CASCADE,
7     bucket      INT     NOT NULL REFERENCES container.user_bucket (id) ON UPDATE CASCADE ON DELETE CASCADE,
8     target      INT     NOT NULL,
9     hold_type   TEXT    NOT NULL DEFAULT 'T', -- maybe different hold types in the future...
10     run_date    TIMESTAMP WITH TIME ZONE    NOT NULL DEFAULT NOW(),
11     cancelled   TIMESTAMP WITH TIME ZONE
12 );
13
14 CREATE TABLE action.batch_hold_event_map (
15     id                  SERIAL  PRIMARY KEY,
16     batch_hold_event    INT     NOT NULL REFERENCES action.batch_hold_event (id) ON UPDATE CASCADE ON DELETE CASCADE,
17     hold                INT     NOT NULL REFERENCES action.hold_request (id) ON UPDATE CASCADE ON DELETE CASCADE
18 );
19
20 INSERT INTO container.user_bucket_type (code,label) VALUES ('hold_subscription','Hold Group Container');
21
22 INSERT INTO config.org_unit_setting_type
23     (name, label, description, grp, datatype)
24 VALUES (
25     'holds.subscription.randomize',
26     oils_i18n_gettext(
27         'holds.subscription.randomize',
28         'Randomize group hold order',
29         'coust',
30         'label'
31     ),
32     oils_i18n_gettext(
33         'holds.subscription.randomize',
34         'When placing a batch group hold, randomize the order of the patrons receiving the holds so they are not always in the same order.',
35         'coust',
36         'description'
37     ),
38     'holds',
39     'bool'
40 );
41
42 INSERT INTO permission.perm_list (id,code,description)
43   VALUES ( 628, 'MANAGE_HOLD_GROUPS', oils_i18n_gettext(628, 'Manage hold groups and hold group events', 'ppl', 'description'));
44
45 INSERT INTO action.hold_request_cancel_cause (id,label)
46   VALUES ( 8, oils_i18n_gettext(8, 'Hold Group Event rollback', 'ahrcc', 'label'));
47
48 INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, delay_field, group_field, cleanup_success, template)
49     VALUES ('f', 1, 'Hold Group Hold Placed for Patron Email Notification', 'hold_request.success', 'NOOP_True', 'SendEmail', '30 minutes', 'request_time', 'usr', 'CreateHoldNotification',
50 $$
51 [%- USE date -%]
52 [%- user = target.0.usr -%]
53 To: [%- params.recipient_email || user.email %]
54 From: [%- params.sender_email || default_sender %]
55 Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
56 Subject: Subcription Hold placed for you
57 Auto-Submitted: auto-generated
58
59 Dear [% user.family_name %], [% user.first_given_name %]
60 The following items have been placed on hold for you:
61
62 [% FOR hold IN target %]
63     [%- copy_details = helpers.get_copy_bib_basics(hold.current_copy.id) -%]
64     Title: [% copy_details.title %]
65     Author: [% copy_details.author %]
66     Call Number: [% hold.current_copy.call_number.label %]
67     Barcode: [% hold.current_copy.barcode %]
68     Library: [% hold.pickup_lib.name %]
69 [% END %]
70
71 $$);
72
73 INSERT INTO action_trigger.environment (event_def, path ) VALUES
74 ( currval('action_trigger.event_definition_id_seq'), 'usr' ),
75 ( currval('action_trigger.event_definition_id_seq'), 'pickup_lib' ),
76 ( currval('action_trigger.event_definition_id_seq'), 'current_copy.call_number' );
77
78
79 INSERT INTO action_trigger.event_definition (
80     active, owner, name, hook, validator, reactor, cleanup_success,
81     delay, delay_field, group_field, template
82 ) VALUES (
83     false, 1, 'Hold Group Hold Placed for Patron SMS Notification', 'hold_request.success', 'NOOP_True',
84     'SendSMS', 'CreateHoldNotification', '00:30:00', 'shelf_time', 'sms_notify',
85     '[%- USE date -%]
86 [%- user = target.0.usr -%]
87 From: [%- params.sender_email || default_sender %]
88 Date: [%- date.format(date.now, ''%a, %d %b %Y %T -0000'', gmt => 1) %]
89 To: [%- params.recipient_email || helpers.get_sms_gateway_email(target.0.sms_carrier,target.0.sms_notify) %]
90 Subject: [% target.size %] subscription hold(s) placed for you
91 Auto-Submitted: auto-generated
92
93 [% FOR hold IN target %][%-
94   bibxml = helpers.xml_doc( hold.current_copy.call_number.record.marc );
95   title = "";
96   FOR part IN bibxml.findnodes(''//*[@tag="245"]/*[@code="a"]'');
97     title = title _ part.textContent;
98   END;
99   author = bibxml.findnodes(''//*[@tag="100"]/*[@code="a"]'').textContent;
100 %][% hold.usr.first_given_name %]:[% title %] @ [% hold.pickup_lib.name %]
101 [% END %]
102 '
103 );
104
105 INSERT INTO action_trigger.environment (
106     event_def,
107     path
108 ) VALUES (
109     currval('action_trigger.event_definition_id_seq'),
110     'current_copy.call_number.record.simple_record'
111 ), (
112     currval('action_trigger.event_definition_id_seq'),
113     'usr'
114 ), (
115     currval('action_trigger.event_definition_id_seq'),
116     'pickup_lib.billing_address'
117 );
118
119 INSERT INTO action_trigger.event_params (event_def, param, value)
120     VALUES (currval('action_trigger.event_definition_id_seq'), 'check_sms_notify', 1);
121
122
123 COMMIT;
124