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 |
|