Bugzilla – Attachment 104088 Details for
Bug 23185
Koha::Objects supports passing through 'update' which means we can side step 'set' + 'store'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23185: Make Koha::Objects->update loop on the object set if needed
Bug-23185-Make-KohaObjects-update-loop-on-the-obje.patch (text/plain), 3.09 KB, created by
Martin Renvoize (ashimema)
on 2020-05-01 13:14:17 UTC
(
hide
)
Description:
Bug 23185: Make Koha::Objects->update loop on the object set if needed
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-05-01 13:14:17 UTC
Size:
3.09 KB
patch
obsolete
>From 6aac6f9b7001c8dbb2c3cb1d8c2bfc7d71db8e13 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 28 Apr 2020 17:14:41 +0200 >Subject: [PATCH] Bug 23185: Make Koha::Objects->update loop on the object set > if needed > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Exceptions/Object.pm | 4 ++++ > Koha/Object.pm | 3 ++- > Koha/Objects.pm | 32 ++++++++++++++++++++++++++++++-- > 3 files changed, 36 insertions(+), 3 deletions(-) > >diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm >index 488e5764ff..53bd44ca90 100644 >--- a/Koha/Exceptions/Object.pm >+++ b/Koha/Exceptions/Object.pm >@@ -55,6 +55,10 @@ use Exception::Class ( > description => 'Invalid data passed', > fields => ['type', 'property', 'value'], > }, >+ 'Koha::Exceptions::Object::NotInStorage' => { >+ isa => 'Koha::Exceptions::Object', >+ description => 'The object is not in storage yet', >+ }, > ); > > sub full_message { >diff --git a/Koha/Object.pm b/Koha/Object.pm >index 44ef617824..ed7cc4bdc9 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -208,7 +208,8 @@ A shortcut for set + store in one call. > > sub update { > my ($self, $values) = @_; >- return $self->set($values)->store(); >+ Koha::Exceptions::Object::NotInStorage->throw unless $self->in_storage; >+ $self->set($values)->store(); > } > > =head3 $object->delete(); >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index eb77c0e0e6..7512f2616f 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -194,6 +194,34 @@ sub delete { > return $self->_resultset->delete; > } > >+=head3 update >+ >+=cut >+ >+sub update { >+ my ($self, $params) = @_; >+ >+ my $no_triggers = delete $params->{no_triggers}; >+ >+ if ( >+ !$no_triggers >+ && ( Class::Inspector->function_exists( $self->object_class, 'update' ) >+ or Class::Inspector->function_exists( $self->object_class, 'store' ) ) >+ ) >+ { >+ my $objects_updated; >+ $self->_resultset->result_source->schema->txn_do( sub { >+ while ( my $o = $self->next ) { >+ $o->update($params); >+ $objects_updated++; >+ } >+ }); >+ return $objects_updated; >+ } >+ >+ return $self->_resultset->update($params); >+} >+ > =head3 single > > my $object = Koha::Objects->search({}, { rows => 1 })->single >@@ -474,14 +502,14 @@ The autoload method is used call DBIx::Class method on a resultset. > > Important: If you plan to use one of the DBIx::Class methods you must provide > relevant tests in t/db_dependent/Koha/Objects.t >-Currently count, is_paged, pager, update, result_class, single and slice are covered. >+Currently count, is_paged, pager, result_class, single and slice are covered. > > =cut > > sub AUTOLOAD { > my ( $self, @params ) = @_; > >- my @known_methods = qw( count is_paged pager update result_class single slice ); >+ my @known_methods = qw( count is_paged pager result_class single slice ); > my $method = our $AUTOLOAD; > $method =~ s/.*:://; > >-- >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 23185
:
103867
|
103868
|
103946
|
103947
|
104087
|
104088
|
104089
|
104232
|
104233
|
104234
|
104271
|
104272
|
104273
|
104276
|
104537
|
104538
|
104541