Italian SQL updates
[koha.git] / C4 / AuthoritiesMarc.pm
index c61031b..c2c1786 100644 (file)
@@ -246,7 +246,7 @@ sub SearchAuthorities {
             }#if value
         }
         ##Add how many queries generated
-               my $query;
+               $query='';
                foreach my $query_part (@queries){
                        $query=($query?$and.$query_part.$query:$query_part);
                }
@@ -526,8 +526,9 @@ sub AddAuthority {
        my $leader='    nz   a22     o  4500';#Leader for incomplete MARC21 record
 
 # if authid empty => true add, find a new authid number
-  my $format= 'UNIMARCAUTH' if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC');
-  $format= 'MARC21' if (uc(C4::Context->preference('marcflavour')) ne 'UNIMARC');
+  my $format = uc(C4::Context->preference('marcflavour')) eq 'UNIMARC'
+    ? 'UNIMARCAUTH' : 'MARC21'
+  ; 
 
        if ($format eq "MARC21") {
                if (!$record->leader) {
@@ -590,12 +591,10 @@ sub AddAuthority {
     my $sth=$dbh->prepare("select max(authid) from auth_header");
     $sth->execute;
     ($authid)=$sth->fetchrow;
-    $authid=$authid+1;
-  ##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));
-    }
+    ( $authid ||= 0 )++; # $authid is undef for the first authority
+    ## Insert the recordID in MARC record
+    if   ( my $field = $record->field('001') ) { $field->data($authid) }
+    else { $record->insert_fields_ordered(MARC::Field->new('001',$authid)) }
   } else {
     $auth_exists=$dbh->do(qq(select authid from auth_header where authid=?),undef,$authid);
 #     warn "auth_exists = $auth_exists";