4 SELECT evergreen.upgrade_deps_block_check('0994', :eg_version);
6 CREATE OR REPLACE FUNCTION authority.propagate_changes
7 (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$
9 bib_rec biblio.record_entry%ROWTYPE;
13 SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid;
15 new_marc := vandelay.merge_record_xml(
16 bib_rec.marc, authority.generate_overlay_template(aid));
18 IF new_marc = bib_rec.marc THEN
19 -- Authority record change had no impact on this bib record.
20 -- Nothing left to do.
24 PERFORM 1 FROM config.global_flag
25 WHERE name = 'ingest.disable_authority_auto_update_bib_meta'
29 -- update the bib record editor and edit_date
31 SELECT editor FROM authority.record_entry WHERE id = aid);
32 bib_rec.edit_date = NOW();
35 UPDATE biblio.record_entry SET
37 editor = bib_rec.editor,
38 edit_date = bib_rec.edit_date
44 $func$ LANGUAGE PLPGSQL;
48 -- Disabled by default
49 INSERT INTO config.global_flag (name, enabled, label) VALUES (
50 'ingest.disable_authority_auto_update_bib_meta', FALSE,
52 'ingest.disable_authority_auto_update_bib_meta',
53 'Authority Automation: Disable automatic authority updates ' ||
54 'from modifying bib record editor and edit_date',
61 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
63 ashs authority.simple_heading%ROWTYPE;
64 mbe_row metabib.browse_entry%ROWTYPE;
69 IF NEW.deleted IS TRUE THEN -- If this authority is deleted
70 DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
71 DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
72 DELETE FROM authority.simple_heading WHERE record = NEW.id;
73 -- Should remove matching $0 from controlled fields at the same time?
75 -- XXX What do we about the actual linking subfields present in
76 -- authority records that target this one when this happens?
77 DELETE FROM authority.authority_linking
78 WHERE source = NEW.id OR target = NEW.id;
80 RETURN NEW; -- and we're done
83 IF TG_OP = 'UPDATE' THEN -- re-ingest?
84 PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
86 IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
90 -- Unless there's a setting stopping us, propagate these updates to any linked bib records when the heading changes
91 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled;
93 IF NOT FOUND AND NEW.heading <> OLD.heading THEN
94 PERFORM authority.propagate_changes(NEW.id);
97 DELETE FROM authority.simple_heading WHERE record = NEW.id;
98 DELETE FROM authority.authority_linking WHERE source = NEW.id;
101 INSERT INTO authority.authority_linking (source, target, field)
102 SELECT source, target, field FROM authority.calculate_authority_linking(
103 NEW.id, NEW.control_set, NEW.marc::XML
106 FOR ashs IN SELECT * FROM authority.simple_heading_set(NEW.marc) LOOP
108 INSERT INTO authority.simple_heading (record,atag,value,sort_value,thesaurus)
109 VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value, ashs.thesaurus);
110 ash_id := CURRVAL('authority.simple_heading_id_seq'::REGCLASS);
112 SELECT INTO mbe_row * FROM metabib.browse_entry
113 WHERE value = ashs.value AND sort_value = ashs.sort_value;
116 mbe_id := mbe_row.id;
118 INSERT INTO metabib.browse_entry
119 ( value, sort_value ) VALUES
120 ( ashs.value, ashs.sort_value );
122 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
125 INSERT INTO metabib.browse_entry_simple_heading_map (entry,simple_heading) VALUES (mbe_id,ash_id);
129 -- Flatten and insert the afr data
130 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
132 PERFORM authority.reingest_authority_full_rec(NEW.id);
133 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
135 PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
141 $func$ LANGUAGE PLPGSQL;