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 687-695 sub GetPreparedLetter { Link Here
687
    my $mtt         = $params{message_transport_type} || 'email';
689
    my $mtt         = $params{message_transport_type} || 'email';
688
    my $lang        = $params{lang} || 'default';
690
    my $lang        = $params{lang} || 'default';
689
691
690
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
692
    my $letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang );
691
        or warn( "No $module $letter_code letter transported by " . $mtt ),
693
692
            return;
694
    unless ( $letter ) {
695
        $letter = getletter( $module, $letter_code, $branchcode, $mtt, 'default' )
696
            or warn( "No $module $letter_code letter transported by " . $mtt ),
697
                return;
698
    }
693
699
694
    my $tables = $params{tables};
700
    my $tables = $params{tables};
695
    my $substitute = $params{substitute};
701
    my $substitute = $params{substitute};
(-)a/t/db_dependent/Letters.t (-2 / +46 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 => 79;
21
use Test::More tests => 80;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 489-491 is($err2, 1, "Successfully sent serial notification"); Link Here
489
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
489
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
491
}
491
}
492
- 
492
493
subtest 'TranslateNotices' => sub {
494
    plan tests => 3;
495
    $dbh->do(
496
        q|
497
        INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
498
        ('test', 'code', '', 'test', 'a test', 'just a test', 'email', 'default'),
499
        ('test', 'code', '', 'test', 'una prueba', 'solo una prueba', 'email', 'es-ES');
500
    | );
501
    my $substitute = {};
502
    my $letter = C4::Letters::GetPreparedLetter(
503
            module                 => 'test',
504
            letter_code            => 'code',
505
            message_transport_type => 'email',
506
            substitute             => $substitute,
507
    );
508
    is(
509
        $letter->{title},
510
        'a test',
511
        'GetPreparedLetter should return the default one if the lang parameter is not provided'
512
    );
513
514
    $letter = C4::Letters::GetPreparedLetter(
515
            module                 => 'test',
516
            letter_code            => 'code',
517
            message_transport_type => 'email',
518
            substitute             => $substitute,
519
            lang                   => 'es-ES',
520
    );
521
    is( $letter->{title}, 'una prueba',
522
        'GetPreparedLetter should return the required notice if it exists' );
523
524
    $letter = C4::Letters::GetPreparedLetter(
525
            module                 => 'test',
526
            letter_code            => 'code',
527
            message_transport_type => 'email',
528
            substitute             => $substitute,
529
            lang                   => 'fr-FR',
530
    );
531
    is(
532
        $letter->{title},
533
        'a test',
534
        'GetPreparedLetter should return the default notice if the one required does not exist'
535
    );
536
};

Return to bug 17762