LP#1588948 Propagate authority->bib edit[or|_date]
authorBill Erickson <berickxx@gmail.com>
Fri, 3 Jun 2016 19:16:58 +0000 (15:16 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 24 Aug 2016 16:54:14 +0000 (12:54 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/999.functions.global.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-propage-edit-date.sql [new file with mode: 0644]

index e8228c8..b21fe2a 100644 (file)
@@ -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'
+    )
+);
+
index 97ce100..bbd76f8 100644 (file)
@@ -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 (file)
index 0000000..c22b73d
--- /dev/null
@@ -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;
+