LP#957466 Vandelay set the 905$u to current user if not defined
authorJason Stephenson <jstephenson@mvlc.org>
Fri, 13 Feb 2015 17:22:19 +0000 (12:22 -0500)
committerDan Wells <dbw2@calvin.edu>
Tue, 24 Feb 2015 18:58:39 +0000 (13:58 -0500)
This version only adds a 905$u if none already exist in the document. It
does so by creating a new 905 tag with subfield u. It does not add on
to any possibly existing 905 tag that does not have a subfield u.

This will cause the code in the previous commit to trigger and update the
appropriate fields in biblio.record_entry.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm

index 1dc306e..ff018d0 100644 (file)
@@ -2133,6 +2133,30 @@ sub strip_marc_fields {
     return $class->entityize($marcdoc->documentElement->toString);
 }
 
+# marcdoc is an XML::LibXML document
+# updates the document and returns the entityized MARC string.
+sub set_marc_905u {
+    my ($class, $marcdoc, $username) = @_;
+
+    # Look for existing 905$u subfields. If any exist, do nothing.
+    my @nodes = $marcdoc->findnodes('//field[@tag="905"]/subfield[@code="u"]');
+    unless (@nodes) {
+        # We create a new 905 and the subfield u to that.
+        my $parentNode = $marcdoc->createElement('field');
+        $parentNode->setAttribute('tag', '905');
+        $parentNode->setAttribute('ind1', '');
+        $parentNode->setAttribute('ind2', '');
+        $marcdoc->documentElement->addChild($parentNode);
+        my $node = $marcdoc->createElement('subfield');
+        $node->setAttribute('code', 'u');
+        $node->appendTextNode($username);
+        $parentNode->addChild($node);
+
+    }
+
+    return $class->entityize($marcdoc->documentElement->toString);
+}
+
 # Given a list of PostgreSQL arrays of numbers,
 # unnest the numbers and return a unique set, skipping any list elements
 # that are just '{NULL}'.
index 26eddad..efb6cc7 100644 (file)
@@ -989,6 +989,11 @@ 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));
+
             unless ($e->$update_func($rec)) {
                 $$report_args{evt} = $e->die_event;
                 finish_rec_import_attempt($report_args);