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