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 71-76 BEGIN { Link Here
71
        &GetVariationsOfISBN
72
        &GetVariationsOfISBN
72
        &GetVariationsOfISBNs
73
        &GetVariationsOfISBNs
73
        &NormalizeISBN
74
        &NormalizeISBN
75
        &GetVariationsOfISSN
76
        &GetVariationsOfISSNs
77
        &NormalizeISSN
74
78
75
		$DEBUG
79
		$DEBUG
76
	);
80
	);
Lines 1637-1642 sub GetVariationsOfISBNs { Link Here
1637
    return wantarray ? @isbns : join( " | ", @isbns );
1641
    return wantarray ? @isbns : join( " | ", @isbns );
1638
}
1642
}
1639
1643
1644
=head2 NormalizedISSN
1645
1646
  my $issns = NormalizedISSN({
1647
          issn => $issn,
1648
          strip_hyphen => [0,1]
1649
          });
1650
1651
  Returns an issn validated by Business::ISSN.
1652
  Optionally strips hyphen.
1653
1654
  If the string cannot be validated as an issn,
1655
  it returns nothing.
1656
1657
=cut
1658
1659
sub NormalizeISSN {
1660
    my ($params) = @_;
1661
1662
    my $string        = $params->{issn};
1663
    my $strip_hyphen  = $params->{strip_hyphen};
1664
1665
    my $issn = Business::ISSN->new($string);
1666
1667
    if ( $issn && $issn->is_valid ){
1668
1669
        if ($strip_hyphen) {
1670
            $string = $issn->_issn;
1671
        }
1672
        else {
1673
            $string = $issn->as_string;
1674
        }
1675
        return $string;
1676
    }
1677
1678
}
1679
1680
=head2 GetVariationsOfISSN
1681
1682
  my @issns = GetVariationsOfISSN( $issn );
1683
1684
  Returns a list of variations of the given issn in
1685
  with and without a hyphen.
1686
1687
  In a scalar context, the issns are returned as a
1688
  string delimited by ' | '.
1689
1690
=cut
1691
1692
sub GetVariationsOfISSN {
1693
    my ($issn) = @_;
1694
1695
    return unless $issn;
1696
1697
    my @issns;
1698
1699
    push( @issns, NormalizeISSN({ issn => $issn }) );
1700
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1701
1702
    # Strip out any "empty" strings from the array
1703
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1704
1705
    return wantarray ? @issns : join( " | ", @issns );
1706
}
1707
1708
=head2 GetVariationsOfISSNs
1709
1710
  my @issns = GetVariationsOfISSNs( @issns );
1711
1712
  Returns a list of variations of the given issns in
1713
  with and without a hyphen.
1714
1715
  In a scalar context, the issns are returned as a
1716
  string delimited by ' | '.
1717
1718
=cut
1719
1720
sub GetVariationsOfISSNs {
1721
    my (@issns) = @_;
1722
1723
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1724
1725
    return wantarray ? @issns : join( " | ", @issns );
1726
}
1727
1728
1640
=head2 IsKohaFieldLinked
1729
=head2 IsKohaFieldLinked
1641
1730
1642
    my $is_linked = IsKohaFieldLinked({
1731
    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 / +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