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

(-)a/C4/Reserves.pm (-60 / +39 lines)
Lines 1034-1046 Unsuspends all suspended reserves with a suspend_until date from before today. Link Here
1034
=cut
1034
=cut
1035
1035
1036
sub AutoUnsuspendReserves {
1036
sub AutoUnsuspendReserves {
1037
    my $today = dt_from_string();
1037
1038
1038
    my $dbh = C4::Context->dbh;
1039
    my @holds = Koha::Holds->search( { suspend_until => { '<' => $today->ymd() } } );
1039
1040
    my $query = "UPDATE reserves SET suspend = 0, suspend_until = NULL WHERE DATE( suspend_until ) < DATE( CURDATE() )";
1041
    my $sth = $dbh->prepare( $query );
1042
    $sth->execute();
1043
1040
1041
    map { $_->suspend(0)->suspend_until(undef)->store() } @holds;
1044
}
1042
}
1045
1043
1046
=head2 CancelReserve
1044
=head2 CancelReserve
Lines 1161-1179 sub ModReserve { Link Here
1161
        CancelReserve({ reserve_id => $reserve_id });
1159
        CancelReserve({ reserve_id => $reserve_id });
1162
    }
1160
    }
1163
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1161
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1164
        my $query = "
1162
        my $hold = Koha::Holds->find($reserve_id);
1165
            UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL
1163
1166
            WHERE reserve_id = ?
1164
        $hold->set(
1167
        ";
1165
            {
1168
        my $sth = $dbh->prepare($query);
1166
                priority    => $rank,
1169
        $sth->execute( $rank, $branchcode, $itemnumber, $reserve_id );
1167
                branchcode  => $branchcode,
1168
                itemnumber  => $itemnumber,
1169
                found       => undef,
1170
                waitingdate => undef
1171
            }
1172
        )->store();
1170
1173
1171
        if ( defined( $suspend_until ) ) {
1174
        if ( defined( $suspend_until ) ) {
1172
            if ( $suspend_until ) {
1175
            if ( $suspend_until ) {
1173
                $suspend_until = eval { output_pref( { dt => dt_from_string( $suspend_until ), dateonly => 1, dateformat => 'iso' }); };
1176
                $suspend_until = eval { dt_from_string( $suspend_until ) };
1174
                $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE reserve_id = ?", undef, ( $suspend_until, $reserve_id ) );
1177
                $hold->suspend_hold( $suspend_until );
1175
            } else {
1178
            } else {
1176
                $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE reserve_id = ?", undef, ( $reserve_id ) );
1179
                # FIXME: Why are we doing this? Should this be resuming the hold,
1180
                # or maybe suspending it indefinitely?
1181
                $hold->set( { suspend_until => undef } )->store();
1177
            }
1182
            }
1178
        }
1183
        }
