View | Details | Raw Unified | Return to bug 10855
Collapse All | Expand All

(-)a/C4/Serials.pm (+1 lines)
Lines 657-662 sub SearchSubscriptions { Link Here
657
        $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids({
657
        $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids({
658
                fields => $args->{additional_fields},
658
                fields => $args->{additional_fields},
659
                tablename => 'subscription',
659
                tablename => 'subscription',
660
                exact_match => 0,
660
        });
661
        });
661
        return () unless @$matching_record_ids_for_additional_fields;
662
        return () unless @$matching_record_ids_for_additional_fields;
662
    }
663
    }
(-)a/Koha/AdditionalField.pm (-2 / +3 lines)
Lines 204-209 sub get_matching_record_ids { Link Here
204
204
205
    my $fields = $args->{fields} // [];
205
    my $fields = $args->{fields} // [];
206
    my $tablename = $args->{tablename};
206
    my $tablename = $args->{tablename};
207
    my $exact_match = $args->{exact_match} // 1;
207
    return [] unless @$fields;
208
    return [] unless @$fields;
208
209
209
    my $dbh = C4::Context->dbh;
210
    my $dbh = C4::Context->dbh;
Lines 222-234 sub get_matching_record_ids { Link Here
222
                    WHERE afv.field_id = af.id
223
                    WHERE afv.field_id = af.id
223
                    AND af.name = ?
224
                    AND af.name = ?
224
                    AND af.tablename = ?
225
                    AND af.tablename = ?
225
                    AND value = ?
226
                    AND value LIKE ?
226
                ) AS field$i USING (id)
227
                ) AS field$i USING (id)
227
            WHERE field$i.id IS NOT NULL
228
            WHERE field$i.id IS NOT NULL
228
        ) AS values$i |;
229
        ) AS values$i |;
229
        $subquery .= ' USING (record_id)' if $i > 1;
230
        $subquery .= ' USING (record_id)' if $i > 1;
230
        push @subqueries, $subquery;
231
        push @subqueries, $subquery;
231
        push @args, $field->{name}, $tablename, $field->{value};
232
        push @args, $field->{name}, $tablename, ( $exact_match ? $field->{value} : "%$field->{value}%" );
232
    }
233
    }
233
    $query .= join( ' LEFT JOIN ', @subqueries ) . ' WHERE 1';
234
    $query .= join( ' LEFT JOIN ', @subqueries ) . ' WHERE 1';
234
    for my $j ( 1 .. $i ) {
235
    for my $j ( 1 .. $i ) {
(-)a/t/db_dependent/AdditionalField.t (-2 / +16 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 34;
4
use Test::More tests => 37;
5
5
6
use C4::Context;
6
use C4::Context;
7
use Koha::AdditionalField;
7
use Koha::AdditionalField;
Lines 276-279 is ( $exists, 1, "get_matching_record_ids: field common: common_value matches su Link Here
276
$exists = grep /not_existent_id/, @$matching_record_ids;
276
$exists = grep /not_existent_id/, @$matching_record_ids;
277
is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
277
is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
278
278
279
$fields = [
280
    {
281
        name => 'common',
282
        value => q|common|,
283
    }
284
];
285
$matching_record_ids = Koha::AdditionalField->get_matching_record_ids({ tablename => 'subscription', fields => $fields, exact_match => 0 });
286
$exists = grep /$subscriptionid1/, @$matching_record_ids;
287
is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription1" );
288
$exists = grep /$subscriptionid2/, @$matching_record_ids;
289
is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription2 too" );
290
$exists = grep /not_existent_id/, @$matching_record_ids;
291
is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
292
293
279
$dbh->rollback;
294
$dbh->rollback;
280
- 

Return to bug 10855