Bug 41318: Rename AmazonLocale to AmazonLocaleTld

To be more flexible we could allow the top-level domain instead of
having a predefined list.
However this patch still list the different available options (and adds
Brazilian) for easy selection.

Note that this system preference is not used to retrieve the image but
only to link to from the image. Contrary to what the reporter of the bug
report thought. And actually what I thought as well until I finished to
write the patch and started testing it!
Anyway now the patch is written, there should not be any changes in
behaviour. Most of the time the links are actually broken when not using
.com. So I think we either broke the whole feature at some point, or it
never really worked. On a separate bug we could eventually have a look
at fetching from the locale tld.

Test plan:
Turn on OPACAmazonCoverImages and AmazonCoverImages
http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=5
http://localhost:8080/cgi-bin/koha/opac-detail.pl?biblionumber=5
=> You see the PBP cover
click on it, it opens the lightbox, click "(see the original image)" at
the bottom
=> This is where the syspref AmazonLocale/AmazonLocaleTld acts

Modify the syspref's value and confirm that the link is modified and
point to the correct domain (leading to 404 or broken pages most of the time,
at least in my tests).

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Jonathan Druart 2025-11-27 12:38:53 +01:00 committed by Pedro Amorim
parent 3b2a4f53ed
commit 18134d8343
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
12 changed files with 58 additions and 159 deletions

80
C4/External/Amazon.pm vendored
View File

@ -1,80 +0,0 @@
package C4::External::Amazon;
# Copyright (C) 2006 LibLime
# <jmf at liblime dot com>
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.
use strict;
use warnings;
use vars qw(@ISA @EXPORT);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
get_amazon_tld
);
}
sub get_amazon_tld {
my %tld = (
CA => '.ca',
DE => '.de',
FR => '.fr',
IN => '.in',
JP => '.jp',
UK => '.co.uk',
US => '.com',
);
my $locale = C4::Context->preference('AmazonLocale');
my $tld = $tld{$locale} || '.com'; # default top level domain is .com
return $tld;
}
=head1 NAME
C4::External::Amazon - Functions for retrieving Amazon.com content in Koha
=head2 FUNCTIONS
This module provides facilities for retrieving Amazon.com content in Koha
=over
=item get_amazon_tld()
Get Amazon Top Level Domain depending on Amazon local preference: AmazonLocal.
For example, if AmazonLocal is 'UK', returns '.co.uk'.
=back
=cut
1;
__END__
=head1 NOTES
=cut
=head1 AUTHOR
Joshua Ferraro <jmf@liblime.com>
=cut

View File

