From 5e49827a1ad1c997354a4c059f6a18d5469611f7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 23 Apr 2025 20:03:27 +0000 Subject: [PATCH] Bug 39717: Use numeric comparison for stock rotation stages To test: 1 - Enable SotckRotation http://localhost:8081/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=StockRotation 2 - Browse to "Cataloging -> StockRotation" 3 - 'New rota' - fill out the form and save 4 - Manage->stages 5 - Add many stages, more than 10 at least 6 - Try to move a stage form the bottom to position 3 7 - Note message above list: Saving changes... Error: Bad Request 8 - Apply patch, restart_all 9 - Attempt to move stages, try many combinations 10 - Success! Signed-off-by: Nick Clemens --- Koha/StockRotationStage.pm | 2 +- t/db_dependent/StockRotationStages.t | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Koha/StockRotationStage.pm b/Koha/StockRotationStage.pm index aed3d2b40c8..deb06880975 100644 --- a/Koha/StockRotationStage.pm +++ b/Koha/StockRotationStage.pm @@ -255,7 +255,7 @@ Koha::Object Wrapper around DBIx::Class::Ordered. sub move_to { my ( $self, $position ) = @_; return $self->_result->move_to($position) - if ( $position le $self->rota->stockrotationstages->count ); + if ( $position <= $self->rota->stockrotationstages->count ); return 0; } diff --git a/t/db_dependent/StockRotationStages.t b/t/db_dependent/StockRotationStages.t index 4547e035fe1..610ab88c894 100755 --- a/t/db_dependent/StockRotationStages.t +++ b/t/db_dependent/StockRotationStages.t @@ -68,7 +68,7 @@ subtest 'Basic object tests' => sub { }; subtest 'DBIx::Class::Ordered tests' => sub { - plan tests => 33; + plan tests => 34; $schema->storage->txn_begin; @@ -157,6 +157,17 @@ subtest 'DBIx::Class::Ordered tests' => sub { is( $srstage->previous_sibling->stage_id, $stageprevious->{stage_id}, "Move, correct previous." ); is( $srstage->next_sibling->stage_id, $stagenext->{stage_id}, "Move, correct next." ); + for ( my $i = 6 ; $i < 20 ; $i++ ) { + $builder->build( + { + source => 'Stockrotationstage', + value => { rota_id => $rota->{rota_id}, position => $i } + } + ); + } + + ok( $srstage->move_to(4), "Moved." ); + # Group manipulation my $newrota = $builder->build( { source => 'Stockrotationrota' } ); ok( $srstage->move_to_group( $newrota->{rota_id} ), "Move to Group." ); -- 2.39.5