|
Lines 51-66
AuthorisedValue specific store to ensure relevant caches are flushed on change
Link Here
|
| 51 |
=cut |
51 |
=cut |
| 52 |
|
52 |
|
| 53 |
sub store { |
53 |
sub store { |
| 54 |
my ($self) = @_; |
54 |
my ( $self, $branches ) = @_; |
| 55 |
|
55 |
|
| 56 |
my $flush = 0; |
56 |
my $flush = 0; |
| 57 |
|
57 |
|
| 58 |
my $new_authorized_value = !$self->in_storage; |
58 |
my $new_authorized_value = !$self->in_storage; |
| 59 |
|
59 |
|
|
|
60 |
my $original = { |
| 61 |
authorised_value => undef, |
| 62 |
id => undef, |
| 63 |
category => undef, |
| 64 |
library_limits => undef, |
| 65 |
lib => undef, |
| 66 |
lib_opac => undef, |
| 67 |
imageurl => undef, |
| 68 |
}; |
| 69 |
|
| 60 |
if ( !$self->in_storage ) { |
70 |
if ( !$self->in_storage ) { |
| 61 |
$flush = 1; |
71 |
$flush = 1; |
| 62 |
} |
72 |
} else { |
| 63 |
else { |
73 |
my $original_av = Koha::AuthorisedValues->find( $self->id ); |
|
|
74 |
|
| 75 |
# Fetch current library limits using get_library_limits method |
| 76 |
my $libraries = $original_av->get_library_limits(); |
| 77 |
|
| 78 |
# Extract branch codes |
| 79 |
my @original_library_limits; |
| 80 |
if ($libraries) { |
| 81 |
while ( my $library = $libraries->next ) { |
| 82 |
push @original_library_limits, $library->branchcode; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
$original = { |
| 87 |
authorised_value => $original_av->authorised_value, |
| 88 |
id => $original_av->id, |
| 89 |
category => $original_av->category, |
| 90 |
library_limits => \@original_library_limits, |
| 91 |
lib => $original_av->lib, |
| 92 |
lib_opac => $original_av->lib_opac, |
| 93 |
imageurl => $original_av->imageurl |
| 94 |
}; |
| 95 |
|
| 64 |
my %updated_columns = $self->_result->get_dirty_columns; |
96 |
my %updated_columns = $self->_result->get_dirty_columns; |
| 65 |
|
97 |
|
| 66 |
if ( exists $updated_columns{lib} |
98 |
if ( exists $updated_columns{lib} |
|
Lines 75-86
sub store {
Link Here
|
| 75 |
$self = $self->SUPER::store; |
107 |
$self = $self->SUPER::store; |
| 76 |
|
108 |
|
| 77 |
if ( C4::Context->preference("AuthorizedValuesLog") ) { |
109 |
if ( C4::Context->preference("AuthorizedValuesLog") ) { |
|
|
110 |
$self->replace_library_limits($branches); |
| 78 |
my $action = $new_authorized_value ? 'CREATE' : 'MODIFY'; |
111 |
my $action = $new_authorized_value ? 'CREATE' : 'MODIFY'; |
| 79 |
logaction( 'AUTHORIZEDVALUE', $action, $self->id, $self ); |
112 |
|
|
|
113 |
logaction( |
| 114 |
'AUTHORIZEDVALUE', |
| 115 |
$action, |
| 116 |
$self->id, |
| 117 |
{ |
| 118 |
authorised_value => $self->authorised_value, |
| 119 |
id => $self->id, |
| 120 |
category => $self->category, |
| 121 |
library_limits => $branches, |
| 122 |
lib => $self->lib, |
| 123 |
lib_opac => $self->lib_opac, |
| 124 |
imageurl => $self->imageurl |
| 125 |
}, |
| 126 |
undef, |
| 127 |
$original |
| 128 |
); |
| 80 |
} |
129 |
} |
| 81 |
|
130 |
|
| 82 |
if ($flush) { |
131 |
if ($flush) { |
| 83 |
my $key = "AV_descriptions:".$self->category; |
132 |
my $key = "AV_descriptions:" . $self->category; |
| 84 |
$cache->clear_from_cache($key); |
133 |
$cache->clear_from_cache($key); |
| 85 |
} |
134 |
} |
| 86 |
|
135 |
|