#1473: MARCfindbreeding breaks MARC21 records in reservoir
[koha_fer] / cataloguing / addbiblio.pl
index 8703cb4..cdd526d 100755 (executable)
@@ -57,20 +57,21 @@ sub MARCfindbreeding {
       $dbh->prepare("select file,marc,encoding from marc_breeding where id=?");
     $sth->execute($id);
     my ( $file, $marc, $encoding ) = $sth->fetchrow;
+    # remove the - in isbn, koha store isbn without any -
     if ($marc) {
         my $record = MARC::Record->new_from_usmarc($marc);
-        if ( $record->field('010') ) {
-            foreach my $field ( $record->field('010') ) {
-                foreach my $subfield ( $field->subfield('a') ) {
-                    my $newisbn = $field->subfield('a');
+        my ($isbnfield,$isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn','');
+        if ( $record->field($isbnfield) ) {
+            foreach my $field ( $record->field($isbnfield) ) {
+                foreach my $subfield ( $field->subfield($isbnsubfield) ) {
+                    my $newisbn = $field->subfield($isbnsubfield);
                     $newisbn =~ s/-//g;
-                    $field->update( 'a' => $newisbn );
+                    $field->update( $isbnsubfield => $newisbn );
                 }
-                # record->insert_fields_ordered($record->field('010'));
             }
         }
-
-        if ($record->subfield(100,'a')) {
+        # fix the unimarc 100 coded field (with unicode information)
+        if (C4::Context->preference('marcflavour') eq 'UNIMARC' && $record->subfield(100,'a')) {
             my $f100a=$record->subfield(100,'a');
             my $f100 = $record->field(100);
             my $f100temp = $f100->as_string;
@@ -87,6 +88,7 @@ sub MARCfindbreeding {
             return -1;
         }
         else {
+            # normalize author : probably UNIMARC specific...
             if (    C4::Context->preference("z3950NormalizeAuthor")
                 and C4::Context->preference("z3950AuthorAuthFields") )
             {
@@ -292,6 +294,7 @@ sub create_input {
         value          => $value,
         random         => CreateKey(),
     );
+    # deal with a <010 tag
     if($subfield eq '@'){
         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield;
     } else {
@@ -301,12 +304,14 @@ sub create_input {
     if(exists $mandatory_z3950->{$tag.$subfield}){
         $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
     }
-    
+    # decide if the subfield must be expanded (visible) by default or not
+    # if it is mandatory, then expand. If it is hidden explicitly by the hidden flag, hidden anyway
     $subfield_data{visibility} = "display:none;"
         if (    ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''
             or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
         );
-    
+    # always expand all subfields of a mandatory field
+    $subfield_data{visibility} = "" if $tagslib->{$tag}->{mandatory};
     # it's an authorised field
     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
         $subfield_data{marc_value} =
@@ -540,7 +545,7 @@ sub build_tabs ($$$$$) {
                             tag_lib       => $tagslib->{$tag}->{lib},
                             repeatable       => $tagslib->{$tag}->{repeatable},
                             subfield_loop => \@subfields_data,
-                            fixedfield    => ($tag < 10)?(1):(0),
+                            fixedfield    => $tag < 10?1:0,
                             random        => CreateKey,
                         );
                         if ($tag >= 010){ # no indicator for theses tag
@@ -579,7 +584,7 @@ sub build_tabs ($$$$$) {
                         indicator        => $indicator,
                         subfield_loop    => \@subfields_data,
                         tagfirstsubfield => $subfields_data[0],
-                        fixedfield       => ($tag < 10)?(1):(0)
+                        fixedfield       => $tag < 10?1:0,
                     );
                     
                     push @loop_data, \%tag_data ;