_rollback() work if failure occurs in these calls.
This is the location where there was unbalanced _beginWork()/_commit() calls. In future, when writing tests, it's probably good to check this often in the tests.
This commit is contained in:
parent
794d34a79f
commit
096561a5c4
1 changed files with 11 additions and 5 deletions
|
@ -744,17 +744,23 @@ sub addRequest($$) {
|
||||||
unless $self->_verifyId($supporterId);
|
unless $self->_verifyId($supporterId);
|
||||||
|
|
||||||
$self->_beginWork;
|
$self->_beginWork;
|
||||||
$self->_getOrCreateRequestType($params);
|
eval {
|
||||||
$self->_getOrCreateRequestConfiguration($params) if (defined $params->{requestConfiguration} or
|
$self->_getOrCreateRequestType($params);
|
||||||
defined $params->{requestConfigurationId});
|
$self->_getOrCreateRequestConfiguration($params) if (defined $params->{requestConfiguration} or
|
||||||
|
defined $params->{requestConfigurationId});
|
||||||
|
};
|
||||||
|
if ($@ or not defined $params->{requestTypeId}) {
|
||||||
|
my $err = $@;
|
||||||
|
$err = "addRequest: unable to create requestType" if (not defined $err);
|
||||||
|
$self->_rollback();
|
||||||
|
die $@ if $@;
|
||||||
|
}
|
||||||
|
|
||||||
# After those two calls above, I know I have requestTypeId and
|
# After those two calls above, I know I have requestTypeId and
|
||||||
# requestConfigurationId are accurate. Note that
|
# requestConfigurationId are accurate. Note that
|
||||||
# $params->{requestConfigurationId} can be undef, which is permitted in the
|
# $params->{requestConfigurationId} can be undef, which is permitted in the
|
||||||
# database schema.
|
# database schema.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $sth = $self->dbh->prepare("INSERT INTO request(supporter_id, request_type_id, request_configuration_id, notes, date_requested) " .
|
my $sth = $self->dbh->prepare("INSERT INTO request(supporter_id, request_type_id, request_configuration_id, notes, date_requested) " .
|
||||||
"VALUES(?, ?, ?, ?, date('now'))");
|
"VALUES(?, ?, ?, ?, date('now'))");
|
||||||
$sth->execute($supporterId, $params->{requestTypeId}, $params->{requestConfigurationId}, $params->{notes});
|
$sth->execute($supporterId, $params->{requestTypeId}, $params->{requestConfigurationId}, $params->{notes});
|
||||||
|
|
Loading…
Add table
Reference in a new issue