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

(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 522-527 our $PERL_DEPS = { Link Here
522
        'required' => '1',
522
        'required' => '1',
523
        'min_ver'  => '2.05',
523
        'min_ver'  => '2.05',
524
    },
524
    },
525
    'Business::ISSN' => {
526
        'usage'    => 'Core',
527
        'required' => '1',
528
        'min_ver'  => '0.91',
529
    },
525
    'Template' => {
530
    'Template' => {
526
        'usage'    => 'Core',
531
        'usage'    => 'Core',
527
        'required' => '1',
532
        'required' => '1',
(-)a/C4/Koha.pm (+89 lines)
Lines 31-36 use Koha::Libraries; Link Here
31
use Koha::MarcSubfieldStructures;
31
use Koha::MarcSubfieldStructures;
32
use DateTime::Format::MySQL;
32
use DateTime::Format::MySQL;
33
use Business::ISBN;
33
use Business::ISBN;
34
use Business::ISSN;
34
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
35
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
35
use DBI qw(:sql_types);
36
use DBI qw(:sql_types);
36
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG);
37
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG);
Lines 63-68 BEGIN { Link Here
63
        &GetVariationsOfISBN
64
        &GetVariationsOfISBN
64
        &GetVariationsOfISBNs
65
        &GetVariationsOfISBNs
65
        &NormalizeISBN
66
        &NormalizeISBN
67
        &GetVariationsOfISSN
68
        &GetVariationsOfISSNs
69
        &NormalizeISSN
66
70
67
		$DEBUG
71
		$DEBUG
68
	);
72
	);
Lines 1337-1342 sub GetVariationsOfISBNs { Link Here
1337
    return wantarray ? @isbns : join( " | ", @isbns );
1341
    return wantarray ? @isbns : join( " | ", @isbns );
1338
}
1342
}
1339
1343
1344
=head2 NormalizedISSN
1345
1346
  my $issns = NormalizedISSN({
1347
          issn => $issn,
1348
          strip_hyphen => [0,1]
1349
          });
1350
1351
  Returns an issn validated by Business::ISSN.
1352
  Optionally strips hyphen.
1353
1354
  If the string cannot be validated as an issn,
1355
  it returns nothing.
1356
1357
=cut
1358
1359
sub NormalizeISSN {
1360
    my ($params) = @_;
1361
1362
    my $string        = $params->{issn};
1363
    my $strip_hyphen  = $params->{strip_hyphen};
1364
1365
    my $issn = Business::ISSN->new($string);
1366
1367
    if ( $issn && $issn->is_valid ){
1368
1369
        if ($strip_hyphen) {
1370
            $string = $issn->_issn;
1371
        }
1372
        else {
1373
            $string = $issn->as_string;
1374
        }
1375
        return $string;
1376
    }
1377
1378
}
1379
1380
=head2 GetVariationsOfISSN
1381
1382
  my @issns = GetVariationsOfISSN( $issn );
1383
1384
  Returns a list of variations of the given issn in
1385
  with and without a hyphen.
1386
1387
  In a scalar context, the issns are returned as a
1388
  string delimited by ' | '.
1389
1390
=cut
1391
1392
sub GetVariationsOfISSN {
1393
    my ($issn) = @_;
1394
1395
    return unless $issn;
1396
1397
    my @issns;
1398
1399
    push( @issns, NormalizeISSN({ issn => $issn }) );
1400
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1401
1402
    # Strip out any "empty" strings from the array
1403
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1404
1405
    return wantarray ? @issns : join( " | ", @issns );
1406
}
1407
1408
=head2 GetVariationsOfISSNs
1409
1410
  my @issns = GetVariationsOfISSNs( @issns );
1411
1412
  Returns a list of variations of the given issns in
1413
  with and without a hyphen.
1414
1415
  In a scalar context, the issns are returned as a
1416
  string delimited by ' | '.
