[open-ils-commits] [GIT] Evergreen ILS branch master updated. 744c0e74493d09dff1a4f7e7a1cfb6d9597cf3fc

Evergreen Git git at git.evergreen-ils.org
Tue Aug 9 15:03:50 EDT 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  744c0e74493d09dff1a4f7e7a1cfb6d9597cf3fc (commit)
       via  ada5bc49fb90f34c18bb3551c83d27ca0bb89626 (commit)
       via  720cb4391ec0149632fbaf9687edf58a4a1d1142 (commit)
       via  43f06ef45bde83713b4b2700692dcc5606fb2a91 (commit)
      from  5317ba59cace4fd62365fc084addac6a3315fcd0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 744c0e74493d09dff1a4f7e7a1cfb6d9597cf3fc
Author: Mike Rylander <mrylander at gmail.com>
Date:   Thu Aug 4 14:00:17 2016 -0400

    LP#1587639 Avoid double-update of editor/edit_date
    
    Look for an editor first, and if not found just use the existing values.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
index 2e5c248..ff474cd 100644
--- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
+++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
@@ -1786,18 +1786,19 @@ DECLARE
     merge_profile   vandelay.merge_profile%ROWTYPE;
     dyn_profile     vandelay.compile_profile%ROWTYPE;
     editor_string   TEXT;
-    editor_id       INT;
+    new_editor      INT;
+    new_edit_date   TIMESTAMPTZ;
     source_marc     TEXT;
     target_marc     TEXT;
+    eg_marc_row     authority.record_entry%ROWTYPE;
     eg_marc         TEXT;
     v_marc          TEXT;
     replace_rule    TEXT;
     match_count     INT;
-    update_fields   TEXT[];
     update_query    TEXT;
 BEGIN
 
-    SELECT  b.marc INTO eg_marc
+    SELECT  * INTO eg_marc_row
       FROM  authority.record_entry b
             JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
       LIMIT 1;
@@ -1807,6 +1808,8 @@ BEGIN
             JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
       LIMIT 1;
 
+    eg_marc := eg_marc_row.marc;
+
     IF eg_marc IS NULL OR v_marc IS NULL THEN
         -- RAISE NOTICE 'no marc for vandelay or authority record';
         RETURN FALSE;
@@ -1817,6 +1820,30 @@ BEGIN
     editor_string := 
         (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
 
+    -- If an editor value can be found, update the authority record
+    -- editor and edit_date values.
+    IF editor_string IS NOT NULL AND editor_string <> '' THEN
+
+        -- Vandelay.pm sets the value to 'usrname' when needed.  
+        SELECT id INTO new_editor
+            FROM actor.usr WHERE usrname = editor_string;
+
+        IF new_editor IS NULL THEN
+            SELECT usr INTO new_editor
+                FROM actor.card WHERE barcode = editor_string;
+        END IF;
+
+        IF new_editor IS NOT NULL THEN
+            new_edit_date := NOW();
+        ELSE -- No valid editor, use current values
+            new_editor = eg_marc_row.editor;
+            new_edit_date = eg_marc_row.edit_date;
+        END IF;
+    ELSE
+        new_editor = eg_marc_row.editor;
+        new_edit_date = eg_marc_row.edit_date;
+    END IF;
+
     dyn_profile := vandelay.compile_profile( v_marc );
 
     IF merge_profile_id IS NOT NULL THEN
@@ -1848,7 +1875,9 @@ BEGIN
     END IF;
 
     UPDATE  authority.record_entry
-      SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
+      SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule ),
+            editor = new_editor,
+            edit_date = new_edit_date
       WHERE id = eg_id;
 
     IF NOT FOUND THEN 
@@ -1864,34 +1893,6 @@ BEGIN
             import_time = NOW()
       WHERE id = import_id;
 
