View | Details | Raw Unified | Return to bug 17762
Collapse All | Expand All

(-)a/C4/Letters.pm (-5 / +11 lines)
Lines 198-205 sub GetLettersAvailableForALibrary { Link Here
198
}
198
}
199
199
200
sub getletter {
200
sub getletter {
201
    my ( $module, $code, $branchcode, $message_transport_type ) = @_;
201
    my ( $module, $code, $branchcode, $message_transport_type, $lang) = @_;
202
    $message_transport_type //= '%';
202
    $message_transport_type //= '%';
203
    $lang //= 'default';
203
204
204
    if ( C4::Context->preference('IndependentBranches')
205
    if ( C4::Context->preference('IndependentBranches')
205
            and $branchcode
206
            and $branchcode
Lines 215-223 sub getletter { Link Here
215
        FROM letter
216
        FROM letter
216
        WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '')
217
        WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '')
217
        AND message_transport_type LIKE ?
218
        AND message_transport_type LIKE ?
219
        AND lang =?
218
        ORDER BY branchcode DESC LIMIT 1
220
        ORDER BY branchcode DESC LIMIT 1
219
    });
221
    });
220
    $sth->execute( $module, $code, $branchcode, $message_transport_type );
222
    $sth->execute( $module, $code, $branchcode, $message_transport_type, $lang );
221
    my $line = $sth->fetchrow_hashref
223
    my $line = $sth->fetchrow_hashref
222
      or return;
224
      or return;
223
    $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
225
    $line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
Lines 688-696 sub GetPreparedLetter { Link Here
688
    my $mtt         = $params{message_transport_type} || 'email';
690
    my $mtt         = $params{message_transport_type} || 'email';
689
    my $lang        = $params{lang} || 'default';
691
    my $lang        = $params{lang} || 'default';
690
692
691
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
693
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang );
692
        or warn( "No $module $letter_code letter transported by " . $mtt ),
694
693
            return;
695
    unless ( $letter ) {
696
        $letter = getletter( $module, $letter_code, $branchcode, $mtt, 'default' )
697
            or warn( "No $module $letter_code letter transported by " . $mtt ),
698
               return;
699
    }
694
700
695
    my $tables = $params{tables} || {};
701
    my $tables = $params{tables} || {};
696
    my $substitute = $params{substitute} || {};
702
    my $substitute = $params{substitute} || {};
(-)a/t/db_dependent/Letters.t (-2 / +47 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 81;
21
use Test::More tests => 82;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 534-539 is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notificatio Link Here
534
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
534
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
535
}
535
}
536
536
537
538
subtest 'TranslateNotices' => sub {
539
    plan tests => 3;
540
    $dbh->do(
541
        q|
542
        INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
543
        ('test', 'code', '', 'test', 'a test', 'just a test', 'email', 'default'),
544
        ('test', 'code', '', 'test', 'una prueba', 'solo una prueba', 'email', 'es-ES');
545
    | );
546
    my $substitute = {};
547
    my $letter = C4::Letters::GetPreparedLetter(
548
            module                 => 'test',
549
            letter_code            => 'code',
550
            message_transport_type => 'email',
551
            substitute             => $substitute,
552
    );
553
    is(
554
        $letter->{title},
555
        'a test',
556
        'GetPreparedLetter should return the default one if the lang parameter is not provided'
557
    );
558
559
    $letter = C4::Letters::GetPreparedLetter(
560
            module                 => 'test',
561
            letter_code            => 'code',
562
            message_transport_type => 'email',
563
            substitute             => $substitute,
564
            lang                   => 'es-ES',
565
    );
566
    is( $letter->{title}, 'una prueba',
567
        'GetPreparedLetter should return the required notice if it exists' );
568
569
    $letter = C4::Letters::GetPreparedLetter(
570
            module                 => 'test',
571
            letter_code            => 'code',
572
            message_transport_type => 'email',
573
            substitute             => $substitute,
574
            lang                   => 'fr-FR',
575
    );
576
    is(
577
        $letter->{title},
578
        'a test',
579
        'GetPreparedLetter should return the default notice if the one required does not exist'
580
    );
581
};
582
537
subtest 'SendQueuedMessages' => sub {
583
subtest 'SendQueuedMessages' => sub {
538
    plan tests => 1;
584
    plan tests => 1;
539
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
585
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
540
- 

Return to bug 17762