Remove vestigial (Sirsi) identifiers; order fields
authorDan Scott <dscott@laurentian.ca>
Sat, 17 Jan 2015 16:05:36 +0000 (11:05 -0500)
committerDan Scott <dscott@laurentian.ca>
Sat, 17 Jan 2015 16:05:36 +0000 (11:05 -0500)
We might as well place any 010/024/035 that we add in numerical order. Also,
remove the 035 $a (Sirsi) identifiers which are now meaningless.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/update_marc_records_in_database.sql

index ede6ca1..f077a3b 100644 (file)
@@ -115,7 +115,7 @@ if ($lccn_number) {
         if (exists $metadata->{'list'}->[0]->{'lccn'} and !$lccn_number) {
             $lccn_number = $metadata->{'list'}->[0]->{'lccn'}->[0];
             my $nf = MARC::Field->new('010', '', '', 'a' => "$lccn_number");
-            $record->insert_grouped_field($nf);
+            $record->insert_fields_ordered($nf);
             my $response = $ua->get("http://xisbn.worldcat.org/webservices/xid/lccn/$lccn_number?method=getMetadata&format=json&fl=*");
             if ($response->is_success) {
                 my $metadata = decode_json($response->decoded_content);
@@ -146,22 +146,23 @@ if ($owi_number) {
     }
     if (!$found_owinumber) {
         my $nf = MARC::Field->new('024', '7', '', 'a' => "http://worldcat.org/entity/work/id/$owi_number", '2' => 'uri');
-        $record->insert_grouped_field($nf);
+        $record->insert_fields_ordered($nf);
     }
 }
 
-if ($oclc_number) {
-    my @idtags = $record->field('035');
-    foreach my $idtag (@idtags) {
-        if ($idtag->subfield('a') =~ m#^\(OCoLC\)$oclc_number#) {
-            $found_oclcnum = 1;
-        }
-    }
-    if (!$found_oclcnum) {
-        my $nf = MARC::Field->new('035', '', '', 'a' => "(OCoLC)$oclc_number");
-        $record->insert_grouped_field($nf);
+my @idtags = $record->field('035');
+foreach my $idtag (@idtags) {
+    # Remove meaningless old local Sirsi identifiers
+    if ($idtag->subfield('a') =~ m#^\(Sirsi\)#) {
+        $record->delete_field($idtag);
+    } elsif ($oclc_number && $idtag->subfield('a') =~ m#^\(OCoLC\)$oclc_number#) {
+        $found_oclcnum = 1;
     }
 }
+if ($oclc_number && !$found_oclcnum) {
+    my $nf = MARC::Field->new('035', '', '', 'a' => "(OCoLC)$oclc_number");
+    $record->insert_fields_ordered($nf);
+}
 
 my $xml = $record->as_xml_record();
 $xml =~ s/\n//sgo;