-    -- If an editor value can be found, update the authority record
-    -- editor and edit_date values.
-    IF editor_string IS NOT NULL AND editor_string <> '' THEN
-
-        -- Vandelay.pm sets the value to 'usrname' when needed.  
-        SELECT id INTO editor_id 
-            FROM actor.usr WHERE usrname = editor_string;
-
-        IF editor_id IS NULL THEN
-            SELECT usr INTO editor_id 
-                FROM actor.card WHERE barcode = editor_string;
-        END IF;
-
-        IF editor_id IS NOT NULL THEN
-            --only update the edit date if we have a valid editor
-            update_fields := ARRAY_APPEND(update_fields, 
-                'editor = ' || editor_id || ', edit_date = NOW()');
-        END IF;
-    END IF;
-
-    IF ARRAY_LENGTH(update_fields, 1) > 0 THEN
-        update_query := 'UPDATE authority.record_entry SET ' || 
-            ARRAY_TO_STRING(update_fields, ',') || 
-            ' WHERE id = ' || eg_id || ';';
-        --RAISE NOTICE 'query: %', update_query;
-        EXECUTE update_query;
-    END IF;
-
     RETURN TRUE;
 
 END;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql
index a8b3a91..968a520 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql
@@ -7,18 +7,19 @@ DECLARE
     merge_profile   vandelay.merge_profile%ROWTYPE;
     dyn_profile     vandelay.compile_profile%ROWTYPE;
     editor_string   TEXT;
-    editor_id       INT;
+    new_editor      INT;
+    new_edit_date   TIMESTAMPTZ;
     source_marc     TEXT;
     target_marc     TEXT;
+    eg_marc_row     authority.record_entry%ROWTYPE;
     eg_marc         TEXT;
     v_marc          TEXT;
     replace_rule    TEXT;
     match_count     INT;
-    update_fields   TEXT[];
     update_query    TEXT;
 BEGIN
 
-    SELECT  b.marc INTO eg_marc
+    SELECT  * INTO eg_marc_row
       FROM  authority.record_entry b
             JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
       LIMIT 1;
@@ -28,6 +29,8 @@ BEGIN
             JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
       LIMIT 1;
 
+    eg_marc := eg_marc_row.marc;
+
     IF eg_marc IS NULL OR v_marc IS NULL THEN
         -- RAISE NOTICE 'no marc for vandelay or authority record';
         RETURN FALSE;
@@ -38,6 +41,30 @@ BEGIN
     editor_string := 
         (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
 
+    -- If an editor value can be found, update the authority record
+    -- editor and edit_date values.
+    IF editor_string IS NOT NULL AND editor_string <> '' THEN
+
+        -- Vandelay.pm sets the value to 'usrname' when needed.  
+        SELECT id INTO new_editor
+            FROM actor.usr WHERE usrname = editor_string;
+
+        IF new_editor IS NULL THEN
+            SELECT usr INTO new_editor
+                FROM actor.card WHERE barcode = editor_string;
+        END IF;
+
+        IF new_editor IS NOT NULL THEN
+            new_edit_date := NOW();
+        ELSE -- No valid editor, use current values
+            new_editor = eg_marc_row.editor;
+            new_edit_date = eg_marc_row.edit_date;
+        END IF;
+    ELSE
+        new_editor = eg_marc_row.editor;
+        new_edit_date = eg_marc_row.edit_date;
+    END IF;
+
     dyn_profile := vandelay.compile_profile( v_marc );
 
     IF merge_profile_id IS NOT NULL THEN
@@ -69,7 +96,9 @@ BEGIN
     END IF;
 
     UPDATE  authority.record_entry
-      SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
+      SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule ),
+            editor = new_editor,
+            edit_date = new_edit_date
       WHERE id = eg_id;
 
     IF NOT FOUND THEN 
@@ -85,34 +114,6 @@ BEGIN
             import_time = NOW()
       WHERE id = import_id;
 
