From 522b6ff61c36db7b6883f5db53f273a8fde7abf0 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Fri, 13 Feb 2015 12:22:19 -0500 Subject: [PATCH] LP#957466 Vandelay set the 905$u on imported bib records to current user. 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: Martha Driscoll --- .../lib/OpenILS/Application/AppUtils.pm | 43 +++++++++++++++++++ .../lib/OpenILS/Application/Vandelay.pm | 5 +++ 2 files changed, 48 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 1dc306eec4..8de64a5467 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2133,6 +2133,49 @@ 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) = @_; + + # We add to the $parentNode, if set. + my $parentNode; + # Look for existing 905$u subfields and remove them: + for my $node ($marcdoc->findnodes('//field[@tag="905"]/subfield[@code="u"]')) { + $parentNode = $node->parentNode(); + $parentNode->removeChild($node); + # If the 905 has no subfield nodes, remove it, too: + unless ($parentNode->findnodes('child::subfield')) { + $parentNode->parentNode->removeChild($parentNode); + undef($parentNode); + } + } + + # Check if we deleted any existing 905s or don't have any. + unless ($parentNode) { + # Look for the last one, if any. + my @nodes = $marcdoc->findnodes('(//field[@tag="905"])[last()]'); + if (@nodes) { + $parentNode = $nodes[0]; + } else { + # We have to create a new one. + $parentNode = $marcdoc->createElement('field'); + $parentNode->setAttribute('tag', '905'); + $parentNode->setAttribute('ind1', ''); + $parentNode->setAttribute('ind2', ''); + $marcdoc->documentElement->addChild($parentNode); + } + } + + # Now we add the subfield u to 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); -- 2.43.2