diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index adf8723..f125a6a 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -579,6 +579,22 @@ sub fufillRequest($$) { my $requestId = $self->getRequest($supporterId, $params->{requestType}); return undef if not defined $requestId; + + my $fufillLookupSql = "SELECT * FROM fulfillment WHERE request_id = " . + $self->dbh->quote($requestId, 'SQL_INTEGER'); + + my $fufillRecord = $self->dbh()->selectall_hashref($fufillLookupSql, "request_id"); + if (not defined $fufillRecord and not defined $fufillRecord->{$requestId}) { + $self->_beginWork; + my $sth->prepare("INSERT INTO fulfillment(request_id, who, how, date) " . + "VALUES(? , ? , ? , date('now');"); + + $sth->execute($requestId, $params->{who}, $params->{how}); + $sth->finish; + $self->_commit; + $fufillRecord = $self->dbh()->selectall_hashref($fufillLookupSql, "request_id"); + } + return $fufillRecord->{$requestId}; } ###################################################################### diff --git a/sql/supporters-schema.sql b/sql/supporters-schema.sql index c93602e..94e6064 100644 --- a/sql/supporters-schema.sql +++ b/sql/supporters-schema.sql @@ -36,11 +36,14 @@ DROP TABLE IF EXISTS "fulfillment"; CREATE TABLE "fulfillment" ( "id" integer NOT NULL PRIMARY KEY, + "request_id" integer NOT NULL, "date" TEXT NOT NULL, "who" varchar(300) NOT NULL, "how" TEXT ); +CREATE UNIQUE INDEX fulfillment__one_fulfillment_per_request ON fulfillment(request_id); + DROP TABLE IF EXISTS "request_type"; CREATE TABLE "request_type" (