From 774e72602d34e7b40baf06538d3ea882455ad2a3 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 28 May 2015 11:46:43 +0300 Subject: [PATCH] Bug 14287 - Preserve valid ISBN-13 identifiers if they start with something else than 978 If Business::ISBN cannot make an ISBN-10 out of a valid ISBN-13 starting with 979, then we should preserve the ISBN-13 instead of getting rid of it. ISBN-13 starting with 979 is valid as well and in a few years starting with 980 might be as well as the ISBN supply is running out. This patch modifies the C4::Koha::NormalizeISBN() to preserve the original ISBN if type conversion fails. Use Buug 13167's TEST PLAN. --- C4/Koha.pm | 5 ++++- t/Koha.t | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 4f54a3b..d3c4f0e 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1725,7 +1725,10 @@ sub NormalizeISBN { elsif ( $format eq 'ISBN-13' ) { $isbn = $isbn->as_isbn13(); } - return unless $isbn; + unless ($isbn) { #If we cannot force the ISBN to another type, atleast prevent Koha from crashing by recovering some ISBN. + $isbn = Business::ISBN->new($string); #If we fail to force the ISBN to the given format, revert to the format we can infer. + warn "C4::Koha::NormalizeISBN():> Couldn't change ISBN '$string' to type '$format'. Using the inferred type '".$isbn->type()."' instead."; + } if ($strip_hyphens) { $string = $isbn->as_string( [] ); diff --git a/t/Koha.t b/t/Koha.t index 933fd5b..7ec3610 100755 --- a/t/Koha.t +++ b/t/Koha.t @@ -93,7 +93,7 @@ eval { $isbn = C4::Koha::NormalizeISBN({ isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 }); }; ok($@ eq '', 'NormalizeISBN does not throw exception when converting to ISBN10 an ISBN starting with 979 (bug 13167)'); -ok(!defined $isbn, 'NormalizeISBN returns undef when converting to ISBN10 an ISBN starting with 979 (bug 13167)'); +ok($isbn eq "9791090085008", 'NormalizeISBN returns ISBN-13 when converting to ISBN10 an ISBN starting with 979 (bug 14287)'); @isbns = GetVariationsOfISBNs('abc'); is(scalar(@isbns), 0, 'zero variations returned of invalid ISBN'); -- 1.7.9.5