From 47fa162822d3ac693e244f1a6f9d0045570a65f1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 23 Jul 2021 08:09:04 -0400 Subject: [PATCH] Bug 28739: Ignore store, update and delete when called from Template Toolkit --- Koha/Object.pm | 8 ++++++++ Koha/Objects.pm | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index 08602da67f..8e5892ceec 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -125,6 +125,8 @@ Returns: sub store { my ($self) = @_; + return $self if ( ( caller() )[0] eq 'Template::Document' ); + my $columns_info = $self->_result->result_source->columns_info; # Handle not null and default values for integers and dates @@ -230,6 +232,8 @@ Returns: sub delete { my ($self) = @_; + return $self if ( ( caller() )[0] eq 'Template::Document' ); + my $deleted = $self->_result()->delete; if ( ref $deleted ) { my $object_class = Koha::Object::_get_object_class( $self->_result->result_class ); @@ -826,6 +830,10 @@ sub AUTOLOAD { ) unless grep { $_ eq $method } @known_methods; + if ( $method eq 'update' ) { + return $self if ( ( caller() )[0] eq 'Template::Document' ); + } + my $r = eval { $self->_result->$method(@_) }; if ( $@ ) { Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ ); diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 3ee0a55742..83abef97cd 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -589,7 +589,6 @@ sub AUTOLOAD { my $method = our $AUTOLOAD; $method =~ s/.*:://; - unless ( grep { $_ eq $method } @known_methods ) { my $class = ref($self) ? ref($self) : $self; Koha::Exceptions::Object::MethodNotCoveredByTests->throw( @@ -598,6 +597,10 @@ sub AUTOLOAD { ); } + if ( $method eq 'update' || $method eq 'delete' ) { + return $self if ( ( caller() )[0] eq 'Template::Document' ); + } + my $r = eval { $self->_resultset->$method(@params) }; if ( $@ ) { carp "No method $method found for " . ref($self) . " " . $@; -- 2.30.1 (Apple Git-130)