From 13980b57cda64982fa3db04e5e3856de983e36e8 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Wed, 22 Feb 2023 12:00:07 -0500 Subject: [PATCH] Bug 33043: Use process_tt in SIP modules Bug 33030 implements a new helper subroutine to standardize processing of Template Toolkit syntax outside slips and notices. We should use this subroutine in the various parts of the SIP server code where we are currently using Template::process directly. Test Plan: 1) Apply this patch 2) prove -r t/db_dependent/SIP --- C4/SIP/ILS/Item.pm | 24 +++--------------------- C4/SIP/ILS/Patron.pm | 20 +++----------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index 9c71e5dcb1..c949d3056d 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -11,7 +11,6 @@ use warnings; use C4::SIP::Sip qw(siplog); use Carp; -use Template; use C4::SIP::ILS::Transaction; use C4::SIP::Sip qw(add_field maybe_add); @@ -29,6 +28,7 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::Holds; use Koha::Items; use Koha::Patrons; +use Koha::TemplateUtils qw( process_tt ); =encoding UTF-8 @@ -183,13 +183,8 @@ sub hold_patron_name { my $borrowernumber = $self->hold_patron_id() or return q{}; if ($template) { - my $tt = Template->new(); - my $patron = Koha::Patrons->find($borrowernumber); - - my $output; - $tt->process( \$template, { patron => $patron }, \$output ); - return $output; + return process_tt( $template, { patron => $patron } ); } my $holder = Koha::Patrons->find( $borrowernumber ); @@ -480,21 +475,8 @@ sub format { my ( $self, $template ) = @_; if ($template) { - require Template; - - my $tt = Template->new(); - my $item = $self->{_object}; - - my $output; - eval { - $tt->process( \$template, { item => $item }, \$output ); - }; - if ( $@ ){ - siplog("LOG_DEBUG", "Error processing template: $template"); - return ""; - } - return $output; + return process_tt( $template, { item => $item } ); } } diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 88afb4ac00..235d869765 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -26,6 +26,7 @@ use C4::Auth qw(checkpw); use Koha::Items; use Koha::Libraries; use Koha::Patrons; +use Koha::TemplateUtils qw( process_tt ); our $kp; # koha patron @@ -253,22 +254,10 @@ sub format { my ( $self, $template ) = @_; if ($template) { - require Template; require Koha::Patrons; - my $tt = Template->new(); - my $patron = Koha::Patrons->find( $self->{borrowernumber} ); - - my $output; - eval { - $tt->process( \$template, { patron => $patron }, \$output ); - }; - if ( $@ ){ - siplog("LOG_DEBUG", "Error processing template: $template"); - return ""; - } - return $output; + return process_tt( $template, { patron => $patron } ); } } @@ -402,16 +391,13 @@ sub fine_items { my $av_field_template = $server ? $server->{account}->{av_field_template} : undef; $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"; - my $tt = Template->new(); - my @return_values; for ( my $i = $start; $i <= $end; $i++ ) { my $fee = $fees[$i]; next unless $fee; - my $output; - $tt->process( \$av_field_template, { accountline => $fee }, \$output ); + my $output = process_tt( $av_field_template, { accountline => $fee } ); push( @return_values, { barcode => $output } ); } -- 2.30.2