Bug 32442: (bug 28739 follow-up) Ensure txn is rollbacked

If the TT process call is returning false and so the croak is raised,
then the txn is not rollbacked and the txn is not commited either.

We need to ensure the txn will be correctly rollbacked.

Test plan:
1. Go to any notice and create some invalid Template Toolkit:

[% IF ( 1 == 1 %]
test
[% END %]

2. Save and continue

3. Logout of Koha and attempt to log back in
=> Without this patch you got
Transaction aborted: DBIx::Class::Storage::DBI::mysql::_exec_svp_release(): DBI Exception: DBD::mysql::db do failed: SAVEPOINT savepoint_4 does not exist at /kohadevbox/koha/Koha/Object.pm line 170
. Rollback failed: DBIx::Class::Storage::DBI::mysql::_exec_svp_rollback(): DBI Exception: DBD::mysql::db do failed: SAVEPOINT savepoint_3 does not exist at /kohadevbox/koha/Koha/Patron.pm line 363 at /kohadevbox/koha/Koha/Patron.pm line 363
 at /usr/share/perl5/DBIx/Class/Exception.pm line 77
=> With this patch applied the login works successfully

QA Note: The test is not testing that the txn is rolledback, I didn't
manage to test that.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-12-14 08:42:03 +01:00 committed by Tomas Cohen Arazi
parent 6d07a1cd8c
commit 494a63f9e8
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 8 additions and 3 deletions

View File

@ -23,7 +23,7 @@ use Carp qw( carp croak );
use Template;
use Module::Load::Conditional qw( can_load );
use Try::Tiny qw( catch try );
use Try::Tiny;
use C4::Members;
use C4::Log qw( logaction );
@ -1620,8 +1620,13 @@ sub _process_tt {
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;
my $processed = try {
$template->process( \$content, $tt_params, \$output );
}
finally {
$schema->txn_rollback;
};
croak "ERROR PROCESSING TEMPLATE: " . $template->error() unless $processed;
return $output;
}