Bug 42310: (QA follow-up) Refresh in-process closure state on add/delete_weekly_closure and add/delete_repeating_closure
add_weekly_closure/delete_weekly_closure and add_repeating_closure/
delete_repeating_closure returned $self without refreshing
$self->{weekly_closed_days}/{day_month_closed_days}, so a calendar object
would keep reporting the pre-change state to is_holiday (and everything
built on it - days_forward, next_open_days, etc.) until it was
re-instantiated. This is distinct from the _holidays Koha::Caches entry,
which single/exception closures already flush correctly on store/delete.
Call _init to rebuild both structures from the database after each
add/delete, so the same object reflects the change immediately.
Test plan:
1) prove t/db_dependent/Koha/Library/Calendar.t t/db_dependent/Calendar.t
t/db_dependent/Holidays.t t/db_dependent/HoldsQueue.t
t/db_dependent/Holds/WaitingReserves.t t/db_dependent/Koha/CurbsidePickups.t
t/db_dependent/Reserves/CancelExpiredReserves.t
t/db_dependent/api/v1/libraries.t
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
004fe4de21
commit
3ef756f5a0
|
|
@ -426,12 +426,18 @@ sub clear_weekly_closed_days {
|
|||
|
||||
sub add_weekly_closure {
|
||||
my ( $self, $params ) = @_;
|
||||
return Koha::Library::Calendar::WeeklyClosure->new( { library_id => $self->{branchcode}, %$params } )->store;
|
||||
my $closure =
|
||||
Koha::Library::Calendar::WeeklyClosure->new( { library_id => $self->{branchcode}, %$params } )->store;
|
||||
$self->_init;
|
||||
return $closure;
|
||||
}
|
||||
|
||||
sub add_repeating_closure {
|
||||
my ( $self, $params ) = @_;
|
||||
return Koha::Library::Calendar::RepeatingClosure->new( { library_id => $self->{branchcode}, %$params } )->store;
|
||||
my $closure =
|
||||
Koha::Library::Calendar::RepeatingClosure->new( { library_id => $self->{branchcode}, %$params } )->store;
|
||||
$self->_init;
|
||||
return $closure;
|
||||
}
|
||||
|
||||
sub add_single_closure {
|
||||
|
|
@ -450,7 +456,10 @@ sub delete_weekly_closure {
|
|||
{ library_id => $self->{branchcode}, weekday => $params->{weekday} },
|
||||
{ rows => 1 }
|
||||
)->single;
|
||||
$row->delete if $row;
|
||||
if ($row) {
|
||||
$row->delete;
|
||||
$self->_init;
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
@ -460,7 +469,10 @@ sub delete_repeating_closure {
|
|||
{ library_id => $self->{branchcode}, day => $params->{day}, month => $params->{month} },
|
||||
{ rows => 1 }
|
||||
)->single;
|
||||
$row->delete if $row;
|
||||
if ($row) {
|
||||
$row->delete;
|
||||
$self->_init;
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
@ -566,11 +578,12 @@ sub copy_to {
|
|||
}
|
||||
|
||||
my $exceptions =
|
||||
Koha::Library::Calendar::Exceptions->search( { library_id => $self->{branchcode}, date => { '>=' => $today } } );
|
||||
Koha::Library::Calendar::Exceptions->search(
|
||||
{ library_id => $self->{branchcode}, date => { '>=' => $today } } );
|
||||
while ( my $row = $exceptions->next ) {
|
||||
next
|
||||
if Koha::Library::Calendar::Exceptions->search( { library_id => $target_branchcode, date => $row->date } )
|
||||
->count;
|
||||
if Koha::Library::Calendar::Exceptions->search(
|
||||
{ library_id => $target_branchcode, date => $row->date } )->count;
|
||||
Koha::Library::Calendar::Exception->new(
|
||||
{
|
||||
library_id => $target_branchcode, date => $row->date,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 8;
|
||||
use Test::More tests => 9;
|
||||
use Test::Exception;
|
||||
use Test::NoWarnings;
|
||||
|
||||
|
|
@ -371,3 +371,35 @@ subtest 'SingleClosure/Exception store() rejects an in-place date change' => sub
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'delete_weekly_closure/delete_repeating_closure refresh in-process state' => sub {
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
my $calendar = Koha::Library::Calendar->new( branchcode => $library->branchcode );
|
||||
|
||||
my $sunday = dt_from_string('2027-08-08'); # a Sunday
|
||||
$calendar->add_weekly_closure( { weekday => 0, title => '', description => '' } );
|
||||
is( $calendar->is_holiday($sunday), 1, 'Sunday is closed after add_weekly_closure' );
|
||||
|
||||
$calendar->delete_weekly_closure( { weekday => 0 } );
|
||||
is(
|
||||
$calendar->is_holiday($sunday), 0,
|
||||
'Sunday is open on the SAME object immediately after delete_weekly_closure, without re-instantiating'
|
||||
);
|
||||
|
||||
my $christmas = dt_from_string('2027-12-25');
|
||||
$calendar->add_repeating_closure( { day => 25, month => 12, title => '', description => '' } );
|
||||
is( $calendar->is_holiday($christmas), 1, 'Christmas is closed after add_repeating_closure' );
|
||||
|
||||
$calendar->delete_repeating_closure( { day => 25, month => 12 } );
|
||||
is(
|
||||
$calendar->is_holiday($christmas), 0,
|
||||
'Christmas is open on the SAME object immediately after delete_repeating_closure, without re-instantiating'
|
||||
);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue