Bug 28739: Execute the letter processing inside a transaction

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2021-10-13 14:46:08 +02:00 committed by Tomas Cohen Arazi
parent 3a154af7f1
commit 7ffc698c9b
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 25 additions and 1 deletions

View File

@ -1609,7 +1609,10 @@ sub _process_tt {
$content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|;
my $output;
my $schema = Koha::Database->new->schema;
$schema->txn_begin;
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
$schema->txn_rollback;
return $output;
}

View File

@ -19,7 +19,7 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 29;
use Test::More tests => 30;
use Test::MockModule;
use Test::Warn;
@ -1188,6 +1188,27 @@ EOF
is( $letter->{content}, $expected_content );
};
subtest 'Execute TT process in a DB transaction' => sub {
plan tests => 2;
my $code = 'TEST_TXN';
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $template = <<EOF;
=[% branch.branchcode %]=
[%~ branch.delete ~%]
EOF
reset_template({ template => $template, code => $code, module => 'test' });
my $letter = GetPreparedLetter(
module => 'test',
letter_code => $code,
tables => {
branches => $library->branchcode,
}
);
my $branchcode = $library->branchcode;
like($letter->{content}, qr{=$branchcode=}, 'content generated with the library');
is( ref($library->get_from_storage), 'Koha::Library', 'calling ->delete on the object has not been comitted');
};
sub reset_template {
my ( $params ) = @_;
my $template = $params->{template};