From 28d9ccf8df4cd3e9989d91e3053c26aca6a48e76 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 3 Jun 2016 15:16:58 -0400 Subject: [PATCH] LP#1588948 Propagate authority->bib edit[or|_date] Adds a new global flag 'ingest.disable_authority_auto_update_bib_meta', which is disabled by default. When disabled, the 'editor' and 'edit_date' columns on bib records updated via authority field propagation are updated to the value of the editor on the authority record and NOW(), respectively. When enabled, editor and edit_date are not modified. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 12 ++++ Open-ILS/src/sql/Pg/999.functions.global.sql | 38 +++++++++++-- ...XXX.schema.authority-propage-edit-date.sql | 55 +++++++++++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index e8228c8e49..b21fe2a817 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -16344,3 +16344,15 @@ INSERT INTO actor.org_unit_setting ( 'circ.patron_search.diacritic_insensitive', 'true' ); + +INSERT INTO config.global_flag (name, enabled, label) VALUES ( + 'ingest.disable_authority_auto_update_bib_meta', FALSE, + oils_i18n_gettext( + 'ingest.disable_authority_auto_update_bib_meta', + 'Authority Automation: Disable automatic authority updates ' || + 'from modifying bib record editor and edit_date', + 'cgf', + 'label' + ) +); + diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 97ce10065b..bbd76f8ccc 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1483,12 +1483,38 @@ CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON config.copy_sta CREATE TRIGGER a_opac_vis_mat_view_tgr AFTER INSERT OR UPDATE ON actor.org_unit FOR EACH ROW EXECUTE PROCEDURE asset.cache_copy_visibility(); -- Authority ingest routines -CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$ - UPDATE biblio.record_entry - SET marc = vandelay.merge_record_xml( marc, authority.generate_overlay_template( $1 ) ) - WHERE id = $2; - SELECT $1; -$func$ LANGUAGE SQL; +CREATE OR REPLACE FUNCTION authority.propagate_changes + (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$ +DECLARE + bib_rec biblio.record_entry%ROWTYPE; +BEGIN + + SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid; + + bib_rec.marc := vandelay.merge_record_xml( + bib_rec.marc, authority.generate_overlay_template(aid)); + + PERFORM 1 FROM config.global_flag + WHERE name = 'ingest.disable_authority_auto_update_bib_meta' + AND enabled; + + IF NOT FOUND THEN + -- update the bib record editor and edit_date + bib_rec.editor := ( + SELECT editor FROM authority.record_entry WHERE id = aid); + bib_rec.edit_date = NOW(); + END IF; + + UPDATE biblio.record_entry SET + marc = bib_rec.marc, + editor = bib_rec.editor, + edit_date = bib_rec.edit_date + WHERE id = bid; + + RETURN aid; + +END; +$func$ LANGUAGE PLPGSQL; CREATE OR REPLACE FUNCTION authority.propagate_changes (aid BIGINT) RETURNS SETOF BIGINT AS $func$ SELECT authority.propagate_changes( authority, bib ) FROM authority.bib_linking WHERE authority = $1; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql new file mode 100644 index 0000000000..c22b73db99 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql @@ -0,0 +1,55 @@ + +BEGIN; + +DROP FUNCTION authority.propagate_changes (BIGINT, BIGINT); + +CREATE OR REPLACE FUNCTION authority.propagate_changes + (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$ +DECLARE + bib_rec biblio.record_entry%ROWTYPE; +BEGIN + + SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid; + + bib_rec.marc := vandelay.merge_record_xml( + bib_rec.marc, authority.generate_overlay_template(aid)); + + PERFORM 1 FROM config.global_flag + WHERE name = 'ingest.disable_authority_auto_update_bib_meta' + AND enabled; + + IF NOT FOUND THEN + -- update the bib record editor and edit_date + bib_rec.editor := ( + SELECT editor FROM authority.record_entry WHERE id = aid); + bib_rec.edit_date = NOW(); + END IF; + + UPDATE biblio.record_entry SET + marc = bib_rec.marc, + editor = bib_rec.editor, + edit_date = bib_rec.edit_date + WHERE id = bid; + + RETURN aid; + +END; +$func$ LANGUAGE PLPGSQL; + + +-- DATA +-- Disabled by default +INSERT INTO config.global_flag (name, enabled, label) VALUES ( + 'ingest.disable_authority_auto_update_bib_meta', FALSE, + oils_i18n_gettext( + 'ingest.disable_authority_auto_update_bib_meta', + 'Authority Automation: Disable automatic authority updates ' || + 'from modifying bib record editor and edit_date', + 'cgf', + 'label' + ) +); + + +COMMIT; + -- 2.43.2