From 42df0021f62d34b91de3eef5fc40b44ac96e17bc 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 | 18 +++--------------- 2 files changed, 6 insertions(+), 36 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..1bdf3897e3 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 } ); } } @@ -410,8 +399,7 @@ sub fine_items { 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