LP#1588948 Auth propagate bib meta on change only
authorBill Erickson <berickxx@gmail.com>
Mon, 13 Jun 2016 17:57:30 +0000 (13:57 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 24 Aug 2016 16:54:14 +0000 (12:54 -0400)
Only update bib record editor and edit_date if an authority record
change propagation resulted in a modified bib record.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/999.functions.global.sql
Open-ILS/src/sql/Pg/t/authority-update-bib-propagation.pg
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql

index bbd76f8..04b0b29 100644 (file)
@@ -1487,13 +1487,20 @@ CREATE OR REPLACE FUNCTION authority.propagate_changes
     (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$
 DECLARE
     bib_rec biblio.record_entry%ROWTYPE;
+    new_marc TEXT;
 BEGIN
 
     SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid;
 
-    bib_rec.marc := vandelay.merge_record_xml(
+    new_marc := vandelay.merge_record_xml(
         bib_rec.marc, authority.generate_overlay_template(aid));
 
+    IF new_marc = bib_rec.marc THEN
+        -- Authority record change had no impact on this bib record.
+        -- Nothing left to do.
+        RETURN aid;
+    END IF;
+
     PERFORM 1 FROM config.global_flag 
         WHERE name = 'ingest.disable_authority_auto_update_bib_meta' 
             AND enabled;
@@ -1506,7 +1513,7 @@ BEGIN
     END IF;
 
     UPDATE biblio.record_entry SET
-        marc = bib_rec.marc,
+        marc = new_marc,
         editor = bib_rec.editor,
         edit_date = bib_rec.edit_date
     WHERE id = bid;
index 4dd5e15..201fffc 100644 (file)
@@ -6,7 +6,7 @@ editor and edit_date), but includes general tests for confirming authority
 update propagation to bib records.
 */
 
-SELECT plan(8);
+SELECT plan(9);
 
 INSERT INTO actor.usr (profile, ident_type, usrname, home_ou, family_name,
             passwd, first_given_name, expire_date, dob, suffix)
@@ -52,6 +52,25 @@ SELECT is(
     'Bib edit_date is updated'
 );
 
+-- Apply a change to the authority record that has no effect on the bib.
+
+UPDATE biblio.record_entry 
+    SET editor = 1, edit_date = NOW() - '1 week'::INTERVAL
+    WHERE id = 1234512345;
+
+UPDATE authority.record_entry SET 
+    editor = CURRVAL('actor.usr_id_seq'), -- test user created above
+    marc = $$
+<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim"><leader>     nz  a22     o  4500</leader><controlfield tag="001">999999100</controlfield><controlfield tag="003">LOCAL</controlfield><controlfield tag="005">20160606150106.0</controlfield><controlfield tag="008">      ||||||||||||||||||||||||||||||||||</controlfield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">LOCAL</subfield><subfield code="c">LOCAL</subfield></datafield><datafield tag="100" ind1=" " ind2=" "><subfield code="a">Doe, Jane Smith</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="c">999999100</subfield><subfield code="t">authority</subfield><subfield code="x">test</subfield></datafield></record>
+$$
+WHERE id = 999999100;
+
+SELECT isnt(
+    (SELECT DATE(edit_date) FROM biblio.record_entry WHERE id = 1234512345),
+    CURRENT_DATE,
+    'Authority change with no effect does not update bib record'
+);
+
 -- Reset the bib data for easier testing
 
 UPDATE biblio.record_entry 
index c22b73d..b5bd375 100644 (file)
@@ -7,13 +7,20 @@ CREATE OR REPLACE FUNCTION authority.propagate_changes
     (aid BIGINT, bid BIGINT) RETURNS BIGINT AS $func$
 DECLARE
     bib_rec biblio.record_entry%ROWTYPE;
+    new_marc TEXT;
 BEGIN
 
     SELECT INTO bib_rec * FROM biblio.record_entry WHERE id = bid;
 
-    bib_rec.marc := vandelay.merge_record_xml(
+    new_marc := vandelay.merge_record_xml(
         bib_rec.marc, authority.generate_overlay_template(aid));
 
+    IF new_marc = bib_rec.marc THEN
+        -- Authority record change had no impact on this bib record.
+        -- Nothing left to do.
+        RETURN aid;
+    END IF;
+
     PERFORM 1 FROM config.global_flag 
         WHERE name = 'ingest.disable_authority_auto_update_bib_meta' 
             AND enabled;
@@ -26,7 +33,7 @@ BEGIN
     END IF;
 
     UPDATE biblio.record_entry SET
-        marc = bib_rec.marc,
+        marc = new_marc,
         editor = bib_rec.editor,
         edit_date = bib_rec.edit_date
     WHERE id = bid;