From: Jason Stephenson Date: Wed, 18 Feb 2015 16:34:53 +0000 (-0500) Subject: LP#957466: A simpler version of set_marc_905u. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=46b0f9c1a340d83b88fd6c49de2aad1a079c4c0d;p=evergreen%2Fmasslnc.git LP#957466: A simpler version of set_marc_905u. 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. 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 b560bc9966..e70e5a19e4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2141,41 +2141,22 @@ sub strip_marc_fields { 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); - } - } + # 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); - # 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); }