From aff5e667862514d4b5bc2726f4c8ef28f527ed04 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sun, 20 Dec 2015 13:59:50 -0800 Subject: [PATCH] fulfillRequest(): basic implementation. First attempt at implementing fulfillRequest() method. It seems that request_id was incorrectly missing from the fulfillment table. --- Supporters/lib/Supporters.pm | 16 ++++++++++++++++ sql/supporters-schema.sql | 3 +++ 2 files changed, 19 insertions(+) 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" (