From 320fc0c263ddf8accdd25c66fb917d327a790c26 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Sat, 26 May 2018 22:38:25 +0200 Subject: [PATCH 1/3] Wrong array casting of UploadedFile-Object --- src/ngrest/validators/StorageUploadValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngrest/validators/StorageUploadValidator.php b/src/ngrest/validators/StorageUploadValidator.php index 20acd8d183..b3a795b3ea 100644 --- a/src/ngrest/validators/StorageUploadValidator.php +++ b/src/ngrest/validators/StorageUploadValidator.php @@ -86,7 +86,7 @@ public function validateAttribute($model, $attribute) return; } - $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : (array) UploadedFile::getInstance($model, $attribute); + $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : [ UploadedFile::getInstance($model, $attribute) ]; $contextModel = new DynamicModel(['file' => $files]); $contextModel->addRule(['file'], 'file', ['maxFiles' => $this->multiple ? 0 : 1])->validate(); From dafefc3436a72fbb6465e7237aca4cf4196295e5 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Mon, 28 May 2018 21:26:21 +0200 Subject: [PATCH 2/3] Update StorageUploadValidator.php --- src/ngrest/validators/StorageUploadValidator.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ngrest/validators/StorageUploadValidator.php b/src/ngrest/validators/StorageUploadValidator.php index b3a795b3ea..10aca8b87c 100644 --- a/src/ngrest/validators/StorageUploadValidator.php +++ b/src/ngrest/validators/StorageUploadValidator.php @@ -86,14 +86,18 @@ public function validateAttribute($model, $attribute) return; } - $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : [ UploadedFile::getInstance($model, $attribute) ]; - + $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : UploadedFile::getInstance($model, $attribute); + $contextModel = new DynamicModel(['file' => $files]); $contextModel->addRule(['file'], 'file', ['maxFiles' => $this->multiple ? 0 : 1])->validate(); - + if ($contextModel->hasErrors()) { return $this->addError($model, $attribute, $contextModel->getFirstError('file')); } + + if (!is_array($files)) { + $files = [$files]; + } $data = []; foreach ($files as $file) { From 68f0dcd59ddcf03d462551da6ed62f1c1ad32f74 Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Mon, 28 May 2018 21:30:01 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27a26d0117..dfeb38ae69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. This projec + [#129](https://github.com/luyadev/luya-module-admin/issues/129) Fixed problem when ngrest plugin try to write in object property instead of active record attribute. + [#125](https://github.com/luyadev/luya-module-admin/issues/125) Detach cruft behavior for global search response. ++ [#132](https://github.com/luyadev/luya-module-admin/pull/132) Fixed validation error on single file upload with the StorageUploadValidator. ## 1.2.0 (17. May 2018)