From d1d9b805838aa77c9d742ef35a94811c69473a40 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Thu, 17 Dec 2015 20:15:41 -0800 Subject: [PATCH] Implementation of _getOrCreateRequestType Tests pass for this now: ok 97 - _getOrCreateRequestType: dies on empty hash ok 98 - _getOrCreateRequestType: dies for string request id ok 99 - _getOrCreateRequestType: dies for non-existant requestTypeId ok 100 - _getOrCreateRequestType: succeeds with just requestType ok 101 - _getOrCreateRequestType: lookup of a request works after _getOrCreateRequestType ok 102 - _getOrCreateRequestType: lookup of a request works after _getOrCreateRequestType ok 103 - _getOrCreateRequestType: lookup of existing requestType suceeds. ok 104 - _getOrCreateRequestType: deletes requestType if both are provided. --- Supporters/lib/Supporters.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 1786de0..c6113aa 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -487,6 +487,40 @@ sub _verifyId($$) { } +=item _getOrCreateRequestType + +Arguments: + +=over + +=item $params (hash reference) + +This hash reference usually contains other paramaters, too, but this method +looks only at the keys C and C. If +C is set, it simply deletes the C parameter and +verifies c is in the request_type table. + +=cut + +sub _getOrCreateRequestType($$) { + my($self, $params) = @_; + + if (not defined $params->{requestTypeId}) { + $params->{requestTypeId} = $self->addRequestType($params->{requestType}); + } else { + my $id = $params->{requestTypeId}; + die "_getOrCreateRequestType(): called with a non-numeric requestTypeId" + unless defined $id and looks_like_number($id); + + my $val = $self->dbh()->selectall_hashref("SELECT id FROM request_type WHERE id = " . + $self->dbh->quote($id, 'SQL_INTEGER'), 'id'); + + die "_getOrCreateRequestType(): given requestTypeId, $id, is invalid" + unless (defined $val and defined $val->{$id}); + } + delete $params->{requestType}; +} + =item _beginWork() Parameters: