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}'.
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);