Never fulfill requests that are on hold.

Requests on hold can never be fulfilled.

If you want to fulfill a request that is currently on hold, the right
semantic is that you should remove the hold, then fulfill the request.

Note that this test now passes and it didn't before:
  fulfillRequest: .... but undef is returned when attempting to fulfill a held request.
This commit is contained in:
Bradley M. Kuhn 2017-01-14 20:15:35 -08:00
parent 836a70c0ab
commit 258d9fad0f

View file

@ -1289,6 +1289,16 @@ sub fulfillRequest($$) {
my $fulfillRecord = $self->dbh()->selectall_hashref($fulfillLookupSql, "request_id");
if (not defined $fulfillRecord or not defined $fulfillRecord->{$requestId}) {
# First check if request is held. If it's held, it cannot be fulfilled.
my $holdReq = $self->dbh()->selectall_hashref("SELECT id, request_id, release_date " .
"FROM request_hold WHERE request_id = " .
$self->dbh->quote($requestId, 'SQL_INTEGER'),
'request_id');
return undef
if (defined $holdReq and defined $holdReq->{$requestId} and defined $holdReq->{$requestId}{id}
and $TODAY lt $holdReq->{$requestId}{release_date});
# Ok, it's not on hold, so go ahead and fulfill it.
$self->_beginWork;
my $sth = $self->dbh->prepare("INSERT INTO fulfillment(request_id, who, how, date) " .
"VALUES(? , ? , ? , date('now'))");