From: Jason Stephenson Date: Fri, 13 Feb 2015 17:22:19 +0000 (-0500) Subject: LP#957466 Vandelay set the 905$u to current user if not defined X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4bf4b6e8bd414de8c06070b3554642607662b936;p=contrib%2FConifer.git LP#957466 Vandelay set the 905$u to current user if not defined 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 Signed-off-by: Dan Wells --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 1dc306eec4..ff018d0257 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -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}'. diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm index 26eddad0f2..efb6cc75fc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm @@ -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);