Conditionally transaction finish.
Using like return $trans->Commit();
if (!f()) $trans->Rollback();
Conditionally one entry finish trans