]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql
LP#1588948 Propagate authority->bib edit[or|_date]
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.schema.authority-propage-edit-date.sql
1
2 BEGIN;
3
4 DROP FUNCTION authority.propagate_changes (BIGINT, BIGINT);
5
6 CREATE OR REPLACE FUNCTION authority.propagate_changes 
7     (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$
8 DECLARE
9     bib_rec biblio.record_entry%ROWTYPE;
10 BEGIN
11
12     SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid;
13
14     bib_rec.marc := vandelay.merge_record_xml(
15         bib_rec.marc, authority.generate_overlay_template(aid));
16
17     PERFORM 1 FROM config.global_flag 
18         WHERE name = 'ingest.disable_authority_auto_update_bib_meta' 
19             AND enabled;
20
21     IF NOT FOUND THEN 
22         -- update the bib record editor and edit_date
23         bib_rec.editor := (
24             SELECT editor FROM authority.record_entry WHERE id = aid);
25         bib_rec.edit_date = NOW();
26     END IF;
27
28     UPDATE biblio.record_entry SET
29         marc = bib_rec.marc,
30         editor = bib_rec.editor,
31         edit_date = bib_rec.edit_date
32     WHERE id = bid;
33
34     RETURN aid;
35
36 END;
37 $func$ LANGUAGE PLPGSQL;
38
39
40 -- DATA
41 -- Disabled by default
42 INSERT INTO config.global_flag (name, enabled, label) VALUES (
43     'ingest.disable_authority_auto_update_bib_meta',  FALSE, 
44     oils_i18n_gettext(
45         'ingest.disable_authority_auto_update_bib_meta',
46         'Authority Automation: Disable automatic authority updates ' ||
47             'from modifying bib record editor and edit_date',
48         'cgf',
49         'label'
50     )
51 );
52
53
54 COMMIT;
55