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($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
36
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
Lines 72-77 BEGIN { Link Here
72
        &GetVariationsOfISBN
73
        &GetVariationsOfISBN
73
        &GetVariationsOfISBNs
74
        &GetVariationsOfISBNs
74
        &NormalizeISBN
75
        &NormalizeISBN
76
        &GetVariationsOfISSN
77
        &GetVariationsOfISSNs
78
        &NormalizeISSN
75
79
76
		$DEBUG
80
		$DEBUG
77
	);
81
	);
Lines 1660-1665 sub GetVariationsOfISBNs { Link Here
1660
    return wantarray ? @isbns : join( " | ", @isbns );
1664
    return wantarray ? @isbns : join( " | ", @isbns );
1661
}
1665
}
1662
1666
1667
=head2 NormalizedISSN
1668
1669
  my $issns = NormalizedISSN({
1670
          issn => $issn,
1671
          strip_hyphen => [0,1]
1672
          });
1673
1674
  Returns an issn validated by Business::ISSN.
1675
  Optionally strips hyphen.
1676
1677
  If the string cannot be validated as an issn,
1678
  it returns nothing.
1679
1680
=cut
1681
1682
sub NormalizeISSN {
1683
    my ($params) = @_;
1684
1685
    my $string        = $params->{issn};
1686
    my $strip_hyphen  = $params->{strip_hyphen};
1687
1688
    my $issn = Business::ISSN->new($string);
1689
1690
    if ( $issn && $issn->is_valid ){
1691
1692
        if ($strip_hyphen) {
1693
            $string = $issn->_issn;
1694
        }
1695
        else {
1696
            $string = $issn->as_string;
1697
        }
1698
        return $string;
1699
    }
1700
1701
}
1702
1703
=head2 GetVariationsOfISSN
1704
1705
  my @issns = GetVariationsOfISSN( $issn );
1706
1707
  Returns a list of variations of the given issn in
1708
  with and without a hyphen.
1709
1710
  In a scalar context, the issns are returned as a
1711
  string delimited by ' | '.
1712
1713
=cut
1714
1715
sub GetVariationsOfISSN {
1716
    my ($issn) = @_;
1717
1718
    return unless $issn;
1719
1720
    my @issns;
1721
1722
    push( @issns, NormalizeISSN({ issn => $issn }) );
1723
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1724
1725
    # Strip out any "empty" strings from the array
1726
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1727
1728
    return wantarray ? @issns : join( " | ", @issns );
1729
}
1730
1731
=head2 GetVariationsOfISSNs
1732
1733
  my @issns = GetVariationsOfISSNs( @issns );
1734
1735
  Returns a list of variations of the given issns in
1736
  with and without a hyphen.
1737
1738
  In a scalar context, the issns are returned as a
1739
  string delimited by ' | '.
