From 5bc06b751d0ce35d58f3e5ea05642b279a494ddd 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 --- C4/Serials.pm | 69 ++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 51 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index c6151ea9c2..c77fd3e9e2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -46,6 +46,7 @@ use Koha::Serial; use Koha::SharedContent; use Koha::Subscription::Histories; use Koha::Subscriptions; +use Koha::TemplateUtils qw( process_tt ); # Define statuses use constant { @@ -1594,58 +1595,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.30.2