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

(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 742-748 sub CancelHold { Link Here
742
    return { code => 'RecordNotFound' } unless $reserve;
742
    return { code => 'RecordNotFound' } unless $reserve;
743
    return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber);
743
    return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber);
744
744
745
    C4::Reserves::CancelReserveFromId($reserve_id);
745
    C4::Reserves::CancelReserve({reserve_id => $reserve_id});
746
746
747
    return { code => 'Canceled' };
747
    return { code => 'Canceled' };
748
}
748
}
(-)a/C4/Reserves.pm (-72 / +19 lines)
Lines 120-126 BEGIN { Link Here
120
        &CanBookBeReserved
120
        &CanBookBeReserved
121
	&CanItemBeReserved
121
	&CanItemBeReserved
122
        &CancelReserve
122
        &CancelReserve
123
        &CancelReserveFromId
124
        &CancelExpiredReserves
123
        &CancelExpiredReserves
125
124
126
        &AutoUnsuspendReserves
125
        &AutoUnsuspendReserves
Lines 1062-1152 sub CancelReserve { Link Here
1062
    my $dbh = C4::Context->dbh;
1061
    my $dbh = C4::Context->dbh;
1063
1062
1064
    my $reserve = GetReserve( $reserve_id );
1063
    my $reserve = GetReserve( $reserve_id );
1065
1066
    my $query = "
1067
        UPDATE reserves
1068
        SET    cancellationdate = now(),
1069
               found            = Null,
1070
               priority         = 0
1071
        WHERE  reserve_id = ?
1072
    ";
1073
    my $sth = $dbh->prepare($query);
1074
    $sth->execute( $reserve_id );
1075
1076
    $query = "
1077
        INSERT INTO old_reserves
1078
        SELECT * FROM reserves
1079
        WHERE  reserve_id = ?
1080
    ";
1081
    $sth = $dbh->prepare($query);
1082
    $sth->execute( $reserve_id );
1083
1084
    $query = "
1085
        DELETE FROM reserves
1086
        WHERE  reserve_id = ?
1087
    ";
1088
    $sth = $dbh->prepare($query);
1089
    $sth->execute( $reserve_id );
1090
1091
    # now fix the priority on the others....
1092
    _FixPriority({ biblionumber => $reserve->{biblionumber} });
1093
}
1094
1095
=head2 CancelReserveFromId
1096
1097
    C4::Reserves::CancelReserveFromId($reserve_id);
1098
1099
Cancel a reserve, given its reserve_id
1100
1101
=cut
1102
1103
sub CancelReserveFromId {
1104
    my ($reserve_id) = @_;
1105
1106
    my $reserve = GetReserve($reserve_id);
1107
    if ($reserve) {
1064
    if ($reserve) {
1108
        my $dbh = C4::Context->dbh;
1065
        my $query = "
1109
1110
        # update the database, removing the record...
1111
        my $query = qq{
1112
            UPDATE reserves
1066
            UPDATE reserves
1113
            SET cancellationdate = NOW(),
1067
            SET    cancellationdate = now(),
1114
                found = NULL,
1068
                   found            = Null,
1115
                priority = 0
1069
                   priority         = 0
1116
            WHERE reserve_id = ?
1070
            WHERE  reserve_id = ?
1117
        };
1071
        ";
1118
        my $sth = $dbh->prepare($query);
1072
        my $sth = $dbh->prepare($query);
1119
        $sth->execute($reserve_id);
1073
        $sth->execute( $reserve_id );
1120
        $sth->finish;
1121
1074
1122
        $query = qq{
1075
        $query = "
1123
            INSERT INTO old_reserves
1076
            INSERT INTO old_reserves
1124
            SELECT * FROM reserves
1077
            SELECT * FROM reserves
1125
            WHERE reserve_id = ?
1078
            WHERE  reserve_id = ?
1126
        };
1079
        ";
1127
        $sth = $dbh->prepare($query);
1080
        $sth = $dbh->prepare($query);
1128
        my $rv = $sth->execute($reserve_id);
1081
        $sth->execute( $reserve_id );
1129
1130
        if ($rv) {
1131
            $query = qq{
1132
                DELETE FROM reserves
1133
                WHERE reserve_id = ?
1134
            };
1135
            $sth = $dbh->prepare($query);
1136
            $sth->execute($reserve_id);
1137
        } else {
1138
            warn "ERROR: Failed to move reserve $reserve_id to table old_reserves.";
1139
            return;
1140
        }
1141
1082
1142
        # now fix the priority on the others...
1083
        $query = "
1084
            DELETE FROM reserves
1085
            WHERE  reserve_id = ?
1086
        ";
1087
        $sth = $dbh->prepare($query);
1088
        $sth->execute( $reserve_id );
1089
1090
        # now fix the priority on the others....
1143
        _FixPriority({ biblionumber => $reserve->{biblionumber} });
1091
        _FixPriority({ biblionumber => $reserve->{biblionumber} });
1144
    }
1092
    }
1145
1093
1146
    return $reserve;
1094
    return $reserve;
1147
}
1095
}
1148
1096
1149
1150
=head2 ModReserve
1097
=head2 ModReserve
1151
1098
1152
  ModReserve({ rank => $rank,
1099
  ModReserve({ rank => $rank,
(-)a/t/db_dependent/Reserves.t (-5 / +4 lines)
Lines 238-252 $reserve = GetReserve($reserve_id); Link Here
238
isa_ok($reserve, 'HASH', "GetReserve return");
238
isa_ok($reserve, 'HASH', "GetReserve return");
239
is($reserve->{biblionumber}, $biblionumber);
239
is($reserve->{biblionumber}, $biblionumber);
240
240
241
$reserve = CancelReserveFromId($reserve_id);
241
$reserve = CancelReserve({reserve_id => $reserve_id});
242
isa_ok($reserve, 'HASH', "CancelReserveFromId return");
242
isa_ok($reserve, 'HASH', "CancelReserve return");
243
is($reserve->{biblionumber}, $biblionumber);
243
is($reserve->{biblionumber}, $biblionumber);
244
244
245
$reserve = GetReserve($reserve_id);
245
$reserve = GetReserve($reserve_id);
246
is($reserve, undef, "GetReserve returns undef after deletion");
246
is($reserve, undef, "GetReserve returns undef after deletion");
247
247
248
$reserve = CancelReserveFromId($reserve_id);
248
$reserve = CancelReserve({reserve_id => $reserve_id});
249
is($reserve, undef, "CancelReserveFromId return undef if reserve does not exist");
249
is($reserve, undef, "CancelReserve return undef if reserve does not exist");
250
250
251
251
252
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
252
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
253
- 

Return to bug 8868