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

(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 517-522 our $PERL_DEPS = { Link Here
517
        'required' => '1',
517
        'required' => '1',
518
        'min_ver'  => '2.05',
518
        'min_ver'  => '2.05',
519
    },
519
    },
520
    'Business::ISSN' => {
521
        'usage'    => 'Core',
522
        'required' => '1',
523
        'min_ver'  => '0.91',
524
    },
520
    'Template' => {
525
    'Template' => {
521
        'usage'    => 'Core',
526
        'usage'    => 'Core',
522
        'required' => '1',
527
        'required' => '1',
(-)a/C4/Koha.pm (+89 lines)
Lines 30-35 use Koha::DateUtils qw(dt_from_string); Link Here
30
use Koha::Libraries;
30
use Koha::Libraries;
31
use DateTime::Format::MySQL;
31
use DateTime::Format::MySQL;
32
use Business::ISBN;
32
use Business::ISBN;
33
use Business::ISSN;
33
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
34
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
34
use DBI qw(:sql_types);
35
use DBI qw(:sql_types);
35
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG);
36
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG);
Lines 69-74 BEGIN { Link Here
69
        &GetVariationsOfISBN
70
        &GetVariationsOfISBN
70
        &GetVariationsOfISBNs
71
        &GetVariationsOfISBNs
71
        &NormalizeISBN
72
        &NormalizeISBN
73
        &GetVariationsOfISSN
74
        &GetVariationsOfISSNs
75
        &NormalizeISSN
72
76
73
		$DEBUG
77
		$DEBUG
74
	);
78
	);
Lines 1604-1609 sub GetVariationsOfISBNs { Link Here
1604
    return wantarray ? @isbns : join( " | ", @isbns );
1608
    return wantarray ? @isbns : join( " | ", @isbns );
1605
}
1609
}
1606
1610
1611
=head2 NormalizedISSN
1612
1613
  my $issns = NormalizedISSN({
1614
          issn => $issn,
1615
          strip_hyphen => [0,1]
1616
          });
1617
1618
  Returns an issn validated by Business::ISSN.
1619
  Optionally strips hyphen.
1620
1621
  If the string cannot be validated as an issn,
1622
  it returns nothing.
1623
1624
=cut
1625
1626
sub NormalizeISSN {
1627
    my ($params) = @_;
1628
1629
    my $string        = $params->{issn};
1630
    my $strip_hyphen  = $params->{strip_hyphen};
1631
1632
    my $issn = Business::ISSN->new($string);
1633
1634
    if ( $issn && $issn->is_valid ){
1635
1636
        if ($strip_hyphen) {
1637
            $string = $issn->_issn;
1638
        }
1639
        else {
1640
            $string = $issn->as_string;
1641
        }
1642
        return $string;
1643
    }
1644
1645
}
1646
1647
=head2 GetVariationsOfISSN
1648
1649
  my @issns = GetVariationsOfISSN( $issn );
1650
1651
  Returns a list of variations of the given issn in
1652
  with and without a hyphen.
1653
1654
  In a scalar context, the issns are returned as a
1655
  string delimited by ' | '.
1656
1657
=cut
1658
1659
sub GetVariationsOfISSN {
1660
    my ($issn) = @_;
1661
1662
    return unless $issn;
1663
1664
    my @issns;
1665
1666
    push( @issns, NormalizeISSN({ issn => $issn }) );
1667
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1668
1669
    # Strip out any "empty" strings from the array
1670
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1671
1672
    return wantarray ? @issns : join( " | ", @issns );
1673
}
1674
1675
=head2 GetVariationsOfISSNs
1676
1677
  my @issns = GetVariationsOfISSNs( @issns );
1678
1679
  Returns a list of variations of the given issns in
1680
  with and without a hyphen.
1681
1682
  In a scalar context, the issns are returned as a
1683
  string delimited by ' | '.
1684
1685
=cut
1686
1687
sub GetVariationsOfISSNs {
1688
    my (@issns) = @_;
1689
1690
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1691
1692
    return wantarray ? @issns : join( " | ", @issns );
1693
}
1694
1695
1607
=head2 IsKohaFieldLinked
1696
=head2 IsKohaFieldLinked
1608
1697
1609
    my $is_linked = IsKohaFieldLinked({
1698
    my $is_linked = IsKohaFieldLinked({
(-)a/C4/Matcher.pm (-1 / +6 lines)
Lines 638-643 sub get_matches { Link Here
638
            && C4::Context->preference('AggressiveMatchOnISBN') )
638
            && C4::Context->preference('AggressiveMatchOnISBN') )
639
            && !C4::Context->preference('UseQueryParser');
639
            && !C4::Context->preference('UseQueryParser');
640
640
641
        @source_keys = C4::Koha::GetVariationsOfISSNs(@source_keys)
642
          if ( $matchpoint->{index} =~ /^issn$/i
643
            && C4::Context->preference('AggressiveMatchOnISSN') )
644
            && !C4::Context->preference('UseQueryParser');
645
641
        # build query
646
        # build query
642
        my $query;
647
        my $query;
643
        my $error;
648
        my $error;
Lines 650-656 sub get_matches { Link Here
650
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
655
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
651
            }
656
            }
652
            else {
657
            else {
653
                my $phr = C4::Context->preference('AggressiveMatchOnISBN') ? ',phr' : q{};
658
                my $phr = ( C4::Context->preference('AggressiveMatchOnISBN') || C4::Context->preference('AggressiveMatchOnISSN') )  ? ',phr' : q{};
654
                $query = join( " or ",
659
                $query = join( " or ",
655
                    map { "$matchpoint->{'index'}$phr=\"$_\"" } @source_keys );
660
                    map { "$matchpoint->{'index'}$phr=\"$_\"" } @source_keys );
656
                    #NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it.
661
                    #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