Bugzilla – Attachment 73552 Details for
Bug 19926
Add the Koha::Object->unblessed_all_relateds method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19926: Add the Koha::Object->unblessed_all_relateds method
Bug-19926-Add-the-KohaObject-unblessedallrelateds-.patch (text/plain), 3.55 KB, created by
Josef Moravec
on 2018-04-03 12:23:06 UTC
(
hide
)
Description:
Bug 19926: Add the Koha::Object->unblessed_all_relateds method
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2018-04-03 12:23:06 UTC
Size:
3.55 KB
patch
obsolete
>From dadded62f4c80eeb7d304cb41756022bf07e5945 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 8 Jan 2018 13:19:16 -0300 >Subject: [PATCH] Bug 19926: Add the Koha::Object->unblessed_all_relateds > method > >In order to refactor our legacy code step-by-step, we will need to >provide code with the exact same behaviors and then improve it. > >The same idea appears for the TT syntax for notices: we will want to >deprecate the existing syntax in order to support only one syntax. >Currently we fetch all the values from the related tables, without >knowing which are actually used. > >I am suggestion to introduce a Koha::Object->unblessed_all_relateds >method which will return a hash containing all the fields from the >related tables (with the problems we know: collision in column names). >It is the existing behavior of GetOverduesForPatron and GetPendingIssues >for instance, they are used to send notices and so we have to provide >all the data needed. > >See dependent bugs to understand the context and test this patch. > >Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Object.pm | 45 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 44 insertions(+), 1 deletion(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 7f36a7d..00e0c24 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -293,6 +293,37 @@ sub _numeric_column_type { > return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0; > } > >+=head3 $object->unblessed_all_relateds >+ >+my $everything_into_one_hashref = $object->unblessed_all_relateds >+ >+The unblessed method only retrieves column' values for the column of the object. >+In a *few* cases we want to retrieve the information of all the prefetched data. >+ >+=cut >+ >+sub unblessed_all_relateds { >+ my ($self) = @_; >+ >+ my %data; >+ my $related_resultsets = $self->_result->{related_resultsets} || {}; >+ my $rs = $self; >+ while ( $related_resultsets and %$related_resultsets ) { >+ my @relations = keys %{ $related_resultsets }; >+ if ( @relations ) { >+ my $relation = $relations[0]; >+ $rs = $rs->related_resultset($relation)->get_cache; >+ $rs = $rs->[0]; # Does it makes sense to have several values here? >+ my $object_class = Koha::Object::_get_object_class( $rs->result_class ); >+ my $koha_object = $object_class->_new_from_dbic( $rs ); >+ $related_resultsets = $rs->{related_resultsets}; >+ %data = ( %data, %{ $koha_object->unblessed } ); >+ } >+ } >+ %data = ( %data, %{ $self->unblessed } ); >+ return \%data; >+} >+ > =head3 $object->_result(); > > Returns the internal DBIC Row object >@@ -324,6 +355,17 @@ sub _columns { > return $self->{_columns}; > } > >+sub _get_object_class { >+ my ( $type ) = @_; >+ return unless $type; >+ >+ if( $type->can('koha_object_class') ) { >+ return $type->koha_object_class; >+ } >+ $type =~ s|Schema::Result::||; >+ return ${type}; >+} >+ > =head3 AUTOLOAD > > The autoload method is used only to get and set values for an objects properties. >@@ -348,7 +390,8 @@ sub AUTOLOAD { > } > } > >- my @known_methods = qw( is_changed id in_storage get_column discard_changes update ); >+ my @known_methods = qw( is_changed id in_storage get_column discard_changes update related_resultset ); >+ > Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; > > my $r = eval { $self->_result->$method(@_) }; >-- >2.1.4
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 19926
:
70327
|
70328
|
72764
|
72765
| 73552 |
73553