Skip to content

Commit

Permalink
Add ability to save model after upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rkit committed Oct 2, 2017
1 parent c403d6b commit 02c7e77
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/actions/UploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class UploadAction extends Action
* @var string $resultFieldPath The name of the field that contains the path of the file in the response
*/
public $resultFieldPath = 'path';
/**
* @var bool $saveAfterUpload Save after upload
*/
public $saveAfterUpload = false;
/**
* @var ActiveRecord $model
*/
Expand Down Expand Up @@ -86,7 +90,7 @@ public function run()
$model->file = $model->file[0];
}

return $this->save($model->file);
return $this->upload($model->file);
}

/**
Expand All @@ -96,10 +100,13 @@ public function run()
* @return string JSON
* @SuppressWarnings(PHPMD.ElseExpression)
*/
private function save($file)
private function upload($file)
{
$file = $this->model->createFile($this->attribute, $file->tempName, $file->name);
if ($file) {
if ($this->saveAfterUpload) {
$this->model->save(false);
}
$presetAfterUpload = $this->model->filePresetAfterUpload($this->attribute);
if (count($presetAfterUpload)) {
$this->applyPreset($presetAfterUpload, $file);
Expand Down

0 comments on commit 02c7e77

Please sign in to comment.