From: miker Date: Fri, 12 Mar 2010 20:12:52 +0000 (+0000) Subject: adding 901c cross-check to auto-overlay logic to prevent isbn, etc auto-overlay X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=44b3f2db967067db856df1097ba238c95d9768e9;p=evergreen%2Fbjwebb.git adding 901c cross-check to auto-overlay logic to prevent isbn, etc auto-overlay git-svn-id: svn://svn.open-ils.org/ILS/trunk@15835 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 8a70fe34e..6b1c3e05a 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0193'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0194'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 5707563a5..2fdc70003 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -358,6 +358,7 @@ CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_record ( import_id BIGINT, DECLARE eg_id BIGINT; match_count INT; + match_attr vandelay.bib_attr_definition%ROWTYPE; BEGIN SELECT COUNT(*) INTO match_count FROM vandelay.bib_match WHERE queued_record = import_id; @@ -366,6 +367,17 @@ BEGIN RETURN FALSE; END IF; + SELECT d.* INTO match_attr + FROM vandelay.bib_attr_definition d + JOIN vandelay.queued_bib_record_attr a ON (a.field = d.id) + JOIN vandelay.bib_match m ON (m.matched_attr = a.id) + WHERE m.queued_record = import_id; + + IF NOT (match_attr.xpath ~ '@tag="901"' AND match_attr.xpath ~ '@code="c"') THEN + -- RAISE NOTICE 'not a 901c match'; + RETURN FALSE; + END IF; + SELECT m.eg_record INTO eg_id FROM vandelay.bib_match m WHERE m.queued_record = import_id diff --git a/Open-ILS/src/sql/Pg/upgrade/0194.schema.vandelay.internal-id-crosscheck.sql b/Open-ILS/src/sql/Pg/upgrade/0194.schema.vandelay.internal-id-crosscheck.sql new file mode 100644 index 000000000..b0254f69b --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0194.schema.vandelay.internal-id-crosscheck.sql @@ -0,0 +1,42 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0194'); -- miker + +CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_record ( import_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$ +DECLARE + eg_id BIGINT; + match_count INT; + match_attr vandelay.bib_attr_definition%ROWTYPE; +BEGIN + SELECT COUNT(*) INTO match_count FROM vandelay.bib_match WHERE queued_record = import_id; + + IF match_count <> 1 THEN + -- RAISE NOTICE 'not an exact match'; + RETURN FALSE; + END IF; + + SELECT d.* INTO match_attr + FROM vandelay.bib_attr_definition d + JOIN vandelay.queued_bib_record_attr a ON (a.field = d.id) + JOIN vandelay.bib_match m ON (m.matched_attr = a.id) + WHERE m.queued_record = import_id; + + IF NOT (match_attr.xpath ~ '@tag="901"' AND match_attr.xpath ~ '@code="c"') THEN + -- RAISE NOTICE 'not a 901c match'; + RETURN FALSE; + END IF; + + SELECT m.eg_record INTO eg_id + FROM vandelay.bib_match m + WHERE m.queued_record = import_id + LIMIT 1; + + IF eg_id IS NULL THEN + RETURN FALSE; + END IF; + + RETURN vandelay.overlay_bib_record( import_id, eg_id, merge_profile_id ); +END; +$$ LANGUAGE PLPGSQL; + +COMMIT;