1740
1741
=cut
1742
1743
sub GetVariationsOfISSNs {
1744
    my (@issns) = @_;
1745
1746
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1747
1748
    return wantarray ? @issns : join( " | ", @issns );
1749
}
1750
1751
1663
=head2 IsKohaFieldLinked
1752
=head2 IsKohaFieldLinked
1664
1753
1665
    my $is_linked = IsKohaFieldLinked({
1754
    my $is_linked = IsKohaFieldLinked({
(-)a/C4/Matcher.pm (-1 / +6 lines)
Lines 642-647 sub get_matches { Link Here
642
            && C4::Context->preference('AggressiveMatchOnISBN') )
642
            && C4::Context->preference('AggressiveMatchOnISBN') )
643
            && !C4::Context->preference('UseQueryParser');
643
            && !C4::Context->preference('UseQueryParser');
644
644
645
        @source_keys = C4::Koha::GetVariationsOfISSNs(@source_keys)
646
          if ( $matchpoint->{index} =~ /^issn$/i
647
            && C4::Context->preference('AggressiveMatchOnISSN') )
648
            && !C4::Context->preference('UseQueryParser');
649
645
        # build query
650
        # build query
646
        my $query;
651
        my $query;
647
        my $error;
652
        my $error;
Lines 654-660 sub get_matches { Link Here
654
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
659
                    map { "$matchpoint->{'index'}:$_" } @source_keys );
655
            }
660
            }
656
            else {
661
            else {
657
                my $phr = C4::Context->preference('AggressiveMatchOnISBN') ? ',phr' : q{};
662
                my $phr = ( C4::Context->preference('AggressiveMatchOnISBN') || C4::Context->preference('AggressiveMatchOnISSN') )  ? ',phr' : q{};
658
                $query = join( " or ",
663
                $query = join( " or ",
659
                    map { "$matchpoint->{'index'}$phr=$_" } @source_keys );
664
                    map { "$matchpoint->{'index'}$phr=$_" } @source_keys );
660
            }
665
            }
(-)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 / +20 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 => 34;
28
        plan tests => 41;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 119-124 is( C4::Koha::GetNormalizedISBN('9781250075345 (hardcover) | 1250075343 (hardcov Link Here
119
is( C4::Koha::GetNormalizedISBN('9781250067128 | 125006712X'), '125006712X', 'Test GetNormalizedISBN' );
119
is( C4::Koha::GetNormalizedISBN('9781250067128 | 125006712X'), '125006712X', 'Test GetNormalizedISBN' );
120
is( C4::Koha::GetNormalizedISBN('9780373211463 | 0373211465'), '0373211465', 'Test GetNormalizedISBN' );
120
is( C4::Koha::GetNormalizedISBN('9780373211463 | 0373211465'), '0373211465', 'Test GetNormalizedISBN' );
121
121
122
<<<<<<< HEAD
122
is( C4::Koha::GetNormalizedUPC(), undef, 'GetNormalizedUPC should return undef if no record is passed' );
123
is( C4::Koha::GetNormalizedUPC(), undef, 'GetNormalizedUPC should return undef if no record is passed' );
123
is( C4::Koha::GetNormalizedISBN(), undef, 'GetNormalizedISBN should return undef if no record and no isbn are passed' );
124
is( C4::Koha::GetNormalizedISBN(), undef, 'GetNormalizedISBN should return undef if no record and no isbn are passed' );
124
is( C4::Koha::GetNormalizedEAN(), undef, 'GetNormalizedEAN should return undef if no record and no isbn are passed' );
125
is( C4::Koha::GetNormalizedEAN(), undef, 'GetNormalizedEAN should return undef if no record and no isbn are passed' );
Lines 149-153 subtest 'getFacets() tests' => sub { Link Here
149
        'location facet present with singleBranchMode off (bug 10078)'
150
        'location facet present with singleBranchMode off (bug 10078)'
150
    );
151
    );
151
};
152
};
153
=======
154
155
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 1 }), '00249319', 'Test NormalizeISSN with all features enabled' );
156
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 0 }), '0024-9319', 'Test NormalizeISSN with all features enabled' );
157
158
my @issns = qw/ 0024-9319 00249319 /;
159
is( join('|', @issns), join('|', GetVariationsOfISSN('0024-9319')), 'GetVariationsOfISSN returns all variations' );
160
is( join('|', @issns), join('|', GetVariationsOfISSNs('0024-9319')), 'GetVariationsOfISSNs returns all variations' );
161
162
my $issn;
163
eval {
164
    $issn = C4::Koha::NormalizeISSN({ issn => '1234-5678', strip_hyphen => 1 });
165
};
166
ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN');
167
168
@issns = GetVariationsOfISSNs('abc');
169
is(scalar(@issns), 0, 'zero variations returned of invalid ISSN');
170
>>>>>>> Bug 14629 - Add aggressive ISSN matching feature equivalent to the aggressive ISBN matcher
152
171
153
1;
172
1;
154
- 

Return to bug 14629