1417
1418
=cut
1419
1420
sub GetVariationsOfISSNs {
1421
    my (@issns) = @_;
1422
1423
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1424
1425
    return wantarray ? @issns : join( " | ", @issns );
1426
}
1427
1428
1340
=head2 IsKohaFieldLinked
1429
=head2 IsKohaFieldLinked
1341
1430
1342
    my $is_linked = IsKohaFieldLinked({
1431
    my $is_linked = IsKohaFieldLinked({
(-)a/C4/Matcher.pm (-1 / +6 lines)
Lines 637-642 sub get_matches { Link Here
637
            && C4::Context->preference('AggressiveMatchOnISBN') )
637
            && C4::Context->preference('AggressiveMatchOnISBN') )
638
            && !C4::Context->preference('UseQueryParser');
638
            && !C4::Context->preference('UseQueryParser');
639
639
640
        @source_keys = C4::Koha::GetVariationsOfISSNs(@source_keys)
641
          if ( $matchpoint->{index} =~ /^issn$/i
642
            && C4::Context->preference('AggressiveMatchOnISSN') )
643
            && !C4::Context->preference('UseQueryParser');
644
640
        # build query
645
        # build query
641
        my $query;
646
        my $query;
642
        my $error;
647
        my $error;
Lines 649-655 sub get_matches { Link Here
649
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
654
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
650
            }
655
            }
651
            else {
656
            else {
652
                my $phr = C4::Context->preference('AggressiveMatchOnISBN') ? ',phr' : q{};
657
                my $phr = ( C4::Context->preference('AggressiveMatchOnISBN') || C4::Context->preference('AggressiveMatchOnISSN') )  ? ',phr' : q{};
653
                $query = join( " or ",
658
                $query = join( " or ",
654
                    map { "$matchpoint->{'index'}$phr=\"$_\"" } @source_keys );
659
                    map { "$matchpoint->{'index'}$phr=\"$_\"" } @source_keys );
655
                    #NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it.
660
                    #NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it.
(-)a/installer/data/mysql/atomicupdate/bug_14629-add_AgressiveMatchOnISSN_syspref.sql (+1 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('AggressiveMatchOnISSN','0','If enabled, attempt to match aggressively by trying all variations of the ISSNs in the imported record as a phrase in the ISSN fields of already cataloged records when matching on ISSN with the record import tool','','YesNo')
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+8 lines)
Lines 224-229 Cataloging: Link Here
224
                  yes: "do"
224
                  yes: "do"
225
                  no: "don't"
225
                  no: "don't"
226
            - attempt to match aggressively by trying all variations of the ISBNs in the imported record as a phrase in the ISBN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
226
            - attempt to match aggressively by trying all variations of the ISBNs in the imported record as a phrase in the ISBN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
227
        -
228
            - When matching on ISSN with the record import tool,
229
            - pref: AggressiveMatchOnISSN
230
              choices:
231
                  yes: "do"
232
                  no: "don't"
233
            - attempt to match aggressively by trying all variations of the ISSNs in the imported record as a phrase in the ISSN fields of already cataloged records.  Note that this preference has no effect if UseQueryParser is on.
234
227
    Exporting:
235
    Exporting:
228
        -
236
        -
229
            - Include following fields when exporting BibTeX,
237
            - Include following fields when exporting BibTeX,
(-)a/t/Koha.t (-2 / +17 lines)
Lines 25-31 use Module::Load::Conditional qw/check_install/; Link Here
25
25
26
BEGIN {
26
BEGIN {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
28
        plan tests => 31;
28
        plan tests => 37;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 138-141 subtest 'getFacets() tests' => sub { Link Here
138
    );
138
    );
139
};
139
};
140
140
141
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 1 }), '00249319', 'Test NormalizeISSN with all features enabled' );
142
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 0 }), '0024-9319', 'Test NormalizeISSN with all features enabled' );
143
144
my @issns = qw/ 0024-9319 00249319 /;
145
is( join('|', @issns), join('|', GetVariationsOfISSN('0024-9319')), 'GetVariationsOfISSN returns all variations' );
146
is( join('|', @issns), join('|', GetVariationsOfISSNs('0024-9319')), 'GetVariationsOfISSNs returns all variations' );
147
148
my $issn;
149
eval {
150
    $issn = C4::Koha::NormalizeISSN({ issn => '1234-5678', strip_hyphen => 1 });
151
};
152
ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN');
153
154
@issns = GetVariationsOfISSNs('abc');
155
is(scalar(@issns), 0, 'zero variations returned of invalid ISSN');
156
141
1;
157
1;
142
- 

Return to bug 14629