From 3b6169c332932f469fd84a671b351c31db8edebb Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Thu, 29 Jun 2017 15:59:47 +0200 Subject: [PATCH] SW-18242 - add parameters to exceptions in media resource --- .../Components/Api/Resource/Media.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/engine/Shopware/Components/Api/Resource/Media.php b/engine/Shopware/Components/Api/Resource/Media.php index 6625eae9a7b..1bf246bda83 100644 --- a/engine/Shopware/Components/Api/Resource/Media.php +++ b/engine/Shopware/Components/Api/Resource/Media.php @@ -47,7 +47,7 @@ class Media extends Resource */ public function getRepository() { - return $this->getManager()->getRepository('Shopware\Models\Media\Media'); + return $this->getManager()->getRepository(MediaModel::class); } /** @@ -56,7 +56,7 @@ public function getRepository() * @throws \Shopware\Components\Api\Exception\ParameterMissingException * @throws \Shopware\Components\Api\Exception\NotFoundException * - * @return array|\Shopware\Models\Media\Media + * @return array|MediaModel */ public function getOne($id) { @@ -69,7 +69,7 @@ public function getOne($id) $filters = [['property' => 'media.id', 'expression' => '=', 'value' => $id]]; $query = $this->getRepository()->getMediaListQuery($filters, [], 1); - /** @var $media \Shopware\Models\Media\Media */ + /** @var $media MediaModel */ $media = $query->getOneOrNullResult($this->getResultMode()); if (!$media) { @@ -119,7 +119,7 @@ public function getList($offset = 0, $limit = 25, array $criteria = [], array $o * @throws \Shopware\Components\Api\Exception\ValidationException * @throws \Exception * - * @return \Shopware\Models\Media\Media + * @return MediaModel */ public function create(array $params) { @@ -127,7 +127,7 @@ public function create(array $params) $params = $this->prepareMediaData($params); - $media = new \Shopware\Models\Media\Media(); + $media = new MediaModel(); $media->fromArray($params); $path = $this->prepareFilePath($media->getPath(), $media->getFileName()); @@ -160,17 +160,17 @@ public function create(array $params) * @throws \Shopware\Components\Api\Exception\ParameterMissingException * @throws \Shopware\Components\Api\Exception\CustomValidationException * - * @return \Shopware\Models\Media\Media + * @return MediaModel */ public function update($id, array $params) { $this->checkPrivilege('update'); if (empty($id)) { - throw new ApiException\ParameterMissingException(); + throw new ApiException\ParameterMissingException('id'); } - /** @var $media \Shopware\Models\Media\Media */ + /** @var $media MediaModel */ $media = $this->getRepository()->find($id); if (!$media) { @@ -203,17 +203,17 @@ public function update($id, array $params) * @throws \Shopware\Components\Api\Exception\ParameterMissingException * @throws \Shopware\Components\Api\Exception\NotFoundException * - * @return \Shopware\Models\Media\Media + * @return MediaModel */ public function delete($id) { $this->checkPrivilege('delete'); if (empty($id)) { - throw new ApiException\ParameterMissingException(); + throw new ApiException\ParameterMissingException('id'); } - /** @var $media \Shopware\Models\Media\Media */ + /** @var $media MediaModel */ $media = $this->getRepository()->find($id); if (!$media) { @@ -256,7 +256,7 @@ public function internalCreateMediaByFileLink($link, $albumId = -1) $media->setUserId(0); /** @var $album Album */ - $album = $this->getManager()->find('Shopware\Models\Media\Album', $albumId); + $album = $this->getManager()->find(Album::class, $albumId); if (!$album) { throw new ApiException\CustomValidationException( sprintf('Album by id %s not found', $albumId) @@ -430,8 +430,8 @@ protected function uploadBase64File($url, $destinationPath, $baseFilename) } /** - * @param array $params - * @param \Shopware\Models\Media\Media $media + * @param array $params + * @param MediaModel $media * * @throws \Shopware\Components\Api\Exception\CustomValidationException * @throws \Shopware\Components\Api\Exception\ParameterMissingException @@ -443,15 +443,15 @@ private function prepareMediaData($params, $media = null) { // in create mode, album is a required param if (!$media && (!isset($params['album']) || empty($params['album']))) { - throw new ApiException\ParameterMissingException(); + throw new ApiException\ParameterMissingException('album'); } if (!$media && (!isset($params['file']) || empty($params['file']))) { - throw new ApiException\ParameterMissingException(); + throw new ApiException\ParameterMissingException('file'); } if (!$media && (!isset($params['description']) || empty($params['description']))) { - throw new ApiException\ParameterMissingException(); + throw new ApiException\ParameterMissingException('description'); } if (!$media && (!isset($params['userId']) || empty($params['userId']))) { @@ -464,14 +464,14 @@ private function prepareMediaData($params, $media = null) // Check / set album if (isset($params['album'])) { - $album = Shopware()->Models()->find('\Shopware\Models\Media\Album', $params['album']); + $album = Shopware()->Models()->find(Album::class, $params['album']); if (!$album) { throw new ApiException\CustomValidationException(sprintf('Album by id %s not found', $params['album'])); } $params['album'] = $album; } - if (isset($params['file']) && !($params['file'] instanceof \Symfony\Component\HttpFoundation\File\File)) { + if (isset($params['file']) && !($params['file'] instanceof File)) { if (!isset($params['name'])) { $params['name'] = pathinfo($params['file'], PATHINFO_FILENAME); } @@ -486,7 +486,7 @@ private function prepareMediaData($params, $media = null) } else { $path = $params['file']; } - $params['file'] = new \Symfony\Component\HttpFoundation\File\File($path); + $params['file'] = new File($path); } return $params;