3 SELECT evergreen.upgrade_deps_block_check('0897', :eg_version);
5 CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete() RETURNS TRIGGER AS $BODY$
7 ashs authority.simple_heading%ROWTYPE;
8 mbe_row metabib.browse_entry%ROWTYPE;
13 IF NEW.deleted IS TRUE THEN -- If this authority is deleted
14 DELETE FROM authority.bib_linking WHERE authority = NEW.id; -- Avoid updating fields in bibs that are no longer visible
15 DELETE FROM authority.full_rec WHERE record = NEW.id; -- Avoid validating fields against deleted authority records
16 DELETE FROM authority.simple_heading WHERE record = NEW.id;
17 -- Should remove matching $0 from controlled fields at the same time?
19 -- XXX What do we about the actual linking subfields present in
20 -- authority records that target this one when this happens?
21 DELETE FROM authority.authority_linking
22 WHERE source = NEW.id OR target = NEW.id;
24 RETURN NEW; -- and we're done
27 IF TG_OP = 'UPDATE' THEN -- re-ingest?
28 PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
30 IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
34 -- Unless there's a setting stopping us, propagate these updates to any linked bib records
35 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled;
38 PERFORM authority.propagate_changes(NEW.id);
41 DELETE FROM authority.simple_heading WHERE record = NEW.id;
42 DELETE FROM authority.authority_linking WHERE source = NEW.id;
45 INSERT INTO authority.authority_linking (source, target, field)
46 SELECT source, target, field FROM authority.calculate_authority_linking(
47 NEW.id, NEW.control_set, NEW.marc::XML
50 FOR ashs IN SELECT * FROM authority.simple_heading_set(NEW.marc) LOOP
52 INSERT INTO authority.simple_heading (record,atag,value,sort_value)
53 VALUES (ashs.record, ashs.atag, ashs.value, ashs.sort_value);
54 ash_id := CURRVAL('authority.simple_heading_id_seq'::REGCLASS);
56 SELECT INTO mbe_row * FROM metabib.browse_entry
57 WHERE value = ashs.value AND sort_value = ashs.sort_value;
62 INSERT INTO metabib.browse_entry
63 ( value, sort_value ) VALUES
64 ( ashs.value, ashs.sort_value );
66 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
69 INSERT INTO metabib.browse_entry_simple_heading_map (entry,simple_heading) VALUES (mbe_id,ash_id);
73 -- Flatten and insert the afr data
74 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_full_rec' AND enabled;
76 PERFORM authority.reingest_authority_full_rec(NEW.id);
77 PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_rec_descriptor' AND enabled;
79 PERFORM authority.reingest_authority_rec_descriptor(NEW.id);
85 $BODY$ LANGUAGE plpgsql;