-    -- If an editor value can be found, update the authority record
-    -- editor and edit_date values.
-    IF editor_string IS NOT NULL AND editor_string <> '' THEN
-
-        -- Vandelay.pm sets the value to 'usrname' when needed.  
-        SELECT id INTO editor_id 
-            FROM actor.usr WHERE usrname = editor_string;
-
-        IF editor_id IS NULL THEN
-            SELECT usr INTO editor_id 
-                FROM actor.card WHERE barcode = editor_string;
-        END IF;
-
-        IF editor_id IS NOT NULL THEN
-            --only update the edit date if we have a valid editor
-            update_fields := ARRAY_APPEND(update_fields, 
-                'editor = ' || editor_id || ', edit_date = NOW()');
-        END IF;
-    END IF;
-
-    IF ARRAY_LENGTH(update_fields, 1) > 0 THEN
-        update_query := 'UPDATE authority.record_entry SET ' || 
-            ARRAY_TO_STRING(update_fields, ',') || 
-            ' WHERE id = ' || eg_id || ';';
-        --RAISE NOTICE 'query: %', update_query;
-        EXECUTE update_query;
-    END IF;
-
     RETURN TRUE;
 
 END;

commit ada5bc49fb90f34c18bb3551c83d27ca0bb89626
Author: Bill Erickson <berickxx at gmail.com>
Date:   Wed Jun 1 11:55:27 2016 -0400

    LP#1587639 Vand. authority updates release notes
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/docs/RELEASE_NOTES_NEXT/Cataloging/auth_bib_update.adoc b/docs/RELEASE_NOTES_NEXT/Cataloging/auth_bib_update.adoc
new file mode 100644
index 0000000..72af4b8
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Cataloging/auth_bib_update.adoc
@@ -0,0 +1,6 @@
+Authority Record Import Updates Editor, Edit Date.
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Importing an authority record via MARC Batch Import/Export now causes the 
+authority record's editor and edit_date fields to be updated.  The editor
+value may come from the MARC 905u field or, if none is present, the user 
+performing the import.

