From e2e4b894675a24688058c930d50ed5928292cdbe Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Wed, 22 Feb 2023 11:47:12 -0500 Subject: [PATCH] Bug 33041: Use process_tt in C4::Serial::NewIssue Bug 33030 implements a new helper subroutine to standardize processing of Template Toolkit syntax outside slips and notices. We should use this subroutine in C4::Serial::NewIssue Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Items.t Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Serials.pm | 69 ++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 51 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 40a4d1acd7..b01172dc10 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -47,6 +47,7 @@ use Koha::SharedContent; use Koha::Subscription::Histories; use Koha::Subscriptions; use Koha::Suggestions; +use Koha::TemplateUtils qw( process_tt ); # Define statuses use constant { @@ -1595,58 +1596,24 @@ sub NewIssue { my $subscription = Koha::Subscriptions->find( $subscriptionid ); if ( my $template = $subscription->published_on_template ) { - # If we detect a TT opening tag, run string through Template Toolkit Processor - if ( index( $template, '[%' ) != -1 ) { # Much faster than regex - my $use_template_cache = C4::Context->config('template_cache_dir') - && defined $ENV{GATEWAY_INTERFACE}; - - my $tt = Template->new( - { - EVAL_PERL => 1, - ABSOLUTE => 1, - PLUGIN_BASE => 'Koha::Template::Plugin', - COMPILE_EXT => $use_template_cache ? '.ttc' : '', - COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', - FILTERS => {}, - ENCODING => 'UTF-8', - } - ) or die Template->error(); - - my $schema = Koha::Database->new->schema; - - $schema->txn_begin; - try { - my $text; - $tt->process( - \$template, - { - subscription => $subscription, - serialseq => $serialseq, - serialseq_x => $subscription->lastvalue1(), - serialseq_y => $subscription->lastvalue2(), - serialseq_z => $subscription->lastvalue3(), - subscriptionid => $subscriptionid, - biblionumber => $biblionumber, - status => $status, - planneddate => $planneddate, - publisheddate => $publisheddate, - publisheddatetext => $publisheddatetext, - notes => $notes, - routingnotes => $routingnotes, - }, - \$text - ); - $publisheddatetext = $text; - } - catch { - croak "ERROR PROCESSING TEMPLATE: $_ :: " . $template->error(); + $publisheddatetext = process_tt( + $template, + { + subscription => $subscription, + serialseq => $serialseq, + serialseq_x => $subscription->lastvalue1(), + serialseq_y => $subscription->lastvalue2(), + serialseq_z => $subscription->lastvalue3(), + subscriptionid => $subscriptionid, + biblionumber => $biblionumber, + status => $status, + planneddate => $planneddate, + publisheddate => $publisheddate, + publisheddatetext => $publisheddatetext, + notes => $notes, + routingnotes => $routingnotes, } - finally { - $schema->txn_rollback; - }; - } else { - $publisheddatetext = $template; - } + ); } my $serial = Koha::Serial->new( -- 2.39.5