From ab73f58fd81ae521ecadefd7ba11f913662f9375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20R=C3=B6hrl?= Date: Thu, 20 Dec 2018 13:26:09 +0100 Subject: [PATCH] added private function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Röhrl --- lib/Service/LabelService.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/Service/LabelService.php b/lib/Service/LabelService.php index 0291133df..44d2c255d 100644 --- a/lib/Service/LabelService.php +++ b/lib/Service/LabelService.php @@ -90,15 +90,10 @@ class LabelService { throw new BadRequestException('board id must be a number'); } - $boardLabels = $this->labelMapper->findAll($boardId); - foreach($boardLabels as $boardLabel) { - if ($boardLabel->getTitle() === $title) { - throw new BadRequestException('title must be unique'); - break; - } - } - $this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE); + + $this->checkDuplicateTitle($boardId, $title); + if ($this->boardService->isArchived(null, $boardId)) { throw new StatusException('Operation not allowed. This board is archived.'); } @@ -160,14 +155,33 @@ class LabelService { } $this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE); + + $label = $this->find($id); + $this->checkDuplicateTitle($label->getBoardId(), $title); + if ($this->boardService->isArchived($this->labelMapper, $id)) { throw new StatusException('Operation not allowed. This board is archived.'); } - $label = $this->find($id); + $label->setTitle($title); $label->setColor($color); $this->changeHelper->boardChanged($label->getBoardId()); return $this->labelMapper->update($label); } + /** + * @param $boardId + * @param $title + * @throws BadRequestException + */ + private function checkDuplicateTitle($boardId, $title) { + $boardLabels = $this->labelMapper->findAll($boardId); + foreach($boardLabels as $boardLabel) { + if ($boardLabel->getTitle() === $title) { + throw new BadRequestException('title must be unique'); + break; + } + } + } + }