fixing 001 hardcoded field in auth record (001 = authid)
authorPaul POULAIN <paul@koha-fr.org>
Tue, 6 Nov 2007 17:55:35 +0000 (11:55 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 7 Nov 2007 14:18:22 +0000 (08:18 -0600)
+ add 100 field support if needed
+ add 152 (authtypecode) if needed

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/AuthoritiesMarc.pm

index caece1e..6cb52ae 100644 (file)
@@ -505,8 +505,10 @@ sub AddAuthority {
     ($authid)=$sth->fetchrow;
     $authid=$authid+1;
   ##Insert the recordID in MARC record 
-  ##Both authid and authtypecode is expected to be in the same field. Modify if other requirements arise
-    $record->add_fields('001',$authid) unless $record->field('001');
+    unless ($record->field('001') && $record->field('001')->data() eq $authid){
+        $record->delete_field($record->field('001'));
+        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
+    }
     $record->add_fields('152','','','b'=>$authtypecode) unless $record->field('152');
 #     warn $record->as_formatted;
     $dbh->do("lock tables auth_header WRITE");
@@ -514,13 +516,30 @@ sub AddAuthority {
     $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record($format));
     $sth->finish;
   }else{
-      $record->add_fields('001',$authid) unless ($record->field('001'));
-      $record->add_fields('100',$authid) unless ($record->field('100'));
-      $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
-      $dbh->do("lock tables auth_header WRITE");
-      my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
-      $sth->execute($record->as_usmarc,$record->as_xml_record($format),$authid);
-      $sth->finish;
+  ##Insert the recordID in MARC record 
+    unless ($record->field('001') && $record->field('001')->data() eq $authid){
+        $record->delete_field($record->field('001'));
+        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
+    }
+    # check for field 100 in UNIMARC
+    if (($format eq "UNIMARCAUTH") && (!$record->subfield('100','a')){
+        $record->leader("     nx  j22             ");
+        my $date=POSIX::strftime("%Y%m%d",localtime);    
+        if ($record->field('100')){
+            $record->field('100')->update('a'=>$date."afrey50      ba0");
+        } else {      
+            $record->append_fields(
+            MARC::Field->new('100',' ',' '
+                ,'a'=>$date."afrey50      ba0")
+            );
+        }
+    }
+    # field 152 contains authtypecode (unused field in MARC21, correct place in UNIMARC)
+    $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
+    $dbh->do("lock tables auth_header WRITE");
+    my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
+    $sth->execute($record->as_usmarc,$record->as_xml_record($format),$authid);
+    $sth->finish;
   }
   $dbh->do("unlock tables");
   ModZebra($authid,'specialUpdate',"authorityserver",$record);