From 18134d8343004f8e3daf2b615232e53f5e42db26 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 27 Nov 2025 12:38:53 +0100 Subject: [PATCH] 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 Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer Signed-off-by: Pedro Amorim --- C4/External/Amazon.pm | 80 ------------------- catalogue/detail.pl | 14 ++-- .../data/mysql/atomicupdate/bug_41318.pl | 32 ++++++++ .../data/mysql/localization/de-DE/custom.sql | 2 +- .../data/mysql/localization/fr-CA/custom.sql | 2 +- installer/data/mysql/mandatory/sysprefs.sql | 2 +- .../admin/preferences/enhanced_content.pref | 24 +++--- .../prog/en/modules/catalogue/detail.tt | 2 +- .../bootstrap/en/includes/cover-images.inc | 3 +- .../bootstrap/en/modules/opac-detail.tt | 2 +- opac/opac-detail.pl | 3 - t/db_dependent/Amazon.t | 51 ------------ 12 files changed, 58 insertions(+), 159 deletions(-) delete mode 100644 C4/External/Amazon.pm create mode 100755 installer/data/mysql/atomicupdate/bug_41318.pl delete mode 100755 t/db_dependent/Amazon.t diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm deleted file mode 100644 index 297443fdf0..0000000000 --- a/C4/External/Amazon.pm +++ /dev/null @@ -1,80 +0,0 @@ -package C4::External::Amazon; - -# Copyright (C) 2006 LibLime -# -# -# 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 . - -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 - -=cut diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 7aae3d53e3..491b13c0ea 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -30,13 +30,12 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Biblio qw( GetBiblioData GetFrameworkCode ); use C4::Items qw( GetAnalyticsCount ); use C4::Reserves; -use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); -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::Tags qw( get_tags ); -use C4::XSLT qw( XSLTParse4Display ); -use Koha::DateUtils qw( format_sqldatetime ); +use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); +use C4::XISBN qw( get_xisbns ); +use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra ); +use C4::Tags qw( get_tags ); +use C4::XSLT qw( XSLTParse4Display ); +use Koha::DateUtils qw( format_sqldatetime ); use C4::HTML5Media; use C4::CourseReserves qw( GetItemCourseReservesInfo ); use Koha::AuthorisedValues; @@ -425,7 +424,6 @@ foreach ( keys %{$dat} ) { # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews'); # method query not found?!?! -$template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages") ); $template->param( biblionumber => $biblionumber, ( $analyze ? 'analyze' : 'detailview' ) => 1, diff --git a/installer/data/mysql/atomicupdate/bug_41318.pl b/installer/data/mysql/atomicupdate/bug_41318.pl new file mode 100755 index 0000000000..c257cf48aa --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41318.pl @@ -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" ); + } + }, +}; diff --git a/installer/data/mysql/localization/de-DE/custom.sql b/installer/data/mysql/localization/de-DE/custom.sql index c30dad0d1d..99bf368be2 100644 --- a/installer/data/mysql/localization/de-DE/custom.sql +++ b/installer/data/mysql/localization/de-DE/custom.sql @@ -16,7 +16,7 @@ -- You should have received a copy of the GNU General Public License -- along with Koha; if not, see . -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 = 'Herr|Frau' WHERE variable = 'BorrowersTitles'; UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat'; diff --git a/installer/data/mysql/localization/fr-CA/custom.sql b/installer/data/mysql/localization/fr-CA/custom.sql index da727eaf90..941cf9dd75 100644 --- a/installer/data/mysql/localization/fr-CA/custom.sql +++ b/installer/data/mysql/localization/fr-CA/custom.sql @@ -17,7 +17,7 @@ -- along with Koha; if not, see . 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 = 'M.|Mme|Mx' WHERE variable = 'BorrowersTitles'; UPDATE systempreferences SET value = 'FR' WHERE variable = 'CurencyFormat'; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index a1a09d77e7..d513d59912 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -65,7 +65,7 @@ INSERT INTO systempreferences ( `variable`, `value` ) VALUES ('AlwaysShowHoldingsTableFilters','0'), ('AmazonAssocTag',''), ('AmazonCoverImages','0'), -('AmazonLocale','US'), +('AmazonLocaleTld','com'), ('AnonSuggestions','0'), ('AnonymizeLastBorrower','0'), ('AnonymizeLastBorrowerDays','0'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref index 4cd49e2a6b..312c6ad2c1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -18,17 +18,19 @@ Enhanced content: - other editions of an item on the OPAC. Amazon: - - - Use Amazon data from its - - pref: AmazonLocale - choices: - US: American - CA: Canadian - DE: German - FR: French - IN: Indian - JP: Japanese - UK: British - - website. + - Use Amazon data using the following top-level domain + - pref: AmazonLocaleTld + - . + - '
Options:
    ' + - '
  • Enter "com" for American
  • ' + - '
  • Enter "com.br" for Brazilian
  • ' + - '
  • Enter "co.uk" for British
  • ' + - '
  • Enter "ca" for Canadian
  • ' + - '
  • Enter "fr" for French
  • ' + - '
  • Enter "de" for German
  • ' + - '
  • Enter "in" for Indian
  • ' + - '
  • Enter "jp" for Japanese
  • ' + - '
' - - Put the associate tag - pref: AmazonAssocTag diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 229acb28ea..340fc272f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -278,7 +278,7 @@ Amazon cover image
Image from Amazon.com
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/cover-images.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/cover-images.inc index 6ff39db6f1..912dbb7d73 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/cover-images.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/cover-images.inc @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE ItemTypes %]
Image from Amazon.com
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index a7e9b9a5ef..a9502b0672 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -100,7 +100,7 @@ Amazon cover image
Image from Amazon.com
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 064eab3205..914bba5f5e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -43,7 +43,6 @@ use C4::Biblio qw( use C4::Record qw( marc2cites ); use C4::Tags qw( get_tags ); use C4::XISBN qw( get_xisbns ); -use C4::External::Amazon qw( get_amazon_tld ); use C4::External::Syndetics qw( get_syndetics_anotes 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; if ( C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail') ) { $template->param( diff --git a/t/db_dependent/Amazon.t b/t/db_dependent/Amazon.t deleted file mode 100755 index 7af8666621..0000000000 --- a/t/db_dependent/Amazon.t +++ /dev/null @@ -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();