From 01c32453438f561617c55c466a106236775536b9 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Thu, 29 Jul 2010 16:12:27 +0200 Subject: [PATCH] [SIGNED-OFF]Bug 4305 Get Amazon book covers for ISBN13 Content-Type: text/plain; charset="utf-8" The way Koha get book cover from Amazon doesn't work from biblio records having ISBN13 because Amazon expect an ISBN10. This patch transforms ISBN13 into ISBN10 before sending it to Amazon. Warning! On some devel installations, you will have to install by hand a new CPAN depency: Business::ISBN --- C4/Installer/PerlDependencies.pm | 5 +++++ C4/Koha.pm | 21 ++++++++------------- install_misc/apt-get-debian-lenny.sh | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 19a84a0..3ac49dc 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -464,6 +464,11 @@ our $PERL_DEPS = { 'required' => '0', 'min_ver' => '0.97', }, + 'Business::ISBN' => { + 'usage' => 'Core', + 'required' => '0', + 'min_ver' => '2.05', + }, }; 1; diff --git a/C4/Koha.pm b/C4/Koha.pm index cb93034..fb27ee2 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -24,6 +24,7 @@ use C4::Context; use C4::Output; use URI::Split qw(uri_split); use Memoize; +use Business::ISBN; use vars qw($VERSION @ISA @EXPORT $DEBUG); @@ -1235,6 +1236,7 @@ sub GetNormalizedUPC { } # Normalizes and returns the first valid ISBN found in the record +# ISBN13 are converted into ISBN10. This is required to get Amazon cover book. sub GetNormalizedISBN { my ($isbn,$record,$marcflavour) = @_; my @fields; @@ -1321,19 +1323,12 @@ sub _normalize_match_point { } sub _isbn_cleanup ($) { - my $normalized_isbn = shift; - $normalized_isbn =~ s/-//g; - $normalized_isbn =~/([0-9x]{1,})/i; - $normalized_isbn = $1; - if ( - $normalized_isbn =~ /\b(\d{13})\b/ or - $normalized_isbn =~ /\b(\d{12})\b/i or - $normalized_isbn =~ /\b(\d{10})\b/ or - $normalized_isbn =~ /\b(\d{9}X)\b/i - ) { - return $1; - } - return undef; + my $isbn = Business::ISBN->new( shift ); + return undef unless $isbn; + $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13'; + $isbn = $isbn->as_string; + $isbn =~ s/-//g; + return $isbn; } 1; diff --git a/install_misc/apt-get-debian-lenny.sh b/install_misc/apt-get-debian-lenny.sh index 48c53e4..8b90a85 100755 --- a/install_misc/apt-get-debian-lenny.sh +++ b/install_misc/apt-get-debian-lenny.sh @@ -12,6 +12,7 @@ idzebra-2.0 \ idzebra-2.0-utils \ libalgorithm-checkdigits-perl \ libbiblio-endnotestyle-perl \ +libbusiness-isbn-perl \ libcgi-session-perl \ libcgi-session-serialize-yaml-perl \ libclass-accessor-perl \ -- 1.5.6.5