From c49bdc3a8d8e5a9389a27a8dca90544ff5c42f95 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 8 Dec 2016 17:51:44 +0100 Subject: [PATCH] Bug 17762: Add the lang parameter to C4::Letters::getletter Sponsored-by: Orex Digital Signed-off-by: Hugo Agud Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall --- C4/Letters.pm | 16 +++++++++----- t/db_dependent/Letters.t | 48 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index f0e155c3a8..ea5cb9fa1a 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -198,8 +198,9 @@ sub GetLettersAvailableForALibrary { } sub getletter { - my ( $module, $code, $branchcode, $message_transport_type ) = @_; + my ( $module, $code, $branchcode, $message_transport_type, $lang) = @_; $message_transport_type //= '%'; + $lang //= 'default'; if ( C4::Context->preference('IndependentBranches') and $branchcode @@ -215,9 +216,10 @@ sub getletter { FROM letter WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type LIKE ? + AND lang =? ORDER BY branchcode DESC LIMIT 1 }); - $sth->execute( $module, $code, $branchcode, $message_transport_type ); + $sth->execute( $module, $code, $branchcode, $message_transport_type, $lang ); my $line = $sth->fetchrow_hashref or return; $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html}; @@ -688,9 +690,13 @@ sub GetPreparedLetter { my $mtt = $params{message_transport_type} || 'email'; my $lang = $params{lang} || 'default'; - my $letter = getletter( $module, $letter_code, $branchcode, $mtt ) - or warn( "No $module $letter_code letter transported by " . $mtt ), - return; + my $letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang ); + + unless ( $letter ) { + $letter = getletter( $module, $letter_code, $branchcode, $mtt, 'default' ) + or warn( "No $module $letter_code letter transported by " . $mtt ), + return; + } my $tables = $params{tables} || {}; my $substitute = $params{substitute} || {}; diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index e1d67a6e81..48b12aebb6 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 81; +use Test::More tests => 82; use Test::MockModule; use Test::Warn; @@ -534,6 +534,52 @@ is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notificatio is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully'); } + +subtest 'TranslateNotices' => sub { + plan tests => 3; + $dbh->do( + q| + INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES + ('test', 'code', '', 'test', 'a test', 'just a test', 'email', 'default'), + ('test', 'code', '', 'test', 'una prueba', 'solo una prueba', 'email', 'es-ES'); + | ); + my $substitute = {}; + my $letter = C4::Letters::GetPreparedLetter( + module => 'test', + letter_code => 'code', + message_transport_type => 'email', + substitute => $substitute, + ); + is( + $letter->{title}, + 'a test', + 'GetPreparedLetter should return the default one if the lang parameter is not provided' + ); + + $letter = C4::Letters::GetPreparedLetter( + module => 'test', + letter_code => 'code', + message_transport_type => 'email', + substitute => $substitute, + lang => 'es-ES', + ); + is( $letter->{title}, 'una prueba', + 'GetPreparedLetter should return the required notice if it exists' ); + + $letter = C4::Letters::GetPreparedLetter( + module => 'test', + letter_code => 'code', + message_transport_type => 'email', + substitute => $substitute, + lang => 'fr-FR', + ); + is( + $letter->{title}, + 'a test', + 'GetPreparedLetter should return the default notice if the one required does not exist' + ); +}; + subtest 'SendQueuedMessages' => sub { plan tests => 1; t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' ); -- 2.39.5