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

(-)a/C4/Reserves.pm (-15 / +18 lines)
Lines 60-65 BEGIN { Link Here
60
        GetMaxPatronHoldsForRecord
60
        GetMaxPatronHoldsForRecord
61
61
62
        MergeHolds
62
        MergeHolds
63
64
        FixPriority
63
    );
65
    );
64
}
66
}
65
67
Lines 290-296 sub AddReserve { Link Here
290
        ChargeReserveFee( $borrowernumber, $reserve_fee, $title );
292
        ChargeReserveFee( $borrowernumber, $reserve_fee, $title );
291
    }
293
    }
292
294
293
    _FixPriority( { biblionumber => $biblionumber } );
295
    FixPriority( { biblionumber => $biblionumber } );
294
296
295
    # Send e-mail to librarian if syspref is active
297
    # Send e-mail to librarian if syspref is active
296
    if ( C4::Context->preference("emailLibrarianWhenHoldIsPlaced") ) {
298
    if ( C4::Context->preference("emailLibrarianWhenHoldIsPlaced") ) {
Lines 1219-1224 sub ModReserve { Link Here
1219
    my $biblionumber        = $params->{'biblionumber'};
1221
    my $biblionumber        = $params->{'biblionumber'};
1220
    my $cancellation_reason = $params->{'cancellation_reason'};
1222
    my $cancellation_reason = $params->{'cancellation_reason'};
1221
    my $date                = $params->{expirationdate};
1223
    my $date                = $params->{expirationdate};
1224
    my $skip_fixup_priority = $params->{skip_fixup_priority};
1222
1225
1223
    return if defined $rank && $rank eq "n";
1226
    return if defined $rank && $rank eq "n";
1224
1227
Lines 1277-1283 sub ModReserve { Link Here
1277
            }
1280
            }
1278
        }
1281
        }
1279
1282
1280
        _FixPriority( { reserve_id => $reserve_id, rank => $rank } );
1283
        FixPriority( { reserve_id => $reserve_id, rank => $rank } ) unless $skip_fixup_priority;
1281
1284
1282
        logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold, undef, $original )
1285
        logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold, undef, $original )
1283
            if C4::Context->preference('HoldsLog');
1286
            if C4::Context->preference('HoldsLog');
Lines 1390-1396 sub ModReserveAffect { Link Here
1390
1393
1391
    _koha_notify_hold_changed($hold) if $notify_library;
1394
    _koha_notify_hold_changed($hold) if $notify_library;
1392
1395
1393
    _FixPriority( { biblionumber => $biblionumber } );
1396
    FixPriority( { biblionumber => $biblionumber } );
1394
    my $item = Koha::Items->find($itemnumber);
1397
    my $item = Koha::Items->find($itemnumber);
1395
    if (   $item->location
1398
    if (   $item->location
1396
        && $item->location eq 'CART'
1399
        && $item->location eq 'CART'
Lines 1477-1483 sub ModReserveMinusPriority { Link Here
1477
    $sth_upd->execute( $itemnumber, $reserve_id );
1480
    $sth_upd->execute( $itemnumber, $reserve_id );
1478
1481
1479
    # second step update all others reserves
1482
    # second step update all others reserves
1480
    _FixPriority( { reserve_id => $reserve_id, rank => '0' } );
1483
    FixPriority( { reserve_id => $reserve_id, rank => '0' } );
1481
}
1484
}
1482
1485
1483
=head2 IsAvailableForItemLevelRequest
1486
=head2 IsAvailableForItemLevelRequest
Lines 1634-1647 sub AlterPriority { Link Here
1634
1637
1635
    if ( $where eq 'up' ) {
1638
    if ( $where eq 'up' ) {
1636
        return unless $prev_priority;
1639
        return unless $prev_priority;
1637
        _FixPriority( { reserve_id => $reserve_id, rank => $prev_priority } );
1640
        FixPriority( { reserve_id => $reserve_id, rank => $prev_priority } );
1638
    } elsif ( $where eq 'down' ) {
1641
    } elsif ( $where eq 'down' ) {
1639
        return unless $next_priority;
1642
        return unless $next_priority;
1640
        _FixPriority( { reserve_id => $reserve_id, rank => $next_priority } );
1643
        FixPriority( { reserve_id => $reserve_id, rank => $next_priority } );
1641
    } elsif ( $where eq 'top' ) {
1644
    } elsif ( $where eq 'top' ) {
1642
        _FixPriority( { reserve_id => $reserve_id, rank => $first_priority } );
1645
        FixPriority( { reserve_id => $reserve_id, rank => $first_priority } );
1643
    } elsif ( $where eq 'bottom' ) {
1646
    } elsif ( $where eq 'bottom' ) {
1644
        _FixPriority( { reserve_id => $reserve_id, rank => $last_priority } );
1647
        FixPriority( { reserve_id => $reserve_id, rank => $last_priority } );
1645
    }
1648
    }
1646
1649
1647
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $hold->biblionumber ] } )
1650
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [ $hold->biblionumber ] } )
Lines 1666-1672 sub ToggleLowestPriority { Link Here
1666
    my $sth = $dbh->prepare("UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1669
    my $sth = $dbh->prepare("UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1667
    $sth->execute($reserve_id);
1670
    $sth->execute($reserve_id);
1668
1671
1669
    _FixPriority( { reserve_id => $reserve_id, rank => '999999' } );
1672
    FixPriority( { reserve_id => $reserve_id, rank => '999999' } );
1670
}
1673
}
1671
1674
1672
=head2 SuspendAll
1675
=head2 SuspendAll
Lines 1709-1717 sub SuspendAll { Link Here
1709
    }
1712
    }
