Skip to content

Commit

Permalink
Merge pull request #28 from bvanleeuwen1995/imageUploadTransaction
Browse files Browse the repository at this point in the history
Upload transaction
  • Loading branch information
noam148 committed May 18, 2017
2 parents 7df3ce7 + 5d7baf0 commit a1ceb0c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions controllers/ManagerController.php
Expand Up @@ -115,12 +115,14 @@ public function actionIndex() {
public function actionUpload() {
//set response header
Yii::$app->getResponse()->format = Response::FORMAT_JSON;

// Check if the user is allowed to upload the image
if (Yii::$app->controller->module->canUploadImage == false) {
// Return the response array to prevent from the action being executed any further
return [];
}
// Create the transaction and set the success variable
$transaction = Yii::$app->db->beginTransaction();
$bSuccess = false;

//disable Csrf
Yii::$app->controller->enableCsrfValidation = false;
Expand Down Expand Up @@ -152,10 +154,20 @@ public function actionUpload() {
//move_uploaded_file($sTempFile, $sMediaPath."/".$sFileName);
//save with Imagine class
Image::getImagine()->open($sTempFile)->save($sMediaPath . "/" . $sSaveFileName);
$bSuccess = true;
}
}
}
}

if ($bSuccess) {
// The upload action went successful, save the transaction
$transaction->commit();
} else {
// There where problems during the upload, kill the transaction
$transaction->rollBack();
}

//echo return json encoded
return $return;
}
Expand Down Expand Up @@ -372,19 +384,20 @@ public function actionDelete() {
//set response header
Yii::$app->getResponse()->format = Response::FORMAT_JSON;

if (Yii::$app->controller->module->canRemoveImage == false)
// User can not remove this image, return false status
return $return;
if (Yii::$app->controller->module->canRemoveImage == false) {
// User can not remove this image, return false status
return $return;
}

//get post
$ImageManager_id = Yii::$app->request->post("ImageManager_id");
//get details
$model = $this->findModel($ImageManager_id);

//delete record
if ($model->delete())
if ($model->delete()) {
$return['delete'] = true;

}
return $return;
}

Expand Down

0 comments on commit a1ceb0c

Please sign in to comment.