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 76-81 BEGIN { Link Here
76
        &GetVariationsOfISBN
77
        &GetVariationsOfISBN
77
        &GetVariationsOfISBNs
78
        &GetVariationsOfISBNs
78
        &NormalizeISBN
79
        &NormalizeISBN
80
        &GetVariationsOfISSN
81
        &GetVariationsOfISSNs
82
        &NormalizeISSN
79
83
80
		$DEBUG
84
		$DEBUG
81
	);
85
	);
Lines 1809-1814 sub GetVariationsOfISBNs { Link Here
1809
    return wantarray ? @isbns : join( " | ", @isbns );
1813
    return wantarray ? @isbns : join( " | ", @isbns );
1810
}
1814
}
1811
1815
1816
=head2 NormalizedISSN
1817
1818
  my $issns = NormalizedISSN({
1819
          issn => $issn,
1820
          strip_hyphen => [0,1]
1821
          });
1822
1823
  Returns an issn validated by Business::ISSN.
1824
  Optionally strips hyphen.
1825
1826
  If the string cannot be validated as an issn,
1827
  it returns nothing.
1828
1829
=cut
1830
1831
sub NormalizeISSN {
1832
    my ($params) = @_;
1833
1834
    my $string        = $params->{issn};
1835
    my $strip_hyphen  = $params->{strip_hyphen};
1836
1837
    my $issn = Business::ISSN->new($string);
1838
1839
    if ( $issn && $issn->is_valid ){
1840
1841
        if ($strip_hyphen) {
1842
            $string = $issn->_issn;
1843
        }
1844
        else {
1845
            $string = $issn->as_string;
1846
        }
1847
        return $string;
1848
    }
1849
1850
}
1851
1852
=head2 GetVariationsOfISSN
1853
1854
  my @issns = GetVariationsOfISSN( $issn );
1855
1856
  Returns a list of variations of the given issn in
1857
  with and without a hyphen.
1858
1859
  In a scalar context, the issns are returned as a
1860
  string delimited by ' | '.
1861
1862
=cut
1863
1864
sub GetVariationsOfISSN {
1865
    my ($issn) = @_;
1866
1867
    return unless $issn;
1868
1869
    my @issns;
1870
1871
    push( @issns, NormalizeISSN({ issn => $issn }) );
1872
    push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) );
1873
1874
    # Strip out any "empty" strings from the array
1875
    @issns = grep { defined($_) && $_ =~ /\S/ } @issns;
1876
1877
    return wantarray ? @issns : join( " | ", @issns );
1878
}
1879
1880
=head2 GetVariationsOfISSNs
1881
1882
  my @issns = GetVariationsOfISSNs( @issns );
1883
1884
  Returns a list of variations of the given issns in
1885
  with and without a hyphen.
1886
1887
  In a scalar context, the issns are returned as a
1888
  string delimited by ' | '.
1889
1890
=cut
1891
1892
sub GetVariationsOfISSNs {
1893
    my (@issns) = @_;
1894
1895
    @issns = map { GetVariationsOfISSN( $_ ) } @issns;
1896
1897
    return wantarray ? @issns : join( " | ", @issns );
1898
}
1899
1900
1812
=head2 IsKohaFieldLinked
1901
=head2 IsKohaFieldLinked
1813
1902
1814
    my $is_linked = IsKohaFieldLinked({
1903
    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 / +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