commit 720cb4391ec0149632fbaf9687edf58a4a1d1142
Author: Bill Erickson <berickxx at gmail.com>
Date:   Wed Jun 1 11:51:00 2016 -0400

    LP#1587639 Vand. authority updates PGTAP
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/t/vandelay-auth-import.sql b/Open-ILS/src/sql/Pg/t/vandelay-auth-import.sql
new file mode 100644
index 0000000..1b11dee
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/t/vandelay-auth-import.sql
@@ -0,0 +1,73 @@
+BEGIN;
+
+SELECT plan(3);
+
+-------------------------
+-- Setup test environment
+--   User w/ library card
+--   Vandelay settings (merge profile, queue)
+--   "Pre-loaded" authority record to be overlayed
+--   Matching authority record added to Vandelay queue
+--     including 905u with user barcode
+-------------------------
+
+INSERT INTO actor.usr (profile, ident_type, usrname, home_ou, family_name,
+            passwd, first_given_name, expire_date, dob, suffix)
+    VALUES (13, 1, 'TEST_USER', 1, 'TESTER', 'TEST1234', 'TEST',
+            NOW() + '3 years'::INTERVAL, NULL, NULL);
+
+INSERT INTO actor.card (barcode, usr)
+    VALUES ('TEST_BARCODE', CURRVAL('actor.usr_id_seq'));
+
+UPDATE actor.usr
+    SET card = CURRVAL('actor.card_id_seq')
+    WHERE id = CURRVAL('actor.usr_id_seq');
+
+INSERT INTO vandelay.merge_profile 
+    (owner, name, preserve_spec) VALUES (1, 'TEST', '901c');
+
+INSERT INTO vandelay.authority_queue (owner, name)
+    VALUES (CURRVAL('actor.usr_id_seq'), 'TEST');
+
+INSERT INTO authority.record_entry (id, edit_date, last_xact_id, marc)
+    VALUES (1234512345, now() - '15 days'::INTERVAL, 'TEST',
+   '<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"><leader>00208nz  a2200097o  45 0</leader><controlfield tag="001">73</controlfield><controlfield tag="003">CONS</controlfield><controlfield tag="005">20021207110052.0</controlfield><controlfield tag="008">021207n| acannaabn          |n aac     d</controlfield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(IISG)IISGa11554924</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">IISG</subfield><subfield code="c">IISG</subfield></datafield><datafield tag="100" ind1="0" ind2=" "><subfield code="a">Maloy, Eileen</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="t">authority</subfield></datafield></record>');
+
+INSERT INTO vandelay.queued_authority_record (queue, purpose, marc)
+    SELECT CURRVAL('vandelay.queue_id_seq'), 'overlay',
+    '<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"><leader>00208nz  a2200097o  45 0</leader><controlfield tag="001">73</controlfield><controlfield tag="003">CONS</controlfield><controlfield tag="005">20021207110052.0</controlfield><controlfield tag="008">021207n| acannaabn          |n aac     d</controlfield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(IISG)IISGa11554924</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">IISG</subfield><subfield code="c">IISG</subfield></datafield><datafield tag="100" ind1="0" ind2=" "><subfield code="a">Maloy, Eileen</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="c">1234512345</subfield><subfield code="t">authority</subfield></datafield><datafield tag="905" ind1=" " ind2=" "><subfield code="u">' 
+        || barcode || '</subfield></datafield></record>'
+    FROM actor.card
+    WHERE id = CURRVAL('actor.card_id_seq');
+
+-----------------------
+-- Import the record --
+-----------------------
+SELECT ok(
+    (
+        SELECT vandelay.overlay_authority_record(queued_record, eg_record,
+            CURRVAL('vandelay.merge_profile_id_seq')::int )
+        FROM vandelay.authority_match
+        WHERE queued_record = CURRVAL('vandelay.queued_record_id_seq')
+    ),
+    'Function call succeeded'
+);
+
+---------------------------------
+-- Test for new values of editor,
+-- edit date, and source
+---------------------------------
+SELECT is(
+    (SELECT editor::bigint FROM authority.record_entry ORDER BY id DESC LIMIT 1),
+    CURRVAL('actor.usr_id_seq'),
+    'Editor was updated'
+);
+
+SELECT is(
+    (SELECT edit_date::date FROM authority.record_entry ORDER BY id DESC LIMIT 1),
+    CURRENT_DATE,
+    'Edit Date was updated'
+);
+
+ROLLBACK;
+

commit 43f06ef45bde83713b4b2700692dcc5606fb2a91
Author: Bill Erickson <berickxx at gmail.com>
Date:   Wed Jun 1 10:40:45 2016 -0400

    LP#1587639 Vandelay authority update editor/edit_date
    
    Update the editor and edit_date of authority records when modified by
    Vandelay merge/overlay.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
index e53729d..39c857f 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
@@ -990,17 +990,17 @@ sub import_record_list_impl {
 
             my $marcdoc = XML::LibXML->new->parse_string($rec->marc);
             $rec->marc($U->strip_marc_fields($e, $marcdoc, $strip_grps));
+        }
 
-            # Set the imported record's 905$u, so
-            # editor/creator/edit_date are set correctly.
-            $marcdoc = XML::LibXML->new->parse_string($rec->marc);
-            $rec->marc($U->set_marc_905u($marcdoc, $requestor->usrname));
+        # Set the imported record's 905$u, so
+        # editor/edit_date are set correctly.
+        my $marcdoc = XML::LibXML->new->parse_string($rec->marc);
+        $rec->marc($U->set_marc_905u($marcdoc, $requestor->usrname));
 
