Bugzilla – Attachment 102297 Details for
Bug 25044
No need to define koha_object[s]_class for standard object class names
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25044: Remove the need to define koha_object[s]_class for standard object class names
Bug-25044-Remove-the-need-to-define-kohaobjectscla.patch (text/plain), 3.72 KB, created by
Jonathan Druart
on 2020-04-02 14:04:41 UTC
(
hide
)
Description:
Bug 25044: Remove the need to define koha_object[s]_class for standard object class names
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-04-02 14:04:41 UTC
Size:
3.72 KB
patch
obsolete
>From 8b09a76e163a07bdd26ab5f895f1b93d49fe7a1f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 2 Apr 2020 16:03:17 +0200 >Subject: [PATCH] Bug 25044: Remove the need to define koha_object[s]_class for > standard object class names > >In Koha::Object[s]->prefetch_whitelist, there is a call to the koha_object[s]_class DBIC resultset class. We should not, otherwise those 2 methods will have to be defined all the time, even when we can guess it easily. > >Koha::Item <> Schema::Result::Item => standard >Koha::Acquisition::Order <> Schema::Result::Aqorder => non-standard > >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}; >} > >Test plan: > % prove t/db_dependent/Koha/Object.t t/db_dependent/Koha/Objects.t >should return green before and after this patch >--- > Koha/Object.pm | 2 +- > Koha/Objects.pm | 2 +- > t/db_dependent/Koha/Object.t | 10 ++++++++-- > t/db_dependent/Koha/Objects.t | 10 ++++++++-- > 4 files changed, 18 insertions(+), 6 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index fde0fa9917..44ef617824 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -436,7 +436,7 @@ sub prefetch_whitelist { > my $result_class = $relations->{$key}->{class}; > my $obj = $result_class->new; > try { >- $whitelist->{$key} = $obj->koha_object_class; >+ $whitelist->{$key} = Koha::Object::_get_object_class( $obj->result_class ); > } catch { > $whitelist->{$key} = undef; > } >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 9184a235a8..ea3054c07a 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -362,7 +362,7 @@ Returns a hash of prefetchable subs and the type it returns > sub prefetch_whitelist { > my ( $self ) = @_; > >- $self->{_singular_object} ||= $self->object_class->new(); >+ $self->{_singular_object} ||= $self->_get_object_class->new(); > > $self->{_singular_object}->prefetch_whitelist; > } >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 2d4413486d..c23f023cd4 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -796,7 +796,7 @@ subtest 'get_from_storage' => sub { > > subtest 'prefetch_whitelist() tests' => sub { > >- plan tests => 2; >+ plan tests => 3; > > $schema->storage->txn_begin; > >@@ -811,7 +811,13 @@ subtest 'prefetch_whitelist() tests' => sub { > is( > $prefetch_whitelist->{orders}, > 'Koha::Acquisition::Order', >- 'Guessed the object class correctly' >+ 'Guessed the non-standard object class correctly' >+ ); >+ >+ is( >+ $prefetch_whitelist->{items}, >+ 'Koha::Item', >+ 'Guessed the standard object class correctly' > ); > > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t >index 5bb663030f..c5ac1ba2b6 100644 >--- a/t/db_dependent/Koha/Objects.t >+++ b/t/db_dependent/Koha/Objects.t >@@ -773,7 +773,7 @@ subtest "from_api_mapping() tests" => sub { > > subtest 'prefetch_whitelist() tests' => sub { > >- plan tests => 2; >+ plan tests => 3; > > $schema->storage->txn_begin; > >@@ -788,7 +788,13 @@ subtest 'prefetch_whitelist() tests' => sub { > is( > $prefetch_whitelist->{orders}, > 'Koha::Acquisition::Order', >- 'Guessed the object class correctly' >+ 'Guessed the non-standard object class correctly' >+ ); >+ >+ is( >+ $prefetch_whitelist->{items}, >+ 'Koha::Item', >+ 'Guessed the standard object class correctly' > ); > > $schema->storage->txn_rollback; >-- >2.20.1
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 25044
:
102297
|
102298
|
102529
|
102774
|
102927