From: dbs Date: Tue, 21 Dec 2010 20:21:58 +0000 (+0000) Subject: Propagate merged authority record change to bibliographic record X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=40213e49fa00630a7e3660f82e3bf9c9c8174841;p=evergreen%2Fbjwebb.git Propagate merged authority record change to bibliographic record Launchpad bug 688015 reported that the merge of authority records resulted in the control number identifier in a controlled field in a bibliographic record changing to the right value, but the value of the field itself wasn't being changed. The problem turned out to be a confusion of the "source" and "target" values in the authority.merge_record() function. Once that was straightened out, the merge updated the controlled field as expected. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19032 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 b9c8b590a..914497151 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -70,7 +70,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0471'); -- dbs +INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- dbs CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/011.schema.authority.sql b/Open-ILS/src/sql/Pg/011.schema.authority.sql index bc11a446b..3b420b399 100644 --- a/Open-ILS/src/sql/Pg/011.schema.authority.sql +++ b/Open-ILS/src/sql/Pg/011.schema.authority.sql @@ -200,6 +200,11 @@ DECLARE ingest_same boolean; BEGIN + -- Defining our terms: + -- "target record" = the record that will survive the merge + -- "source record" = the record that is sacrifing its existence and being + -- replaced by the target record + -- 1. Update all bib records with the ID from target_record in their $0 FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre INNER JOIN authority.bib_linking abl ON abl.bib = bre.id @@ -230,7 +235,7 @@ BEGIN -- in linked bibliographic records UPDATE authority.record_entry SET deleted = FALSE - WHERE id = source_record; + WHERE id = target_record; -- 5. "Delete" source_record DELETE FROM authority.record_entry diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index ad5a7ac3a..7cf50411e 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -17325,6 +17325,11 @@ DECLARE ingest_same boolean; BEGIN + -- Defining our terms: + -- "target record" = the record that will survive the merge + -- "source record" = the record that is sacrifing its existence and being + -- replaced by the target record + -- 1. Update all bib records with the ID from target_record in their $0 FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre INNER JOIN authority.bib_linking abl ON abl.bib = bre.id @@ -17354,8 +17359,8 @@ BEGIN -- 4. Make a harmless update to target_record to trigger auto-update -- in linked bibliographic records UPDATE authority.record_entry - SET DELETED = FALSE - WHERE id = source_record; + SET deleted = FALSE + WHERE id = target_record; -- 5. "Delete" source_record DELETE FROM authority.record_entry diff --git a/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql b/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql new file mode 100644 index 000000000..fe31547d8 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0472.schema.authority-merge.sql @@ -0,0 +1,65 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0472'); -- dbs + +CREATE OR REPLACE FUNCTION authority.merge_records ( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$ +DECLARE + moved_objects INT := 0; + bib_id INT := 0; + bib_rec biblio.record_entry%ROWTYPE; + auth_link authority.bib_linking%ROWTYPE; + ingest_same boolean; +BEGIN + + -- Defining our terms: + -- "target record" = the record that will survive the merge + -- "source record" = the record that is sacrifing its existence and being + -- replaced by the target record + + -- 1. Update all bib records with the ID from target_record in their $0 + FOR bib_rec IN SELECT bre.* FROM biblio.record_entry bre + INNER JOIN authority.bib_linking abl ON abl.bib = bre.id + WHERE abl.authority = source_record LOOP + + UPDATE biblio.record_entry + SET marc = REGEXP_REPLACE(marc, + E'([^<]*?\\))' || source_record || '<', + E'\\1' || target_record || '<', 'g') + WHERE id = bib_rec.id; + + moved_objects := moved_objects + 1; + END LOOP; + + -- 2. Grab the current value of reingest on same MARC flag + SELECT enabled INTO ingest_same + FROM config.internal_flag + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + + -- 3. Temporarily set reingest on same to TRUE + UPDATE config.internal_flag + SET enabled = TRUE + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + + -- 4. Make a harmless update to target_record to trigger auto-update + -- in linked bibliographic records + UPDATE authority.record_entry + SET deleted = FALSE + WHERE id = target_record; + + -- 5. "Delete" source_record + DELETE FROM authority.record_entry + WHERE id = source_record; + + -- 6. Set "reingest on same MARC" flag back to initial value + UPDATE config.internal_flag + SET enabled = ingest_same + WHERE name = 'ingest.reingest.force_on_same_marc' + ; + + RETURN moved_objects; +END; +$func$ LANGUAGE plpgsql; + +COMMIT;