1710
}
1713
}
1711
1714
1712
=head2 _FixPriority
1715
=head2 FixPriority
1713
1716
1714
  _FixPriority({
1717
  FixPriority({
1715
    reserve_id => $reserve_id,
1718
    reserve_id => $reserve_id,
1716
    [rank => $rank,]
1719
    [rank => $rank,]
1717
    [ignoreSetLowestRank => $ignoreSetLowestRank]
1720
    [ignoreSetLowestRank => $ignoreSetLowestRank]
Lines 1719-1725 sub SuspendAll { Link Here
1719
1722
1720
  or
1723
  or
1721
1724
1722
  _FixPriority({ biblionumber => $biblionumber});
1725
 FixPriority({ biblionumber => $biblionumber});
1723
1726
1724
This routine adjusts the priority of a hold request and holds
1727
This routine adjusts the priority of a hold request and holds
1725
on the same bib.
1728
on the same bib.
Lines 1740-1750 In both cases, holds that have the lowestPriority flag on are have their Link Here
1740
priority adjusted to ensure that they remain at the end of the line.
1743
priority adjusted to ensure that they remain at the end of the line.
1741
1744
1742
Note that the ignoreSetLowestRank parameter is meant to be used only
1745
Note that the ignoreSetLowestRank parameter is meant to be used only
1743
when _FixPriority calls itself.
1746
when FixPriority calls itself.
1744
1747
1745
=cut
1748
=cut
1746
1749
1747
sub _FixPriority {
1750
sub FixPriority {
1748
    my ($params)            = @_;
1751
    my ($params)            = @_;
1749
    my $reserve_id          = $params->{reserve_id};
1752
    my $reserve_id          = $params->{reserve_id};
1750
    my $rank                = $params->{rank} // '';
1753
    my $rank                = $params->{rank} // '';
Lines 1837-1843 sub _FixPriority { Link Here
1837
            "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 AND biblionumber = ? ORDER BY priority");
1840
            "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 AND biblionumber = ? ORDER BY priority");
1838
        $sth->execute($biblionumber);
1841
        $sth->execute($biblionumber);
1839
        while ( my $res = $sth->fetchrow_hashref() ) {
1842
        while ( my $res = $sth->fetchrow_hashref() ) {
1840
            _FixPriority(
1843
            FixPriority(
1841
                {
1844
                {
1842
                    reserve_id          => $res->{'reserve_id'},
1845
                    reserve_id          => $res->{'reserve_id'},
1843
                    rank                => '999999',
1846
                    rank                => '999999',
(-)a/Koha/Hold.pm (-3 / +3 lines)
Lines 917-923 sub cancel { Link Here
917
917
918
            $self->SUPER::delete();    # Do not add a DELETE log
918
            $self->SUPER::delete();    # Do not add a DELETE log
919
                                       # now fix the priority on the others....
919
                                       # now fix the priority on the others....
920
            C4::Reserves::_FixPriority( { biblionumber => $self->biblionumber } );
920
            C4::Reserves::FixPriority( { biblionumber => $self->biblionumber } );
921
921
922
            # and, if desired, charge a cancel fee
922
            # and, if desired, charge a cancel fee
923
            if ( $params->{'charge_cancel_fee'} ) {
923
            if ( $params->{'charge_cancel_fee'} ) {
Lines 1016-1022 sub fill { Link Here
1016
            $self->SUPER::delete();    # Do not add a DELETE log
1016
            $self->SUPER::delete();    # Do not add a DELETE log
1017
1017
1018
            # now fix the priority on the others....
1018
            # now fix the priority on the others....
1019
            C4::Reserves::_FixPriority( { biblionumber => $self->biblionumber } );
1019
            C4::Reserves::FixPriority( { biblionumber => $self->biblionumber } );
1020
1020
1021
            if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
1021
            if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
1022
                my $fee = $patron->category->reservefee // 0;
1022
                my $fee = $patron->category->reservefee // 0;
Lines 1105-1111 sub revert_found { Link Here
1105
            logaction( 'HOLDS', 'MODIFY', $self->id, $self, undef, $original )
1105
            logaction( 'HOLDS', 'MODIFY', $self->id, $self, undef, $original )
1106
                if C4::Context->preference('HoldsLog');
1106
                if C4::Context->preference('HoldsLog');
1107
1107
1108
            C4::Reserves::_FixPriority( { biblionumber => $self->biblionumber } );
1108
            C4::Reserves::FixPriority( { biblionumber => $self->biblionumber } );
1109
1109
1110
            $self->remove_as_hold_group_target();
1110
            $self->remove_as_hold_group_target();
1111
1111
(-)a/Koha/REST/V1/Holds.pm (-1 / +1 lines)
Lines 515-521 sub update_priority { Link Here
515
515
516
    return try {
516
    return try {
517
        my $priority = $c->req->json;
517
        my $priority = $c->req->json;
518
        C4::Reserves::_FixPriority(
518
        C4::Reserves::FixPriority(
519
            {
519
            {
520
                reserve_id => $hold->id,
520
                reserve_id => $hold->id,
521
                rank       => $priority
521
                rank       => $priority
(-)a/reserve/modrequest.pl (-1 / +5 lines)
Lines 28-34 use List::MoreUtils qw( uniq ); Link Here
28
use Try::Tiny;
28
use Try::Tiny;
29
29
30
use C4::Output;
30
use C4::Output;
31
use C4::Reserves qw( ModReserve );
31
use C4::Reserves qw( ModReserve FixPriority );
32
use C4::Auth     qw( checkauth );
32
use C4::Auth     qw( checkauth );
33
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
33
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
34
34
Lines 63-68 if ( $op eq 'cud-cancelall' || $op eq 'cud-modifyall' ) { Link Here
63
            itemnumber     => $itemnumber[$i],
63
            itemnumber     => $itemnumber[$i],
64
            defined $suspend_until ? ( suspend_until => $suspend_until ) : (),
64
            defined $suspend_until ? ( suspend_until => $suspend_until ) : (),
65
            cancellation_reason => $cancellation_reason,
65
            cancellation_reason => $cancellation_reason,
66
            skip_fixup_priority => 1,
66
        };
67
        };
67
        if ( C4::Context->preference('AllowHoldDateInFuture') ) {
68
        if ( C4::Context->preference('AllowHoldDateInFuture') ) {
68
            $params->{reservedate} = $reservedates[$i] || undef;
69
            $params->{reservedate} = $reservedates[$i] || undef;
Lines 95-100 if ( $op eq 'cud-cancelall' || $op eq 'cud-modifyall' ) { Link Here
95
    my @biblio_ids = uniq @biblionumber;
96
    my @biblio_ids = uniq @biblionumber;
96
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@biblio_ids } )
97
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@biblio_ids } )
97
        if C4::Context->preference('RealTimeHoldsQueue');
98
        if C4::Context->preference('RealTimeHoldsQueue');
99
    foreach my $biblio_id (@biblio_ids) {
100
        FixPriority( { biblionumber => $biblio_id } );
101
    }
98
}
102
}
99
103
100
my $from = $query->param('from');
104
my $from = $query->param('from');
(-)a/reserve/request.pl (-2 / +1 lines)
Lines 157-163 if ( $op eq 'cud-move' ) { Link Here
157
    }
157
    }
158
158
159
    #Fix the priority on the original record
159
    #Fix the priority on the original record
160
    C4::Reserves::_FixPriority( { biblionumber => $original_biblionumber } );
160
    C4::Reserves::FixPriority( { biblionumber => $original_biblionumber } );
161
161
162
    $template->param(
162
    $template->param(
163
        hold_move_successes => \@success_messages,
163
        hold_move_successes => \@success_messages,
164
- 

Return to bug 41416