I have a form that adds new venues into the db. A section of the form allows
the upload of a thumbnail for the venue in context.
Now, when the file-size or image dimension of the uploaded image is not
according to the limit and size specified an exception is thrown:
[CODE]
public function uploadFiles($request){
if (($_FILES["main_thumbnail"]["type"] == "image/jpeg" &&
$_FILES["main_thumbnail"]["size"] <= 20000))
{
$_FILES["main_thumbnail"]["name"] = "thumb_" . $venueId . ".jpg";
move_uploaded_file($_FILES["main_thumbnail"]["tmp_name"], $venuesPath .
$venueThumb . "/" . $_FILES["main_thumbnail"]["name"]);
$size = getimagesize($venuesPath . $venueThumb . "/"
.$_FILES["main_thumbnail"]["name"]);
$img_width = $size[0];
$img_height = $size[1];
if( $img_width > 200 || $img_height > 120){
$this->addError('size', 'Upload Error: The Thumbnail is greater than the
allowed<br/> dimension of 200w X 120h');
unlink($venuesPath . $venueThumb . "/" .$_FILES["main_thumbnail"]["name"]);
rmdir($venuesPath . $venueThumb);
rmdir($venuesPath . $venuePics);
rmdir($venuesPath . $venueMap);
rmdir($venuesPath . $venueId);
throw new Exception('Upload Error: The Thumbnail is greater than the allowed
dimension of 200w X 120h');
}
...
[/CODE]
And then in my controller action i using the rollback function from the
Zend_Db i asked the table inserts to rollback().
[CODE]
...
$db->insert('venue', $venueData);
$venueid = $db->lastInsertId();
$db->insert('contactperson', $contactData);
$db->insert('opendays', $opendays);
$db->commit();
try{
$this->uploadFiles($venueid);
}catch(Exception $e){
$db->rollBack();
$this->addError('sys2', 'A system error as occured. A notice has been sent
to the <br/>System Administrator. You will be notified via email once this
<br/>is sorted.');
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$log = new LogToAdmin();
$log->mailFault($e->getTraceAsString(), $user->UserName, $e->getMessage());
$this->_redirect('admin/venues/add');
}
...
[/CODE]
One thing i have noticed is that the rollback function only rolls back a
transaction if an error was occured on the db server not in the application
code like the scenario i have.
Is there a way of 'forcing' a roll back action in the db like i want for
this scenario??
-----
dee
--
View this message in context: http://www.nabble.com/Transactions---Forcing-a-Rollback-Action-tp19142158p19142158.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论