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

(-)a/C4/Letters.pm (-9 / +12 lines)
Lines 699-710 sub GetPreparedLetter { Link Here
699
               return;
699
               return;
700
    }
700
    }
701
701
702
    my $objects = $params{objects} || {};
702
    my $tables = $params{tables} || {};
703
    my $tables = $params{tables} || {};
703
    my $substitute = $params{substitute} || {};
704
    my $substitute = $params{substitute} || {};
704
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
705
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
705
    my $repeat = $params{repeat};
706
    my $repeat = $params{repeat};
706
    %$tables || %$substitute || $repeat || %$loops
707
    %$tables || %$substitute || $repeat || %$loops || %$objects
707
      or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ),
708
      or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ),
708
         return;
709
         return;
709
    my $want_librarian = $params{want_librarian};
710
    my $want_librarian = $params{want_librarian};
710
711
Lines 779-788 sub GetPreparedLetter { Link Here
779
780
780
    $letter->{content} = _process_tt(
781
    $letter->{content} = _process_tt(
781
        {
782
        {
782
            content => $letter->{content},
783
            content    => $letter->{content},
783
            tables  => $tables,
784
            tables     => $tables,
784
            loops  => $loops,
785
            loops      => $loops,
785
            substitute => $substitute,
786
            substitute => $substitute,
787
            objects    => $objects,
786
        }
788
        }
787
    );
789
    );
788
790
Lines 1454-1462 sub _set_message_status { Link Here
1454
sub _process_tt {
1456
sub _process_tt {
1455
    my ( $params ) = @_;
1457
    my ( $params ) = @_;
1456
1458
1457
    my $content = $params->{content};
1459
    my $content    = $params->{content};
1458
    my $tables = $params->{tables};
1460
    my $tables     = $params->{tables};
1459
    my $loops = $params->{loops};
1461
    my $loops      = $params->{loops};
1462
    my $objects    = $params->{objects};
1460
    my $substitute = $params->{substitute} || {};
1463
    my $substitute = $params->{substitute} || {};
1461
1464
1462
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1465
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
Lines 1472-1478 sub _process_tt { Link Here
1472
        }
1475
        }
1473
    ) or die Template->error();
1476
    ) or die Template->error();
1474
1477
1475
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1478
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
1476
1479
1477
    $content = qq|[% USE KohaDates %]$content|;
1480
    $content = qq|[% USE KohaDates %]$content|;
1478
1481
(-)a/Koha/Object.pm (+8 lines)
Lines 120-125 Returns: Link Here
120
sub store {
120
sub store {
121
    my ($self) = @_;
121
    my ($self) = @_;
122
122
123
    return $self if ( ( caller() )[0] eq 'Template::Document' );
124
123
    try {
125
    try {
124
        return $self->_result()->update_or_insert() ? $self : undef;
126
        return $self->_result()->update_or_insert() ? $self : undef;
125
    }
127
    }
Lines 162-167 Returns: Link Here
162
sub delete {
164
sub delete {
163
    my ($self) = @_;
165
    my ($self) = @_;
164
166
167
    return $self if ( ( caller() )[0] eq 'Template::Document' );
168
165
    # Deleting something not in storage throws an exception
169
    # Deleting something not in storage throws an exception
166
    return -1 unless $self->_result()->in_storage();
170
    return -1 unless $self->_result()->in_storage();
167
171
Lines 351-356 sub AUTOLOAD { Link Here
351
    my @known_methods = qw( is_changed id in_storage get_column discard_changes update );
355
    my @known_methods = qw( is_changed id in_storage get_column discard_changes update );
352
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
356
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
353
357
358
    if ( $method eq 'update' ) {
359
        return $self if ( ( caller() )[0] eq 'Template::Document' );
360
    }
361
354
    my $r = eval { $self->_result->$method(@_) };
362
    my $r = eval { $self->_result->$method(@_) };
355
    if ( $@ ) {
363
    if ( $@ ) {
356
        Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ );
364
        Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ );
(-)a/Koha/Objects.pm (+4 lines)
Lines 383-388 sub AUTOLOAD { Link Here
383
    my $method = our $AUTOLOAD;
383
    my $method = our $AUTOLOAD;
384
    $method =~ s/.*:://;
384
    $method =~ s/.*:://;
385
385
386
    if ( $method eq 'update' || $method eq 'delete' ) {
387
        return $self if ( ( caller() )[0] eq 'Template::Document' );
388
    }
389
386
    carp "The method $method is not covered by tests" and return unless grep {/^$method$/} @known_methods;
390
    carp "The method $method is not covered by tests" and return unless grep {/^$method$/} @known_methods;
387
    my $r = eval { $self->_resultset->$method(@params) };
391
    my $r = eval { $self->_resultset->$method(@params) };
388
    if ( $@ ) {
392
    if ( $@ ) {
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +13 lines)
Lines 19-25 Link Here
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
use Test::More tests => 17;
22
use Test::More tests => 18;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use MARC::Record;
25
use MARC::Record;
Lines 42-47 use Koha::Serial; Link Here
42
use Koha::Subscription;
42
use Koha::Subscription;
43
use Koha::Suggestion;
43
use Koha::Suggestion;
44
use Koha::Checkout;
44
use Koha::Checkout;
45
use Koha::Patrons;
45
use Koha::Notice::Messages;
46
use Koha::Notice::Messages;
46
use Koha::Notice::Templates;
47
use Koha::Notice::Templates;
47
use Koha::Patron::Modification;
48
use Koha::Patron::Modification;
Lines 134-139 $prepared_letter = GetPreparedLetter( Link Here
134
);
135
);
135
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref' );
136
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref' );
136
137
138
$prepared_letter = GetPreparedLetter(
139
    (
140
        module      => 'test',
141
        letter_code => 'TEST_PATRON',
142
        objects      => {
143
            borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ),
144
        },
145
    )
146
);
147
is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' );
148
137
$sth->execute( "TEST_BIBLIO", "[% biblio.id %]" );
149
$sth->execute( "TEST_BIBLIO", "[% biblio.id %]" );
138
$prepared_letter = GetPreparedLetter(
150
$prepared_letter = GetPreparedLetter(
139
    (
151
    (
140
- 

Return to bug 19966