diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-31 02:58:56 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-31 02:58:56 +0200 |
commit | 7036a1407c3dce54a6ac5e283ba55720f85ba7de (patch) | |
tree | 7c5fae7ab816a2b0c56b92ca74ebc7cc591d5a3d /businesslayer/folderbusinesslayer.php | |
parent | 6f23208ff68d4a8bf2fc20b1fcad6b5e636fb584 (diff) |
Throw proper error codes when creating invalid folders through the API, fix #297
Diffstat (limited to 'businesslayer/folderbusinesslayer.php')
-rw-r--r-- | businesslayer/folderbusinesslayer.php | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php index ee0f8c8af..e43c705c6 100644 --- a/businesslayer/folderbusinesslayer.php +++ b/businesslayer/folderbusinesslayer.php @@ -58,13 +58,17 @@ class FolderBusinessLayer extends BusinessLayer { } - private function allowNoNameTwice($folderName, $userId){ + private function validateFolder($folderName, $userId){ $existingFolders = $this->mapper->findByName($folderName, $userId); if(count($existingFolders) > 0){ - throw new BusinessLayerExistsException( + throw new BusinessLayerConflictException( $this->api->getTrans()->t('Can not add folder: Exists already')); } + + if(mb_strlen($folderName) === 0) { + throw new BusinessLayerValidationException('Folder name can not be empty'); + } } @@ -73,11 +77,12 @@ class FolderBusinessLayer extends BusinessLayer { * @param string $folderName the name of the folder * @param string $userId the name of the user for whom it should be created * @param int $parentId the parent folder id, deprecated we dont nest folders - * @throws BusinessLayerExistsException if name exists already + * @throws BusinessLayerConflictException if name exists already + * @throws BusinessLayerValidationException if the folder has invalid parameters * @return Folder the newly created folder */ public function create($folderName, $userId, $parentId=0) { - $this->allowNoNameTwice($folderName, $userId); + $this->validateFolder($folderName, $userId); $folder = new Folder(); $folder->setName($folderName); @@ -87,6 +92,7 @@ class FolderBusinessLayer extends BusinessLayer { return $this->mapper->insert($folder); } + /** * @throws BusinessLayerException if the folder does not exist */ @@ -102,13 +108,13 @@ class FolderBusinessLayer extends BusinessLayer { * @param int $folderId the id of the folder that should be deleted * @param string $folderName the new name of the folder * @param string $userId the name of the user for security reasons - * @throws BusinessLayerExistsException if name exists already - * @throws BusinessLayerInvalidParameterException if the foldername is invalid + * @throws BusinessLayerConflictException if name exists already + * @throws BusinessLayerValidationException if the folder has invalid parameters * @throws BusinessLayerException if the folder does not exist * @return Folder the updated folder */ public function rename($folderId, $folderName, $userId){ - $this->allowNoNameTwice($folderName, $userId); + $this->validateFolder($folderName, $userId); $folder = $this->find($folderId, $userId); $folder->setName($folderName); |