-            unless ($e->$update_func($rec)) {
-                $$report_args{evt} = $e->die_event;
-                finish_rec_import_attempt($report_args);
-                next;
-            }
+        unless ($e->$update_func($rec)) {
+            $$report_args{evt} = $e->die_event;
+            finish_rec_import_attempt($report_args);
+            next;
         }
 
         if(defined $overlay_target) {
diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
index 6c9325d..2e5c248 100644
--- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
+++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
@@ -1785,12 +1785,16 @@ CREATE OR REPLACE FUNCTION vandelay.overlay_authority_record ( import_id BIGINT,
 DECLARE
     merge_profile   vandelay.merge_profile%ROWTYPE;
     dyn_profile     vandelay.compile_profile%ROWTYPE;
+    editor_string   TEXT;
+    editor_id       INT;
     source_marc     TEXT;
     target_marc     TEXT;
     eg_marc         TEXT;
     v_marc          TEXT;
     replace_rule    TEXT;
     match_count     INT;
+    update_fields   TEXT[];
+    update_query    TEXT;
 BEGIN
 
     SELECT  b.marc INTO eg_marc
@@ -1808,6 +1812,11 @@ BEGIN
         RETURN FALSE;
     END IF;
 
+    -- Extract the editor string before any modification to the vandelay
+    -- MARC occur.
+    editor_string := 
+        (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
+
     dyn_profile := vandelay.compile_profile( v_marc );
 
     IF merge_profile_id IS NOT NULL THEN
@@ -1842,17 +1851,48 @@ BEGIN
       SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
       WHERE id = eg_id;
 
-    IF FOUND THEN
-        UPDATE  vandelay.queued_authority_record
-          SET   imported_as = eg_id,
-                import_time = NOW()
-          WHERE id = import_id;
-        RETURN TRUE;
+    IF NOT FOUND THEN 
+        -- Import/merge failed.  Nothing left to do.
+        RETURN FALSE;
     END IF;
 
-    -- RAISE NOTICE 'update of authority.record_entry failed';
+    -- Authority record successfully merged / imported.
 
-    RETURN FALSE;
+    -- Update the vandelay record to show the successful import.
+    UPDATE  vandelay.queued_authority_record
+      SET   imported_as = eg_id,
+            import_time = NOW()
+      WHERE id = import_id;
+
+    -- If an editor value can be found, update the authority record
+    -- editor and edit_date values.
+    IF editor_string IS NOT NULL AND editor_string <> '' THEN
+
+        -- Vandelay.pm sets the value to 'usrname' when needed.  
+        SELECT id INTO editor_id 
+            FROM actor.usr WHERE usrname = editor_string;
+
+        IF editor_id IS NULL THEN
+            SELECT usr INTO editor_id 
+                FROM actor.card WHERE barcode = editor_string;
+        END IF;
+
+        IF editor_id IS NOT NULL THEN
+            --only update the edit date if we have a valid editor
+            update_fields := ARRAY_APPEND(update_fields, 
+                'editor = ' || editor_id || ', edit_date = NOW()');
+        END IF;
+    END IF;
+
+    IF ARRAY_LENGTH(update_fields, 1) > 0 THEN
+        update_query := 'UPDATE authority.record_entry SET ' || 
+            ARRAY_TO_STRING(update_fields, ',') || 
+            ' WHERE id = ' || eg_id || ';';
+        --RAISE NOTICE 'query: %', update_query;
+        EXECUTE update_query;
+    END IF;
+
+    RETURN TRUE;
 
 END;
 $$ LANGUAGE PLPGSQL;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql
new file mode 100644
index 0000000..a8b3a91
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-vandeley-edit-date.sql
@@ -0,0 +1,123 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION vandelay.overlay_authority_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
+DECLARE
+    merge_profile   vandelay.merge_profile%ROWTYPE;
+    dyn_profile     vandelay.compile_profile%ROWTYPE;
+    editor_string   TEXT;
+    editor_id       INT;
+    source_marc     TEXT;
+    target_marc     TEXT;
+    eg_marc         TEXT;
+    v_marc          TEXT;
+    replace_rule    TEXT;
+    match_count     INT;
+    update_fields   TEXT[];
+    update_query    TEXT;
+BEGIN
+
+    SELECT  b.marc INTO eg_marc
+      FROM  authority.record_entry b
+            JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
+      LIMIT 1;
+
+    SELECT  q.marc INTO v_marc
+      FROM  vandelay.queued_record q
+            JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
+      LIMIT 1;
+
+    IF eg_marc IS NULL OR v_marc IS NULL THEN
+        -- RAISE NOTICE 'no marc for vandelay or authority record';
+        RETURN FALSE;
+    END IF;
+
+    -- Extract the editor string before any modification to the vandelay
+    -- MARC occur.
+    editor_string := 
+        (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
+
+    dyn_profile := vandelay.compile_profile( v_marc );
+
+    IF merge_profile_id IS NOT NULL THEN
+        SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
+        IF FOUND THEN
+            dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
+            dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
+            dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
+            dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
+        END IF;
+    END IF;
+
+    IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
+        -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
+        RETURN FALSE;
+    END IF;
+
+    IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' AND dyn_profile.strip_rule = '' THEN
+        --Since we have nothing to do, just return a NOOP "we did it"
+        RETURN TRUE;
+    ELSIF dyn_profile.replace_rule <> '' THEN
+        source_marc = v_marc;
+        target_marc = eg_marc;
+        replace_rule = dyn_profile.replace_rule;
+    ELSE
+        source_marc = eg_marc;
+        target_marc = v_marc;
+        replace_rule = dyn_profile.preserve_rule;
+    END IF;
+
+    UPDATE  authority.record_entry
+      SET   marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
+      WHERE id = eg_id;
+
+    IF NOT FOUND THEN 
+        -- Import/merge failed.  Nothing left to do.
+        RETURN FALSE;
+    END IF;
+
+    -- Authority record successfully merged / imported.
+
+    -- Update the vandelay record to show the successful import.
+    UPDATE  vandelay.queued_authority_record
+      SET   imported_as = eg_id,
+            import_time = NOW()
+      WHERE id = import_id;
+
+    -- If an editor value can be found, update the authority record
+    -- editor and edit_date values.
+    IF editor_string IS NOT NULL AND editor_string <> '' THEN
+
+        -- Vandelay.pm sets the value to 'usrname' when needed.  
+        SELECT id INTO editor_id 
+            FROM actor.usr WHERE usrname = editor_string;
+
+        IF editor_id IS NULL THEN
+            SELECT usr INTO editor_id 
+                FROM actor.card WHERE barcode = editor_string;
+        END IF;
+
+        IF editor_id IS NOT NULL THEN
+            --only update the edit date if we have a valid editor
+            update_fields := ARRAY_APPEND(update_fields, 
+                'editor = ' || editor_id || ', edit_date = NOW()');
+        END IF;
+    END IF;
+
+    IF ARRAY_LENGTH(update_fields, 1) > 0 THEN
+        update_query := 'UPDATE authority.record_entry SET ' || 
+            ARRAY_TO_STRING(update_fields, ',') || 
+            ' WHERE id = ' || eg_id || ';';
+        --RAISE NOTICE 'query: %', update_query;
+        EXECUTE update_query;
+    END IF;
+
+    RETURN TRUE;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+
+COMMIT;
+

-----------------------------------------------------------------------

Summary of changes:
 .../perlmods/lib/OpenILS/Application/Vandelay.pm   |   18 ++--
 Open-ILS/src/sql/Pg/012.schema.vandelay.sql        |   61 +++++++++--
 Open-ILS/src/sql/Pg/t/vandelay-auth-import.sql     |   73 +++++++++++++
 ...> XXXX.schema.authority-vandeley-edit-date.sql} |  113 +++++++++----------
 .../Cataloging/auth_bib_update.adoc                |    6 +
 5 files changed, 193 insertions(+), 78 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/t/vandelay-auth-import.sql
 copy Open-ILS/src/sql/Pg/upgrade/{0193.schema.vandelay.authority_merge_functions.sql => XXXX.schema.authority-vandeley-edit-date.sql} (55%)
 create mode 100644 docs/RELEASE_NOTES_NEXT/Cataloging/auth_bib_update.adoc


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list