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

(-)a/C4/Letters.pm (-9 / +12 lines)
Lines 702-713 sub GetPreparedLetter { Link Here
702
               return;
702
               return;
703
    }
703
    }
704
704
705
    my $objects = $params{objects} || {};
705
    my $tables = $params{tables} || {};
706
    my $tables = $params{tables} || {};
706
    my $substitute = $params{substitute} || {};
707
    my $substitute = $params{substitute} || {};
707
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
708
    my $loops  = $params{loops} || {}; # loops is not supported for historical notices syntax
708
    my $repeat = $params{repeat};
709
    my $repeat = $params{repeat};
709
    %$tables || %$substitute || $repeat || %$loops
710
    %$tables || %$substitute || $repeat || %$loops || %$objects
710
      or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ),
711
      or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ),
711
         return;
712
         return;
712
    my $want_librarian = $params{want_librarian};
713
    my $want_librarian = $params{want_librarian};
713
714
Lines 782-791 sub GetPreparedLetter { Link Here
782
783
783
    $letter->{content} = _process_tt(
784
    $letter->{content} = _process_tt(
784
        {
785
        {
785
            content => $letter->{content},
786
            content    => $letter->{content},
786
            tables  => $tables,
787
            tables     => $tables,
787
            loops  => $loops,
788
            loops      => $loops,
788
            substitute => $substitute,
789
            substitute => $substitute,
790
            objects    => $objects,
789
        }
791
        }
790
    );
792
    );
791
793
Lines 1457-1465 sub _set_message_status { Link Here
1457
sub _process_tt {
1459
sub _process_tt {
1458
    my ( $params ) = @_;
1460
    my ( $params ) = @_;
1459
1461
1460
    my $content = $params->{content};
1462
    my $content    = $params->{content};
1461
    my $tables = $params->{tables};
1463
    my $tables     = $params->{tables};
1462
    my $loops = $params->{loops};
1464
    my $loops      = $params->{loops};
1465
    my $objects    = $params->{objects};
1463
    my $substitute = $params->{substitute} || {};
1466
    my $substitute = $params->{substitute} || {};
1464
1467
1465
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1468
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
Lines 1475-1481 sub _process_tt { Link Here
1475
        }
1478
        }
1476
    ) or die Template->error();
1479
    ) or die Template->error();
1477
1480
1478
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute };
1481
    my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects };
1479
1482
1480
    $content = qq|[% USE KohaDates %]$content|;
1483
    $content = qq|[% USE KohaDates %]$content|;
1481
1484
(-)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