Bugzilla – Attachment 169027 Details for
Bug 35630
Add ability to log changes to authorized values
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35630: Handle library limits inside the store function
Bug-35630-Handle-library-limits-inside-the-store-f.patch (text/plain), 4.81 KB, created by
Sam Lau
on 2024-07-15 19:10:26 UTC
(
hide
)
Description:
Bug 35630: Handle library limits inside the store function
Filename:
MIME Type:
Creator:
Sam Lau
Created:
2024-07-15 19:10:26 UTC
Size:
4.81 KB
patch
obsolete
>From 3020b80c552c9cf46423c5367ab625c6ea7f4648 Mon Sep 17 00:00:00 2001 >From: Sam Lau <samalau@gmail.com> >Date: Mon, 15 Jul 2024 19:05:43 +0000 >Subject: [PATCH] Bug 35630: Handle library limits inside the store function > >This patch makes use of the diff action_logs as mentioned in comment 9. Furthermore, to fix the issue of calling store twice when creating a new AV, the "replace_library_limits" call has been moved inside to the store function. > >Use test plan from previous patch to test. >--- > C4/Log.pm | 2 ++ > Koha/AuthorisedValue.pm | 59 ++++++++++++++++++++++++++++++++++---- > admin/authorised_values.pl | 7 ++--- > 3 files changed, 58 insertions(+), 10 deletions(-) > >diff --git a/C4/Log.pm b/C4/Log.pm >index d7ad162c4c..0909b029b0 100644 >--- a/C4/Log.pm >+++ b/C4/Log.pm >@@ -124,6 +124,8 @@ sub logaction { > $diff //= encode_json( diff( $original, $updated, noU => 1 ) ) > if $original && ref $updated eq 'HASH'; > >+ $infos = Data::Dumper::Dumper( $infos ) if ref $infos; >+ > Koha::ActionLog->new( > { > timestamp => \'NOW()', >diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm >index d096f17a7f..c20e9c57fd 100644 >--- a/Koha/AuthorisedValue.pm >+++ b/Koha/AuthorisedValue.pm >@@ -51,16 +51,48 @@ AuthorisedValue specific store to ensure relevant caches are flushed on change > =cut > > sub store { >- my ($self) = @_; >+ my ( $self, $branches ) = @_; > > my $flush = 0; > > my $new_authorized_value = !$self->in_storage; > >+ my $original = { >+ authorised_value => undef, >+ id => undef, >+ category => undef, >+ library_limits => undef, >+ lib => undef, >+ lib_opac => undef, >+ imageurl => undef, >+ }; >+ > if ( !$self->in_storage ) { > $flush = 1; >- } >- else { >+ } else { >+ my $original_av = Koha::AuthorisedValues->find( $self->id ); >+ >+ # Fetch current library limits using get_library_limits method >+ my $libraries = $original_av->get_library_limits(); >+ >+ # Extract branch codes >+ my @original_library_limits; >+ if ($libraries) { >+ while ( my $library = $libraries->next ) { >+ push @original_library_limits, $library->branchcode; >+ } >+ } >+ >+ $original = { >+ authorised_value => $original_av->authorised_value, >+ id => $original_av->id, >+ category => $original_av->category, >+ library_limits => \@original_library_limits, >+ lib => $original_av->lib, >+ lib_opac => $original_av->lib_opac, >+ imageurl => $original_av->imageurl >+ }; >+ > my %updated_columns = $self->_result->get_dirty_columns; > > if ( exists $updated_columns{lib} >@@ -75,12 +107,29 @@ sub store { > $self = $self->SUPER::store; > > if ( C4::Context->preference("AuthorizedValuesLog") ) { >+ $self->replace_library_limits($branches); > my $action = $new_authorized_value ? 'CREATE' : 'MODIFY'; >- logaction( 'AUTHORIZEDVALUE', $action, $self->id, $self ); >+ >+ logaction( >+ 'AUTHORIZEDVALUE', >+ $action, >+ $self->id, >+ { >+ authorised_value => $self->authorised_value, >+ id => $self->id, >+ category => $self->category, >+ library_limits => $branches, >+ lib => $self->lib, >+ lib_opac => $self->lib_opac, >+ imageurl => $self->imageurl >+ }, >+ undef, >+ $original >+ ); > } > > if ($flush) { >- my $key = "AV_descriptions:".$self->category; >+ my $key = "AV_descriptions:" . $self->category; > $cache->clear_from_cache($key); > } > >diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl >index 7809a24cdd..fbc4ddc5b0 100755 >--- a/admin/authorised_values.pl >+++ b/admin/authorised_values.pl >@@ -119,8 +119,7 @@ if ( $op eq 'add_form' or $op eq 'edit_form' ) { > $av->authorised_value( $new_authorised_value ); > $av->imageurl( $imageurl ); > eval{ >- $av->store; >- $av->replace_library_limits( \@branches ); >+ $av->store( \@branches ); > }; > if ( $@ ) { > push @messages, {type => 'error', code => 'error_on_update' }; >@@ -138,9 +137,7 @@ if ( $op eq 'add_form' or $op eq 'edit_form' ) { > lib_opac => scalar $input->param('lib_opac') || undef, > imageurl => $imageurl, > } >- ); >- $av->replace_library_limits( \@branches ); >- $av->store; >+ )->store( \@branches ); > }; > > if ( $@ ) { >-- >2.39.2
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 35630
:
168747
|
168748
|
169027
|
169044
|
169045
|
169046
|
172629