Bug 25723: Update cache flushing calls
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 17 Jun 2020 12:18:24 +0000 (13:18 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 20 Jul 2020 15:45:31 +0000 (17:45 +0200)
This patch updates the previous single_holidays and exeption_holidays
cache flushing calls to match the new cache key structure of the updated
routines.

Signed-off-by: Emma Perks <Emma.Perks2@uhb.nhs.uk>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Calendar.pm
t/Calendar.t
t/db_dependent/Circulation.t
t/db_dependent/Circulation/CalcDateDue.t
tools/newHolidays.pl

index 76c498f..7b94537 100644 (file)
@@ -277,8 +277,8 @@ sub insert_single_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 
@@ -322,8 +322,8 @@ sub insert_exception_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -423,8 +423,8 @@ UPDATE special_holidays SET title = ?, description = ?
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -466,8 +466,8 @@ UPDATE special_holidays SET title = ?, description = ?
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -547,8 +547,8 @@ sub delete_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -578,8 +578,8 @@ sub delete_holiday_range {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
 }
 
@@ -632,8 +632,8 @@ sub delete_exception_holiday_range {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 }
 
 =head2 isHoliday
index b3dc02f..8657bc4 100755 (executable)
@@ -77,8 +77,8 @@ fixtures_ok [
 ], "add fixtures";
 
 my $cache = Koha::Caches->get_instance();
-$cache->clear_from_cache( 'single_holidays' ) ;
-$cache->clear_from_cache( 'exception_holidays' ) ;
+$cache->clear_from_cache('MPL_holidays');
+$cache->clear_from_cache('CPL_holidays');
 
 # 'MPL' branch is arbitrary, is not used at all but is needed for initialization
 my $cal = Koha::Calendar->new( branchcode => 'MPL' );
@@ -310,6 +310,6 @@ subtest 'days_mode parameter' => sub {
 };
 
 END {
-    $cache->clear_from_cache( 'single_holidays' ) ;
-    $cache->clear_from_cache( 'exception_holidays' ) ;
+    $cache->clear_from_cache('MPL_holidays');
+    $cache->clear_from_cache('CPL_holidays');
 };
index 0c351d3..bd0b9a2 100755 (executable)
@@ -110,7 +110,11 @@ $mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
 my $cache = Koha::Caches->get_instance();
 $dbh->do(q|DELETE FROM special_holidays|);
 $dbh->do(q|DELETE FROM repeatable_holidays|);
-$cache->clear_from_cache('single_holidays');
+my $branches = Koha::Libraries->search();
+for my $branch ( $branches->next ) {
+    my $key = $branch->branchcode . "_holidays";
+    $cache->clear_from_cache($key);
+}
 
 # Start with a clean slate
 $dbh->do('DELETE FROM issues');
@@ -4060,4 +4064,8 @@ subtest 'Filling a hold should cancel existing transfer' => sub {
 
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
-$cache->clear_from_cache('single_holidays');
+$branches = Koha::Libraries->search();
+for my $branch ( $branches->next ) {
+    my $key = $branch->branchcode . "_holidays";
+    $cache->clear_from_cache($key);
+}
index 4c0999e..8085dbd 100644 (file)
@@ -43,8 +43,9 @@ Koha::CirculationRules->set_rules(
 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
 t::lib::Mocks::mock_preference('useDaysMode', 'Days');
 
-my $cache           = Koha::Caches->get_instance();
-$cache->clear_from_cache('single_holidays');
+my $cache = Koha::Caches->get_instance();
+my $key   = $branchcode . "_holidays";
+$cache->clear_from_cache($key);
 
 my $dateexpiry = '2013-01-01';
 
@@ -302,6 +303,5 @@ $calendar->delete_holiday(
     weekday => 6
 );
 
-
-$cache->clear_from_cache('single_holidays');
+$cache->clear_from_cache($key);
 $schema->storage->txn_rollback;
index f13e524..f7a1929 100755 (executable)
@@ -143,7 +143,4 @@ sub add_holiday {
             }
         }
     }
-    # we updated the single_holidays table, so wipe its cache
-    my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
 }