]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0689.data.record_print_format_update.sql
LP#1772955: Only include xacts with balance in summary
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0689.data.record_print_format_update.sql
1 -- Evergreen DB patch 0689.data.record_print_format_update.sql
2 --
3 -- Updates print and email templates for bib record actions
4 --
5 BEGIN;
6
7
8 -- check whether patch can be applied
9 SELECT evergreen.upgrade_deps_block_check('0689', :eg_version);
10
11 UPDATE action_trigger.event_definition SET template = $$
12 <div>
13     <style> li { padding: 8px; margin 5px; }</style>
14     <ol>
15     [% FOR cbreb IN target %]
16     [% FOR item IN cbreb.items;
17         bre_id = item.target_biblio_record_entry;
18
19         bibxml = helpers.unapi_bre(bre_id, {flesh => '{mra}'});
20         FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
21             title = title _ part.textContent;
22         END;
23
24         author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
25         item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
26         publisher = bibxml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
27         pubdate = bibxml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
28         isbn = bibxml.findnodes('//*[@tag="020"]/*[@code="a"]').textContent;
29         issn = bibxml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
30         upc = bibxml.findnodes('//*[@tag="024"]/*[@code="a"]').textContent;
31         %]
32
33         <li>
34             Bib ID# [% bre_id %]<br/>
35             [% IF isbn %]ISBN: [% isbn %]<br/>[% END %]
36             [% IF issn %]ISSN: [% issn %]<br/>[% END %]
37             [% IF upc  %]UPC:  [% upc %]<br/>[% END %]
38             Title: [% title %]<br />
39             Author: [% author %]<br />
40             Publication Info: [% publisher %] [% pubdate %]<br/>
41             Item Type: [% item_type %]
42         </li>
43     [% END %]
44     [% END %]
45     </ol>
46 </div>
47 $$ 
48 WHERE hook = 'biblio.format.record_entry.print' AND id < 100; -- sample data
49
50
51 UPDATE action_trigger.event_definition SET delay = '00:00:00', template = $$
52 [%- SET user = target.0.owner -%]
53 To: [%- params.recipient_email || user.email %]
54 From: [%- params.sender_email || default_sender %]
55 Subject: Bibliographic Records
56
57 [% FOR cbreb IN target %]
58 [% FOR item IN cbreb.items;
59     bre_id = item.target_biblio_record_entry;
60
61     bibxml = helpers.unapi_bre(bre_id, {flesh => '{mra}'});
62     FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
63         title = title _ part.textContent;
64     END;
65
66     author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
67     item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
68     publisher = bibxml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
69     pubdate = bibxml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
70     isbn = bibxml.findnodes('//*[@tag="020"]/*[@code="a"]').textContent;
71     issn = bibxml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
72     upc = bibxml.findnodes('//*[@tag="024"]/*[@code="a"]').textContent;
73 %]
74
75 [% loop.count %]/[% loop.size %].  Bib ID# [% bre_id %] 
76 [% IF isbn %]ISBN: [% isbn _ "\n" %][% END -%]
77 [% IF issn %]ISSN: [% issn _ "\n" %][% END -%]
78 [% IF upc  %]UPC:  [% upc _ "\n" %] [% END -%]
79 Title: [% title %]
80 Author: [% author %]
81 Publication Info: [% publisher %] [% pubdate %]
82 Item Type: [% item_type %]
83
84 [% END %]
85 [% END %]
86 $$ 
87 WHERE hook = 'biblio.format.record_entry.email' AND id < 100; -- sample data
88
89 -- remove a swath of unused environment entries
90
91 DELETE FROM action_trigger.environment env 
92     USING action_trigger.event_definition def 
93     WHERE env.event_def = def.id AND 
94         env.path != 'items' AND 
95         def.hook = 'biblio.format.record_entry.print' AND 
96         def.id < 100; -- sample data
97
98 DELETE FROM action_trigger.environment env 
99     USING action_trigger.event_definition def 
100     WHERE env.event_def = def.id AND 
101         env.path != 'items' AND 
102         env.path != 'owner' AND 
103         def.hook = 'biblio.format.record_entry.email' AND 
104         def.id < 100; -- sample data
105
106 COMMIT;