Bug 32804: (QA follow-up) Typo ahs and fix ImportBatch.t
[koha-ffzg.git] / C4 / Matcher.pm
index b7389d7..7322c14 100644 (file)
@@ -19,12 +19,17 @@ package C4::Matcher;
 
 use Modern::Perl;
 
-use MARC::Record;
 
 use Koha::SearchEngine;
 use Koha::SearchEngine::Search;
 use Koha::SearchEngine::QueryBuilder;
-use Koha::Util::Normalize qw/legacy_default remove_spaces upper_case lower_case ISBN/;
+use Koha::Util::Normalize qw(
+    ISBN
+    legacy_default
+    lower_case
+    remove_spaces
+    upper_case
+);
 
 =head1 NAME
 
@@ -165,7 +170,7 @@ sub fetch {
     $sth->execute($id);
     my $row = $sth->fetchrow_hashref;
     $sth->finish();
-    return undef unless defined $row;
+    return unless defined $row;
 
     my $self = {};
     $self->{'id'} = $row->{'matcher_id'};
@@ -337,7 +342,7 @@ sub _store_matchpoint {
     foreach my $component (@{ $matchpoint->{'components'} }) {
         $seqnum++;
         $sth = $dbh->prepare_cached("INSERT INTO matchpoint_components 
-                                     (matchpoint_id, sequence, tag, subfields, offset, length)
+                                     (matchpoint_id, sequence, tag, subfields, `offset`, length)
                                      VALUES (?, ?, ?, ?, ?, ?)");
         $sth->bind_param(1, $matchpoint_id);
         $sth->bind_param(2, $seqnum);
@@ -812,18 +817,33 @@ sub _get_match_keys {
     for (my $i = 0; $i <= $#{ $matchpoint->{'components'} }; $i++) {
         my $component = $matchpoint->{'components'}->[$i];
         my $j = -1;
-        FIELD: foreach my $field ($source_record->field($component->{'tag'})) {
+
+        my @fields = ();
+        my $tag = $component->{'tag'};
+        if ($tag && $tag eq 'LDR'){
+            $fields[0] = $source_record->leader();
+        }
+        else {
+            @fields = $source_record->field($tag);
+        }
+
+        FIELD: foreach my $field (@fields) {
             $j++;
             last FIELD if $j > 0 and $check_only_first_repeat;
             last FIELD if $i > 0 and $j > $#keys;
 
             my $string;
-            if ( $field->is_control_field() ) {
+            if ( ! ref $field ){
+                $string = "$field";
+            }
+            elsif ( $field->is_control_field() ) {
                 $string = $field->data();
-            } els{
+            } elsif ( defined $component->{subfields} && keys %{$component->{subfields}} ){
                 $string = $field->as_string(
                     join('', keys %{ $component->{ subfields } }), ' ' # ' ' as separator
                 );
+            } else {
+                $string = $field->as_string();
             }
 
             if ($component->{'length'}>0) {