1179
1184
Lines 1614-1642 be cleared when it is unsuspended. Link Here
1614
sub ToggleSuspend {
1619
sub ToggleSuspend {
1615
    my ( $reserve_id, $suspend_until ) = @_;
1620
    my ( $reserve_id, $suspend_until ) = @_;
1616
1621
1617
    $suspend_until = output_pref(
1622
    $suspend_until = dt_from_string($suspend_until) if ($suspend_until);
1618
        {
1619
            dt         => dt_from_string($suspend_until),
1620
            dateformat => 'iso',
1621
            dateonly   => 1
1622
        }
1623
    ) if ($suspend_until);
1624
1625
    my $do_until = ( $suspend_until ) ? '?' : 'NULL';
1626
1627
    my $dbh = C4::Context->dbh;
1628
1623
1629
    my $sth = $dbh->prepare(
1624
    my $hold = Koha::Holds->find( $reserve_id );
1630
        "UPDATE reserves SET suspend = NOT suspend,
1631
        suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END
1632
        WHERE reserve_id = ?
1633
    ");
1634
1625
1635
    my @params;
1626
    if ( $hold->is_suspended ) {
1636
    push( @params, $suspend_until ) if ( $suspend_until );
1627
        $hold->resume()
1637
    push( @params, $reserve_id );
1628
    } else {
1638
1629
        $hold->suspend_hold( $suspend_until );
1639
    $sth->execute( @params );
1630
    }
1640
}
1631
}
1641
1632
1642
=head2 SuspendAll
1633
=head2 SuspendAll
Lines 1661-1698 sub SuspendAll { Link Here
1661
    my $borrowernumber = $params{'borrowernumber'} || undef;
1652
    my $borrowernumber = $params{'borrowernumber'} || undef;
1662
    my $biblionumber   = $params{'biblionumber'}   || undef;
1653
    my $biblionumber   = $params{'biblionumber'}   || undef;
1663
    my $suspend_until  = $params{'suspend_until'}  || undef;
1654
    my $suspend_until  = $params{'suspend_until'}  || undef;
1664
    my $suspend        = defined( $params{'suspend'} ) ? $params{'suspend'} :  1;
1655
    my $suspend = defined( $params{'suspend'} ) ? $params{'suspend'} : 1;
1665
1656
1666
    $suspend_until = eval { output_pref( { dt => dt_from_string( $suspend_until), dateonly => 1, dateformat => 'iso' } ); }
1657
    $suspend_until = eval { dt_from_string($suspend_until) }
1667
                     if ( defined( $suspend_until ) );
1658
      if ( defined($suspend_until) );
1668
1659
1669
    return unless ( $borrowernumber || $biblionumber );
1660
    return unless ( $borrowernumber || $biblionumber );
1670
1661
1671
    my ( $query, $sth, $dbh, @query_params );
1662
    my $params;
1663
    $params->{found}          = undef;
1664
    $params->{borrowernumber} = $borrowernumber if $borrowernumber;
1665
    $params->{biblionumber}   = $biblionumber if $biblionumber;
1672
1666
1673
    $query = "UPDATE reserves SET suspend = ? ";
1667
    my @holds = Koha::Holds->search($params);
1674
    push( @query_params, $suspend );
1668
1675
    if ( !$suspend ) {
1669
    if ($suspend) {
1676
        $query .= ", suspend_until = NULL ";
1670
        map { $_->suspend_hold($suspend_until) } @holds;
1677
    } elsif ( $suspend_until ) {
1678
        $query .= ", suspend_until = ? ";
1679
        push( @query_params, $suspend_until );
1680
    }
1681
    $query .= " WHERE ";
1682
    if ( $borrowernumber ) {
1683
        $query .= " borrowernumber = ? ";
1684
        push( @query_params, $borrowernumber );
1685
    }
1671
    }
1686
    $query .= " AND " if ( $borrowernumber && $biblionumber );
1672
    else {
1687
    if ( $biblionumber ) {
1673
        map { $_->resume() } @holds;
1688
        $query .= " biblionumber = ? ";
1689
        push( @query_params, $biblionumber );
1690
    }
1674
    }
1691
    $query .= " AND found IS NULL ";
1692
1693
    $dbh = C4::Context->dbh;
1694
    $sth = $dbh->prepare( $query );
1695
    $sth->execute( @query_params );
1696
}
1675
}
1697
1676
1698
1677
(-)a/Koha/Hold.pm (+12 lines)
Lines 235-240 sub borrower { Link Here
235
    return $self->{_borrower};
235
    return $self->{_borrower};
236
}
236
}
237
237
238
=head3 is_suspended
239
240
my $bool = $hold->is_suspended();
241
242
=cut
243
244
sub is_suspended {
245
    my ( $self ) = @_;
246
247
    return $self->suspend();
248
}
249
238
=head3 type
250
=head3 type
239
251
240
=cut
252
=cut
(-)a/t/db_dependent/Holds.t (-3 / +21 lines)
Lines 8-14 use t::lib::TestBuilder; Link Here
8
use C4::Context;
8
use C4::Context;
9
use C4::Branch;
9
use C4::Branch;
10
10
11
use Test::More tests => 56;
11
use Test::More tests => 60;
12
use MARC::Record;
12
use MARC::Record;
13
use C4::Biblio;
13
use C4::Biblio;
14
use C4::Items;
14
use C4::Items;
Lines 145-156 ok( !$reserve->{'suspend'}, "Test ToggleSuspend(), no date" ); Link Here
145
145
146
ToggleSuspend( $reserve_id, '2012-01-01' );
146
ToggleSuspend( $reserve_id, '2012-01-01' );
147
$reserve = GetReserve( $reserve_id );
147
$reserve = GetReserve( $reserve_id );
148
ok( $reserve->{'suspend_until'} eq '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
148
is( $reserve->{'suspend_until'}, '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
149
149
150
AutoUnsuspendReserves();
150
AutoUnsuspendReserves();
151
$reserve = GetReserve( $reserve_id );
151
$reserve = GetReserve( $reserve_id );
152
ok( !$reserve->{'suspend'}, "Test AutoUnsuspendReserves()" );
152
ok( !$reserve->{'suspend'}, "Test AutoUnsuspendReserves()" );
153
153
154
SuspendAll(
155
    borrowernumber => $borrowernumber,
156
    biblionumber   => $biblionumber,
157
    suspend => 1,
158
    suspend_until => '2012-01-01',
159
);
160
$reserve = GetReserve( $reserve_id );
161
is( $reserve->{'suspend'}, 1, "Test SuspendAll()" );
162
is( $reserve->{'suspend_until'}, '2012-01-01 00:00:00', "Test SuspendAll(), with date" );
163
164
SuspendAll(
165
    borrowernumber => $borrowernumber,
166
    biblionumber   => $biblionumber,
167
    suspend => 0,
168
);
169
$reserve = GetReserve( $reserve_id );
170
is( $reserve->{'suspend'}, 0, "Test resuming with SuspendAll()" );
171
is( $reserve->{'suspend_until'}, undef, "Test resuming with SuspendAll(), should have no suspend until date" );
172
154
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
173
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
155
AddReserve(
174
AddReserve(
156
    $branch_1,
175
    $branch_1,
157
- 

Return to bug 14310