View | Details | Raw Unified | Return to bug 41801
Collapse All | Expand All

(-)a/C4/Reserves.pm (-5 / +11 lines)
Lines 1576-1596 sub AlterPriority { Link Here
1576
1576
1577
=head2 ToggleLowestPriority
1577
=head2 ToggleLowestPriority
1578
1578
1579
  ToggleLowestPriority( $borrowernumber, $biblionumber );
1579
  ToggleLowestPriority( $reserve_id, $is_lowestPriority );
1580
1580
1581
This function sets the lowestPriority field to true if is false, and false if it is true.
1581
This function sets the lowestPriority field to true if is false, and false if it is true
1582
and then reorders the holds on the record.
1583
1584
A hold toggled to lowest priority will go the bottom.
1585
A hold toggled to NOT lowest priority will go to the bottom of other non-lowest priority holds.
1582
1586
1583
=cut
1587
=cut
1584
1588
1585
sub ToggleLowestPriority {
1589
sub ToggleLowestPriority {
1586
    my ($reserve_id) = @_;
1590
    my ( $reserve_id, $is_lowestPriority ) = @_;
1587
1591
1588
    my $dbh = C4::Context->dbh;
1592
    my $dbh = C4::Context->dbh;
1589
1593
1594
    my $rank = $is_lowestPriority ? undef : '999999';
1595
1590
    my $sth = $dbh->prepare("UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1596
    my $sth = $dbh->prepare("UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1591
    $sth->execute($reserve_id);
1597
    $sth->execute($reserve_id);
1592
1598
1593
    FixPriority( { reserve_id => $reserve_id, rank => '999999' } );
1599
    FixPriority( { reserve_id => $reserve_id, rank => $rank } );
1594
}
1600
}
1595
1601
1596
=head2 SuspendAll
1602
=head2 SuspendAll
Lines 1744-1750 sub FixPriority { Link Here
1744
            }
1750
            }
1745
1751
1746
            # if index exists in array then move it to new position
1752
            # if index exists in array then move it to new position
1747
            if ( $key > -1 && $rank ne 'del' && $rank > 0 ) {
1753
            if ( $key > -1 && $rank ne 'del' && $rank && $rank > 0 ) {
1748
                my $new_rank    = $rank - 1;    # $new_rank is what you want the new index to be in the array
1754
                my $new_rank    = $rank - 1;    # $new_rank is what you want the new index to be in the array
1749
                my $moving_item = splice( @priority, $key, 1 );
1755
                my $moving_item = splice( @priority, $key, 1 );
1750
                $new_rank = scalar @priority if $new_rank > scalar @priority;
1756
                $new_rank = scalar @priority if $new_rank > scalar @priority;
(-)a/Koha/REST/V1/Holds.pm (-1 / +1 lines)
Lines 665-671 sub lowest_priority { Link Here
665
        unless $hold;
665
        unless $hold;
666
666
667
    return try {
667
    return try {
668
        C4::Reserves::ToggleLowestPriority($hold_id);
668
        C4::Reserves::ToggleLowestPriority( $hold_id, $hold->lowestPriority );
669
        $hold->discard_changes;    # refresh
669
        $hold->discard_changes;    # refresh
670
        return $c->render( status => 200, openapi => $hold_id );
670
        return $c->render( status => 200, openapi => $hold_id );
671
    } catch {
671
    } catch {
(-)a/t/db_dependent/Reserves.t (-4 / +11 lines)
Lines 2148-2154 subtest 'Bug 40866: AddReserve override JSON logging' => sub { Link Here
2148
2148
2149
subtest 'FixPriority() lowestPriority tests' => sub {
2149
subtest 'FixPriority() lowestPriority tests' => sub {
2150
2150
2151
    plan tests => 14;
2151
    plan tests => 16;
2152
2152
2153
    $schema->storage->txn_begin;
2153
    $schema->storage->txn_begin;
2154
2154
Lines 2173-2180 subtest 'FixPriority() lowestPriority tests' => sub { Link Here
2173
    }
2173
    }
2174
2174
2175
    # Mark holds 4 and 5 as lowestPriority; initial priorities should be 1..5
2175
    # Mark holds 4 and 5 as lowestPriority; initial priorities should be 1..5
2176
    ToggleLowestPriority( $reserve_ids[3] );    # hold 4 → lowestPriority, pushed to bottom
2176
    ToggleLowestPriority( $reserve_ids[3], 0 );    # hold 4 → lowestPriority, pushed to bottom
2177
    ToggleLowestPriority( $reserve_ids[4] );    # hold 5 → lowestPriority, pushed to bottom
2177
    ToggleLowestPriority( $reserve_ids[4], 0 );    # hold 5 → lowestPriority, pushed to bottom
2178
2178
2179
    my @holds = map { Koha::Holds->find($_) } @reserve_ids;
2179
    my @holds = map { Koha::Holds->find($_) } @reserve_ids;
2180
2180
Lines 2209-2214 subtest 'FixPriority() lowestPriority tests' => sub { Link Here
2209
    isnt( $holds[3]->priority, $p4_before, 'lowestPriority hold moved within lowest-priority group' );
2209
    isnt( $holds[3]->priority, $p4_before, 'lowestPriority hold moved within lowest-priority group' );
2210
    ok( $holds[3]->priority > $holds[2]->priority, 'Moved lowestPriority hold still below non-lowest holds' );
2210
    ok( $holds[3]->priority > $holds[2]->priority, 'Moved lowestPriority hold still below non-lowest holds' );
2211
2211
2212
    ToggleLowestPriority( $reserve_ids[4], 1 );    # Untoggle lowest priority for hold 4
2213
    $holds[4]->discard_changes;
2214
    is( $holds[4]->priority, 4, 'Hold is moved to the lowest of non-priority holds when toggled off' );
2215
2216
    ToggleLowestPriority( $reserve_ids[1], 0 );    # Untoggle lowest priority for hold 4
2217
    $holds[1]->discard_changes;
2218
    is( $holds[1]->priority, 5, 'Hold is moved to the lowest of low priority holds when toggled on' );
2219
2212
    # When ALL holds are lowestPriority, movement is unconstrained
2220
    # When ALL holds are lowestPriority, movement is unconstrained
2213
    my $biblio2 = $builder->build_sample_biblio;
2221
    my $biblio2 = $builder->build_sample_biblio;
2214
    my @all_low_ids;
2222
    my @all_low_ids;
2215
- 

Return to bug 41801