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 29-34 use Koha::Cache; Link Here
29
use Koha::DateUtils qw(dt_from_string);
29
use Koha::DateUtils qw(dt_from_string);
30
use DateTime::Format::MySQL;
30
use DateTime::Format::MySQL;
31
use Business::ISBN;
31
use Business::ISBN;
32
use Business::ISSN;
32
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
33
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
33
use DBI qw(:sql_types);
34
use DBI qw(:sql_types);
34
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG);
Lines 77-82 BEGIN { Link Here
77
        &GetVariationsOfISBN
78
        &GetVariationsOfISBN
78
        &GetVariationsOfISBNs
79
        &GetVariationsOfISBNs
79
        &NormalizeISBN
80
        &NormalizeISBN
81
        &GetVariationsOfISSN
82
        &GetVariationsOfISSNs
83
        &NormalizeISSN
80
84
81
		$DEBUG
85
		$DEBUG
82
	);
86
	);
Lines 1872-1877 sub GetVariationsOfISBNs { Link Here
1872
    return wantarray ? @isbns : join( " | ", @isbns );
1876
    return wantarray ? @isbns : join( " | ", @isbns );
1873
}
1877
}
1874
1878
1879
=head2 NormalizedISSN
1880
1881
  my $issns = NormalizedISSN({
1882
          issn => $issn,
1883
          strip_hyphen => [0,1]
1884
          });
1885
1886
  Returns an issn validated by Business::ISSN.
1887
  Optionally strips hyphen.
1888
1889
  If the string cannot be validated as an issn,
1890
  it returns nothing.
1891
1892
=cut
1893
1894
sub NormalizeISSN {
1895
    my ($params) = @_;
1896
1897
    my $string        = $params->{issn};
1898
    my $strip_hyphen  = $params->{strip_hyphen};
1899
1900
    my $issn = Business::ISSN->new($string);
1901
1902
    if ( $issn && $issn->is_valid ){
1903
1904
        if ($strip_hyphen) {
1905
            $string = $issn->_issn;
1906
        }
1907
        else {
1908
            $string = $issn->as_string;
1909
        }
1910
        return $string;
1911
    }
1912
1913
}
1914
1915
=head2 GetVariationsOfISSN
1916
1917
  my @issns = GetVariationsOfISSN( $issn );
1918
1919
  Returns a list of variations of the given issn in
1920
  with and without a hyphen.
1921
1922
  In a scalar context, the issns are returned as a
1923
  string delimited by ' | '.
1924
1925
=cut
1926
1927
sub GetVariationsOfISSN {
1928
    my ($issn) = @_;
1929
1930
    return unless $issn;
1931
1932
    my @issns;
1933
1934
    push( @issns, NormalizeISSN({ issn => $issn }) );
1935
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1936
1937
    # Strip out any "empty" strings from the array
1938
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1939
1940
    return wantarray ? @issns : join( " | ", @issns );
1941
}
1942
1943
=head2 GetVariationsOfISSNs
1944
1945
  my @issns = GetVariationsOfISSNs( @issns );
1946
1947
  Returns a list of variations of the given issns in
1948
  with and without a hyphen.
1949
1950
  In a scalar context, the issns are returned as a
1951
  string delimited by ' | '.
1952
1953
=cut
1954
1955
sub GetVariationsOfISSNs {
1956
    my (@issns) = @_;
1957
1958
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1959
1960
    return wantarray ? @issns : join( " | ", @issns );
1961
}
1962
1963
1875
=head2 IsKohaFieldLinked
1964
=head2 IsKohaFieldLinked
1876
1965
1877
    my $is_linked = IsKohaFieldLinked({
1966
    my $is_linked = IsKohaFieldLinked({
(-)a/C4/Matcher.pm (-1 / +6 lines)
Lines 641-646 sub get_matches { Link Here
641
          if ( $matchpoint->{index} =~ /^isbn$/i
641
          if ( $matchpoint->{index} =~ /^isbn$/i
642
            && C4::Context->preference('AggressiveMatchOnISBN') )
642
            && C4::Context->preference('AggressiveMatchOnISBN') )
643
            && !C4::Context->preference('UseQueryParser');
643
            && !C4::Context->preference('UseQueryParser');
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');
644
649
645
        # build query
650
        # build query
646
        my $query;
651
        my $query;
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 / +18 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 => 30;
28
        plan tests => 36;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 119-122 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
123
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 1 }), '00249319', 'Test NormalizeISSN with all features enabled' );
124
is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 0 }), '0024-9319', 'Test NormalizeISSN with all features enabled' );
125
126
my @issns = qw/ 0024-9319 00249319 /;
127
is( join('|', @issns), join('|', GetVariationsOfISSN('0024-9319')), 'GetVariationsOfISSN returns all variations' );
128
is( join('|', @issns), join('|', GetVariationsOfISSNs('0024-9319')), 'GetVariationsOfISSNs returns all variations' );
129
130
my $issn;
131
eval {
132
    $issn = C4::Koha::NormalizeISSN({ issn => '1234-5678', strip_hyphen => 1 });
133
};
134
ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN');
135
136
@issns = GetVariationsOfISSNs('abc');
137
is(scalar(@issns), 0, 'zero variations returned of invalid ISSN');
138
122
1;
139
1;
123
- 

Return to bug 14629