From f3e60fb2a93285df04dda84f0ab7ea87b170889c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 27 May 2022 11:22:23 +0100 Subject: [PATCH] Bug 30848: Ensure we flush the cache as necessary --- Koha/ClassSource.pm | 35 ++++++++++++++++++++++++++++++++++- Koha/ItemType.pm | 36 ++++++++++++++++++++++++++++++++++++ Koha/Library.pm | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/Koha/ClassSource.pm b/Koha/ClassSource.pm index 3b192ee124..0bd83b6296 100644 --- a/Koha/ClassSource.pm +++ b/Koha/ClassSource.pm @@ -17,7 +17,8 @@ package Koha::ClassSource; use Modern::Perl; - +use Koha::BiblioFrameworks; +use Koha::Caches; use Koha::Database; use base qw(Koha::Object); @@ -30,8 +31,40 @@ Koha::ClassSource - Koha Classfication Source Object class =head2 Class Methods +=head3 store + +ClassSource specific store to ensure relevant caches are flushed on change + =cut +sub store { + my ($self) = @_; + + my $flush = 0; + + if ( !$self->in_storage ) { + $flush = 1; + } + else { + my $self_from_storage = $self->get_from_storage; + $flush = 1 if ( $self_from_storage->description ne $self->description ); + } + + $self = $self->SUPER::store; + + if ($flush) { + my $cache = Koha::Caches->get_instance(); + my @frameworks = + Koha::BiblioFrameworks->search()->get_column('frameworkcode'); + for my $frameworkcode (@frameworks) { + my $key = "MarcAVStructure-$frameworkcode"; + $cache->clear_from_cache($key); + } + } + + return $self; +} + =head3 _type Returns name of corresponding DBIC resultset diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 4b77433e8e..495b410d7b 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -20,6 +20,8 @@ use Modern::Perl; use C4::Koha qw( getitemtypeimagelocation ); use C4::Languages; +use Koha::BiblioFrameworks; +use Koha::Caches; use Koha::Database; use Koha::CirculationRules; use Koha::Localizations; @@ -36,6 +38,40 @@ Koha::ItemType - Koha Item type Object class =cut +=head3 store + +ItemType specific store to ensure relevant caches are flushed on change + +=cut + +sub store { + my ($self) = @_; + + my $flush = 0; + + if ( !$self->in_storage ) { + $flush = 1; + } + else { + my $self_from_storage = $self->get_from_storage; + $flush = 1 if ( $self_from_storage->description ne $self->description ); + } + + $self = $self->SUPER::store; + + if ($flush) { + my $cache = Koha::Caches->get_instance(); + my @frameworks = + Koha::BiblioFrameworks->search()->get_column('frameworkcode'); + for my $frameworkcode (@frameworks) { + my $key = "MarcAVStructure-$frameworkcode"; + $cache->clear_from_cache($key); + } + } + + return $self; +} + =head3 image_location =cut diff --git a/Koha/Library.pm b/Koha/Library.pm index 48e125529b..381237443a 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -22,6 +22,8 @@ use Modern::Perl; use C4::Context; +use Koha::BiblioFrameworks; +use Koha::Caches; use Koha::Database; use Koha::StockRotationStages; use Koha::SMTP::Servers; @@ -36,6 +38,40 @@ Koha::Library - Koha Library Object class =head2 Class methods +=head3 store + +Library specific store to ensure relevant caches are flushed on change + +=cut + +sub store { + my ($self) = @_; + + my $flush = 0; + + if ( !$self->in_storage ) { + $flush = 1; + } + else { + my $self_from_storage = $self->get_from_storage; + $flush = 1 if ( $self_from_storage->branchname ne $self->branchname ); + } + + $self = $self->SUPER::store; + + if ($flush) { + my $cache = Koha::Caches->get_instance(); + my @frameworks = + Koha::BiblioFrameworks->search()->get_column('frameworkcode'); + for my $frameworkcode (@frameworks) { + my $key = "MarcAVStructure-$frameworkcode"; + $cache->clear_from_cache($key); + } + } + + return $self; +} + =head3 stockrotationstages my $stages = Koha::Library->stockrotationstages; -- 2.20.1