diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 81b766592f..5fc8cc318c 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -445,27 +445,41 @@ sub add_exception { sub delete_weekly_closure { my ( $self, $params ) = @_; - Koha::Calendar::WeeklyClosures->search( { library_id => $self->{branchcode}, weekday => $params->{weekday} } ) - ->delete; + my $row = Koha::Calendar::WeeklyClosures->search( + { library_id => $self->{branchcode}, weekday => $params->{weekday} }, + { rows => 1 } + )->single; + $row->delete if $row; return $self; } sub delete_repeating_closure { my ( $self, $params ) = @_; - Koha::Calendar::RepeatingClosures->search( - { library_id => $self->{branchcode}, day => $params->{day}, month => $params->{month} } )->delete; + my $row = Koha::Calendar::RepeatingClosures->search( + { library_id => $self->{branchcode}, day => $params->{day}, month => $params->{month} }, + { rows => 1 } + )->single; + $row->delete if $row; return $self; } sub delete_single_closure { my ( $self, $params ) = @_; - Koha::Calendar::SingleClosures->search( { library_id => $self->{branchcode}, date => $params->{date} } )->delete; + my $row = Koha::Calendar::SingleClosures->search( + { library_id => $self->{branchcode}, date => $params->{date} }, + { rows => 1 } + )->single; + $row->delete if $row; return $self; } sub delete_exception { my ( $self, $params ) = @_; - Koha::Calendar::Exceptions->search( { library_id => $self->{branchcode}, date => $params->{date} } )->delete; + my $row = Koha::Calendar::Exceptions->search( + { library_id => $self->{branchcode}, date => $params->{date} }, + { rows => 1 } + )->single; + $row->delete if $row; return $self; } diff --git a/t/db_dependent/Koha/Calendar.t b/t/db_dependent/Koha/Calendar.t index dc91f06fec..7ab73c8efd 100755 --- a/t/db_dependent/Koha/Calendar.t +++ b/t/db_dependent/Koha/Calendar.t @@ -19,10 +19,11 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; use Test::NoWarnings; +use Koha::Caches; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Calendar::WeeklyClosures; @@ -227,3 +228,31 @@ subtest 'CRUD methods' => sub { $schema->storage->txn_rollback; }; + +subtest 'delete_*_closure clears _holidays cache' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $branchcode = $library->branchcode; + my $cache_key = $branchcode . '_holidays'; + my $cache = Koha::Caches->get_instance; + + my $calendar = Koha::Calendar->new( branchcode => $branchcode ); + + $calendar->add_single_closure( { date => '2027-07-04', title => 'Independence', description => '' } ); + $calendar->is_holiday( dt_from_string('2027-07-04') ); # warm cache + ok( defined $cache->get_from_cache($cache_key), 'Cache warm after is_holiday (single)' ); + $calendar->delete_single_closure( { date => '2027-07-04' } ); + is( $cache->get_from_cache($cache_key), undef, 'Cache cleared after delete_single_closure' ); + + $calendar->add_exception( { date => '2027-07-05', title => 'Special open', description => '' } ); + $calendar->is_holiday( dt_from_string('2027-07-05') ); # warm cache + ok( defined $cache->get_from_cache($cache_key), 'Cache warm after is_holiday (exception)' ); + $calendar->delete_exception( { date => '2027-07-05' } ); + is( $cache->get_from_cache($cache_key), undef, 'Cache cleared after delete_exception' ); + + $schema->storage->txn_rollback; +};