@ -30,13 +30,12 @@ use C4::Output qw( output_html_with_http_headers );
use C4::Biblio qw( GetBiblioData GetFrameworkCode ); use C4::Biblio qw( GetBiblioData GetFrameworkCode );
use C4::Items qw( GetAnalyticsCount ); use C4::Items qw( GetAnalyticsCount );
use C4::Reserves; use C4::Reserves;
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
use C4::XISBN qw( get_xisbns ); use C4::XISBN qw( get_xisbns );
use C4::External::Amazon qw( get_amazon_tld ); use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra );
use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra ); use C4::Tags qw( get_tags );
use C4::Tags qw( get_tags ); use C4::XSLT qw( XSLTParse4Display );
use C4::XSLT qw( XSLTParse4Display ); use Koha::DateUtils qw( format_sqldatetime );
use Koha::DateUtils qw( format_sqldatetime );
use C4::HTML5Media; use C4::HTML5Media;
use C4::CourseReserves qw( GetItemCourseReservesInfo ); use C4::CourseReserves qw( GetItemCourseReservesInfo );
use Koha::AuthorisedValues; use Koha::AuthorisedValues;
@ -425,7 +424,6 @@ foreach ( keys %{$dat} ) {
# does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews'); # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
# method query not found?!?! # method query not found?!?!
$template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages") );
$template->param( $template->param(
biblionumber => $biblionumber, biblionumber => $biblionumber,
( $analyze ? 'analyze' : 'detailview' ) => 1, ( $analyze ? 'analyze' : 'detailview' ) => 1,

View File

@ -0,0 +1,32 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "41318",
description => "Rename system preference AmazonLocale to AmazonLocaleTld",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
my $pref_exists =
$dbh->selectrow_array(q{SELECT COUNT(*) FROM systempreferences WHERE variable = "AmazonLocale"});
if ($pref_exists) {
$dbh->do(
q{
UPDATE systempreferences
SET `variable`="AmazonLocaleTld",
`value` = CASE `value`
WHEN 'CA' THEN 'ca'
WHEN 'UK' THEN 'co.uk'
WHEN 'DE' THEN 'de'
WHEN 'FR' THEN 'fr'
WHEN 'IN' THEN 'in'
WHEN 'JP' THEN 'jp'
ELSE 'com'
END
WHERE `variable`="AmazonLocale"
}
) && say_info( $out, "Renamed system preference 'AmazonLocale' to 'AmazonLocaleTld" );
}
},
};

View File

@ -16,7 +16,7 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with Koha; if not, see <https://www.gnu.org/licenses>. -- along with Koha; if not, see <https://www.gnu.org/licenses>.
UPDATE systempreferences SET value = 'DE' WHERE variable = 'AmazonLocale'; UPDATE systempreferences SET value = 'de' WHERE variable = 'AmazonLocaleTld';
UPDATE systempreferences SET value = 'Vater|Mutter' WHERE variable = 'borrowerRelationship'; UPDATE systempreferences SET value = 'Vater|Mutter' WHERE variable = 'borrowerRelationship';
UPDATE systempreferences SET value = 'Herr|Frau' WHERE variable = 'BorrowersTitles'; UPDATE systempreferences SET value = 'Herr|Frau' WHERE variable = 'BorrowersTitles';
UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat'; UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat';

View File

@ -17,7 +17,7 @@
-- along with Koha; if not, see <https://www.gnu.org/licenses>. -- along with Koha; if not, see <https://www.gnu.org/licenses>.
UPDATE systempreferences SET value = 'fre|eng' WHERE variable = 'AdvancedSearchLanguages'; UPDATE systempreferences SET value = 'fre|eng' WHERE variable = 'AdvancedSearchLanguages';
UPDATE systempreferences SET value = 'CA' WHERE variable = 'AmazonLocale'; UPDATE systempreferences SET value = 'ca' WHERE variable = 'AmazonLocaleTld';
UPDATE systempreferences SET value = 'père|mère|grand-parent|tuteur légal|autre' WHERE variable = 'borrowerRelationship'; UPDATE systempreferences SET value = 'père|mère|grand-parent|tuteur légal|autre' WHERE variable = 'borrowerRelationship';
UPDATE systempreferences SET value = 'M.|Mme|Mx' WHERE variable = 'BorrowersTitles'; UPDATE systempreferences SET value = 'M.|Mme|Mx' WHERE variable = 'BorrowersTitles';
UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat'; UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat';

View File

@ -65,7 +65,7 @@ INSERT INTO systempreferences ( `variable`, `value` ) VALUES
('AlwaysShowHoldingsTableFilters','0'), ('AlwaysShowHoldingsTableFilters','0'),
('AmazonAssocTag',''), ('AmazonAssocTag',''),
('AmazonCoverImages','0'), ('AmazonCoverImages','0'),
('AmazonLocale','US'), ('AmazonLocaleTld','com'),
('AnonSuggestions','0'), ('AnonSuggestions','0'),
('AnonymizeLastBorrower','0'), ('AnonymizeLastBorrower','0'),
('AnonymizeLastBorrowerDays','0'), ('AnonymizeLastBorrowerDays','0'),

View File

@ -18,17 +18,19 @@ Enhanced content:
- other editions of an item on the OPAC. - other editions of an item on the OPAC.
Amazon: Amazon:
- -
- Use Amazon data from its - Use Amazon data using the following top-level domain
- pref: AmazonLocale - pref: AmazonLocaleTld
choices: - .
US: American - '<br />Options:<ul>'
CA: Canadian - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="com">com</a>" for American</li>'
DE: German - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="com.br">com.br</a>" for Brazilian</li>'
FR: French - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="co.uk">co.uk</a>" for British</li>'
IN: Indian - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="ca">ca</a>" for Canadian</li>'
JP: Japanese - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="fr">fr</a>" for French</li>'
UK: British - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="de">de</a>" for German</li>'
- website. - '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="in">in</a>" for Indian</li>'
- '<li>Enter "<a href="#" class="set_syspref" data-syspref="AmazonLocaleTld" data-value="jp">jp</a>" for Japanese</li>'
- '</ul>'
- -
- Put the associate tag - Put the associate tag
- pref: AmazonAssocTag - pref: AmazonAssocTag

View File

@ -278,7 +278,7 @@
<img <img
src="https://images-na.ssl-images-amazon.com/images/P/[% normalized_isbn | uri %].01.MZZZZZZZ.jpg" src="https://images-na.ssl-images-amazon.com/images/P/[% normalized_isbn | uri %].01.MZZZZZZZ.jpg"
alt="Amazon cover image" alt="Amazon cover image"
data-link="http://www.amazon[% AmazonTld | uri %]/gp/reader/[% normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link" data-link="http://www.amazon.[% Koha.Preference('AmazonLocaleTld') | uri %]/gp/reader/[% normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link"
/> />
</a> </a>
<div class="hint">Image from Amazon.com</div> <div class="hint">Image from Amazon.com</div>

View File

@ -1,4 +1,5 @@
[% USE raw %] [% USE raw %]
[% USE Koha %]
[% USE ItemTypes %] [% USE ItemTypes %]
<div <div
class="bookcover" class="bookcover"
@ -33,7 +34,7 @@
src="https://images-na.ssl-images-amazon.com/images/P/[% SEARCH_RESULT.normalized_isbn | uri %].01.MZZZZZZZ.jpg" src="https://images-na.ssl-images-amazon.com/images/P/[% SEARCH_RESULT.normalized_isbn | uri %].01.MZZZZZZZ.jpg"
alt="Amazon cover image" alt="Amazon cover image"
id="amazon-thumbnail-[% SEARCH_RESULT.biblionumber | html %]" id="amazon-thumbnail-[% SEARCH_RESULT.biblionumber | html %]"
data-link="http://www.amazon[% AmazonTld | uri %]/gp/reader/[% SEARCH_RESULT.normalized_isbn | html %][% AmazonAssocTag | html %]#reader-link" data-link="http://www.amazon.[% Koha.Preference('AmazonLocaleTld') | uri %]/gp/reader/[% SEARCH_RESULT.normalized_isbn | html %][% AmazonAssocTag | html %]#reader-link"
/> />
</a> </a>
<div class="hint">Image from Amazon.com</div> <div class="hint">Image from Amazon.com</div>

View File

@ -100,7 +100,7 @@
<img <img
src="https://images-na.ssl-images-amazon.com/images/P/[% normalized_isbn | uri %].01.MZZZZZZZ.jpg" src="https://images-na.ssl-images-amazon.com/images/P/[% normalized_isbn | uri %].01.MZZZZZZZ.jpg"
alt="Amazon cover image" alt="Amazon cover image"
data-link="http://www.amazon[% AmazonTld | uri %]/gp/reader/[% normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link" data-link="http://www.amazon.[% Koha.Preference('AmazonLocaleTld') | uri %]/gp/reader/[% normalized_isbn | uri %][% AmazonAssocTag | uri %]#reader-link"
/> />
</a> </a>
<div class="hint">Image from Amazon.com</div> <div class="hint">Image from Amazon.com</div>

View File

@ -43,7 +43,6 @@ use C4::Biblio qw(
use C4::Record qw( marc2cites ); use C4::Record qw( marc2cites );
use C4::Tags qw( get_tags ); use C4::Tags qw( get_tags );
use C4::XISBN qw( get_xisbns ); use C4::XISBN qw( get_xisbns );
use C4::External::Amazon qw( get_amazon_tld );
use C4::External::Syndetics qw( use C4::External::Syndetics qw(
get_syndetics_anotes get_syndetics_anotes
get_syndetics_excerpt get_syndetics_excerpt
@ -1135,8 +1134,6 @@ if ( C4::Context->preference("OPACShelfBrowser") ) {
} }
} }
$template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages") );
my $tag_quantity; my $tag_quantity;
if ( C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail') ) { if ( C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail') ) {
$template->param( $template->param(

View File

@ -1,51 +0,0 @@
#!/usr/bin/perl
#
# This Koha test module is a stub!
# Add more tests here!!!
use strict;
use warnings;
use Test::NoWarnings;
use Test::More tests => 9;
use t::lib::Mocks;
use C4::Context;
BEGIN {
use_ok( 'C4::External::Amazon', qw( get_amazon_tld ) );
}
my $context = C4::Context->new();
my $locale = $context->preference('AmazonLocale');
t::lib::Mocks::mock_preference( 'AmazonLocale', 'CA' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.ca', 'Changes locale to CA and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'DE' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.de', 'Changes locale to DE and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'FR' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.fr', 'Changes locale to FR and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'JP' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.jp', 'Changes locale to JP and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'UK' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.co.uk', 'Changes locale to UK and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'US' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.com', 'Changes locale to US and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', 'NZ' );
$context->clear_syspref_cache();
is( get_amazon_tld, '.com', 'Changes locale to one not in the array and tests get_amazon_tld' );
t::lib::Mocks::mock_preference( 'AmazonLocale', $locale );
$context->clear_syspref_cache();