From: miker Date: Fri, 25 Jun 2010 20:32:58 +0000 (+0000) Subject: add stored procs to implement authority propagation if links exist; add trigger to... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2997f3ca5bca13bf166509b8f6158f0544056921;p=evergreen%2Fbjwebb.git add stored procs to implement authority propagation if links exist; add trigger to optionally fire this propagation (default ON) git-svn-id: svn://svn.open-ils.org/ILS/trunk@16817 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 12c11c17d..ad7698243 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -57,7 +57,6 @@ INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_located_uri'); INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_full_rec'); INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_rec_descriptor'); INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_field_entry'); -INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_authority_linking'); CREATE TABLE config.global_flag ( label TEXT NOT NULL @@ -69,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0318'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0319'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 621a038b7..298807f6d 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -883,6 +883,44 @@ BEGIN END; $func$ LANGUAGE PLPGSQL; +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) RETURNS SETOF BIGINT AS $func$ + SELECT authority.propagate_changes( authority, bib ) FROM authority.bib_linking WHERE authority = $1; +$func$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$ +BEGIN + + IF NEW.deleted IS TRUE THEN -- If this authority is deleted + RETURN NEW; -- and ... we're done + END IF; + + IF TG_OP = 'UPDATE' THEN -- re-ingest? + PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled; + + IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change + RETURN NEW; + END IF; + END IF; + + + -- authority change propogation + PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled; + IF NOT FOUND THEN + PERFORM authority.propagate_changes( NEW.id ); + END IF; + + RETURN NEW; +END; +$func$ LANGUAGE PLPGSQL; + + CREATE OR REPLACE FUNCTION biblio.map_authority_linking (bibid BIGINT, marc TEXT) RETURNS BIGINT AS $func$ DELETE FROM authority.bib_linking WHERE bib = $1; INSERT INTO authority.bib_linking (bib, authority) @@ -910,8 +948,6 @@ BEGIN IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change RETURN NEW; END IF; - - END IF; -- Record authority linking 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 67045d199..b7fd545a1 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -5613,6 +5613,28 @@ INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE VALUES ( + 'ingest.disable_authority_linking', + oils_i18n_gettext( + 'ingest.disable_authority_linking', + 'Authority Automation: Disable bib-authority link tracking', + 'cgf', + 'label' + ) + ); + +INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE + VALUES ( + 'ingest.disable_authority_auto_update', + oils_i18n_gettext( + 'ingest.disable_authority_auto_update', + 'Authority Automation: Disable automatic authority updating (requires link tracking)', + 'cgf', + 'label' + ) + ); + +INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE + VALUES ( 'cat.bib.use_id_for_tcn', oils_i18n_gettext( 'cat.bib.use_id_for_tcn', diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 57c6a7be5..92c1e719f 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1116,6 +1116,8 @@ CREATE TRIGGER fingerprint_tgr BEFORE INSERT OR UPDATE ON biblio.record_entry FO CREATE TRIGGER aaa_indexing_ingest_or_delete AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.indexing_ingest_or_delete (); CREATE TRIGGER bbb_simple_rec_trigger AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_trigger (); +CREATE TRIGGER aaa_auth_ingest_or_delete AFTER INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE authority.indexing_ingest_or_delete (); + -- Utility routines, callable via cstore CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_val INTERVAL ) diff --git a/Open-ILS/src/sql/Pg/upgrade/0319.schema.authority-update-propogation.sql b/Open-ILS/src/sql/Pg/upgrade/0319.schema.authority-update-propogation.sql new file mode 100644 index 000000000..735f87056 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0319.schema.authority-update-propogation.sql @@ -0,0 +1,72 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0319'); --miker + +-- Making this a global_flag (UI accessible) instead of an internal_flag +INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE + VALUES ( + 'ingest.disable_authority_linking', + oils_i18n_gettext( + 'ingest.disable_authority_linking', + 'Authority Automation: Disable bib-authority link tracking', + 'cgf', + 'label' + ) + ); +UPDATE config.global_flag SET enabled = (SELECT enabled FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking'); +DELETE FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking'; + +INSERT INTO config.global_flag (name, label) -- defaults to enabled=FALSE + VALUES ( + 'ingest.disable_authority_auto_update', + oils_i18n_gettext( + 'ingest.disable_authority_auto_update', + 'Authority Automation: Disable automatic authority updating (requires link tracking)', + 'cgf', + 'label' + ) + ); + + +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 $2; +$func$ LANGUAGE SQL; + +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; +$func$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION authority.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$ +BEGIN + + IF NEW.deleted IS TRUE THEN -- If this authority is deleted + RETURN NEW; -- and ... we're done + END IF; + + IF TG_OP = 'UPDATE' THEN -- re-ingest? + PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled; + + IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change + RETURN NEW; + END IF; + END IF; + + + -- authority change propogation + PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_auto_update' AND enabled; + IF NOT FOUND THEN + PERFORM authority.propagate_changes( NEW.id ); + END IF; + + RETURN NEW; +END; +$func$ LANGUAGE PLPGSQL; + +CREATE TRIGGER aaa_auth_ingest_or_delete AFTER INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE authority.indexing_ingest_or_delete (); + + +COMMIT; +