Is there a way to add an action to a CDbConnection
when rollback
action is called ?
I have this code and it works :
$transaction = $model->dbConnection->beginTransaction();
try {
//...
//doing some manipulations
//...
if($model->save()) {
$transaction->commit();
$this->redirect(array('view','id'=>$model->id));
}
} catch(Exception $e) {
$transaction->rollback();
throw $e;
}
Is there a way reverting the manipulations done when the $transaction->rollback();
is called without putting this code in the catch
statement, like adding an event on the transaction rollback function.
Maybe there's a workaround with Behaviours and Events, but I'm not sure how it works.
Thanks!
EDIT - What I want to do is this:
When the model fail to save, there will be a rollback on the database, but I'm doing some manipulations on the files too (that I need to do before validating & saving the model), so if the model fail to save because of the validation, I need to revert theses changes to the files.