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.
This commit is contained in:
Bradley M. Kuhn 2015-12-17 20:15:41 -08:00
parent 8876808aec
commit d1d9b80583

View file

@ -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<requestType> and C<requestTypeId>. If
C<requestTypeId> is set, it simply deletes the C<requestType> parameter and
verifies c<reuqestTypeId> 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() =item _beginWork()
Parameters: Parameters: