yii-auth
yii-auth copied to clipboard
yii-auth with db transaction
Hi All,
I have an issue with this extension (might be) and db transaction. When I login as superuser, I can call unpost method (and other method with db transaction) without any problem. But, when I login as other user, I got an error that said, There is no active transaction!
Can anyone help me with this?
Below is the method: ` public function actionUnpost($id) { if (Yii::app()->request->isPostRequest) { $model = $this->loadModel($id); $qtyCheck = array();
$transaction = Yii::app()->db->beginTransaction(); // Transaction begin
try {
// If unpost this will resulting in negative remaining quantity, we should cancel this unpost!!!
foreach ($model->formDetails as $detail) {
if (isset($qtyCheck[$detail->id])) {
$qtyCheck[$detail->id] -= ($detail->quantity * $detail->type);
} else {
$qtyCheck[$detail->id] = Journal::model()->getRemReceivingQty($detail->id, $detail->locationFk) - ($detail->quantity * $detail->type);
}
// remaining has normal balance positif, so check the remaining should not be less than 0
if (0 > $qtyCheck[$detail->id]) {
throw new CDbException('Stok barang ' . $detail->item->name . ' menjadi negatif, FB tidak bisa diunposting!');
}
// Delete journal entries
foreach ($detail->journalEntries as $entry) {
$entry->delete();
}
}
$model->postingStatus = FormHeader::UNPOSTED;
$model->save(false);
$transaction->commit();
Yii::app()->user->setFlash('success', "FB $model->headerNo telah berhasil diunposting.");
} catch (Exception $e) {
$transaction->rollBack();
Yii::app()->user->setFlash('error', $e->getMessage());
}
$this->redirect(array('view', 'id' => $model->id));
} else {
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again!');
}
}
`
TIA Daniel