Bugzilla – Attachment 173902 Details for
Bug 30657
Make patron attributes available via Template Toolkit in notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30657: Try parent method first
Bug-30657-Try-parent-method-first.patch (text/plain), 4.07 KB, created by
Martin Renvoize (ashimema)
on 2024-11-04 09:25:34 UTC
(
hide
)
Description:
Bug 30657: Try parent method first
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-11-04 09:25:34 UTC
Size:
4.07 KB
patch
obsolete
>From 937717fb8767faa45b2fb5ea8e879be43615c12d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 4 Nov 2024 09:23:47 +0000 >Subject: [PATCH] Bug 30657: Try parent method first > >This patch adds a try/catch inside the Koha::Patron AUTOLOAD to try and >find the method on the parent, including it's AUTOLOAD, prior to running >the local AUTOLOAD code to generate attribute accessors and then use the >called method. >--- > Koha/Patron.pm | 75 +++++++++++++++++++++++++++----------------------- > 1 file changed, 40 insertions(+), 35 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 3e56e8911da..d6fb91e42ad 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -130,44 +130,49 @@ sub AUTOLOAD { > my $self = shift(@args); > my $name = $AUTOLOAD; > $name =~ s/.*:://; # Remove package name >- my $found = 0; >- >- # Fetch attributes dynamically >- my $attribute_types = Koha::Patron::Attribute::Types->search(); >- while ( my $attr = $attribute_types->next ) { >- my $code = $attr->code; >- $found = 1 if ( $code eq $name ); >- >- # Dynamically create accessor method >- no strict 'refs'; >- if ( !defined *{ ref($self) . "::$code" }{CODE} ) { >- if ( $attr->repeatable ) { >- *{ ref($self) . "::$code" } = sub { >- my ($self) = @_; >- return $self->_result->get_column($code) if $self->_result->has_column($code); >- my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); >- my $values = []; >- while ( my $attribute = $attributes->next ) { >- push @$values, $attribute->attribute; >- } >- return $values; >- }; >- } else { >- *{ ref($self) . "::$code" } = sub { >- my ($self) = @_; >- return $self->_result->get_column($code) if $self->_result->has_column($code); >- my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; >- return $attribute ? $attribute->attribute : undef; >- }; >+ >+ return try { >+ my $wt = 'SUPER::' . $name; >+ $self->$wt(@args); >+ } catch { >+ >+ # Fetch attributes dynamically >+ my $found = 0; >+ my $attribute_types = Koha::Patron::Attribute::Types->search(); >+ while ( my $attr = $attribute_types->next ) { >+ my $code = $attr->code; >+ $found = 1 if ( $code eq $name ); >+ >+ # Dynamically create accessor method >+ no strict 'refs'; >+ if ( !defined *{ ref($self) . "::$code" }{CODE} ) { >+ if ( $attr->repeatable ) { >+ *{ ref($self) . "::$code" } = sub { >+ my ($self) = @_; >+ return $self->_result->get_column($code) if $self->_result->has_column($code); >+ my $attributes = $self->_result->borrower_attributes->search( { code => $code } ); >+ my $values = []; >+ while ( my $attribute = $attributes->next ) { >+ push @$values, $attribute->attribute; >+ } >+ return $values; >+ }; >+ } else { >+ *{ ref($self) . "::$code" } = sub { >+ my ($self) = @_; >+ return $self->_result->get_column($code) if $self->_result->has_column($code); >+ my $attribute = $self->_result->borrower_attributes->search( { code => $code } )->first; >+ return $attribute ? $attribute->attribute : undef; >+ }; >+ } > } > } >- } > >- if ($found) { >- return $self->$name(); >- } else { >- my $wt = 'SUPER::' . $name; >- return $self->$wt(@args); >+ if ($found) { >+ return $self->$name(); >+ } else { >+ $@; >+ } > } > } > >-- >2.47.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30657
:
169049
|
169050
|
169056
|
169057
|
173817
|
173818
|
173819
|
173901
|
173902
|
173910
|
173911
|
173912
|
173913
|
173914