X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1d1cc19596ac30d40a74ee751011b9bac038c47c..refs/pull/714/head:/app/Services/ImageService.php diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index 5eea285e5..9755ea307 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -102,7 +102,9 @@ class ImageService extends UploadService { $imageName = $imageName ? $imageName : basename($url); $imageData = file_get_contents($url); - if($imageData === false) throw new \Exception(trans('errors.cannot_get_image_from_url', ['url' => $url])); + if ($imageData === false) { + throw new \Exception(trans('errors.cannot_get_image_from_url', ['url' => $url])); + } return $this->saveNew($imageName, $imageData, $type); } @@ -121,7 +123,9 @@ class ImageService extends UploadService $secureUploads = setting('app-secure-images'); $imageName = str_replace(' ', '-', $imageName); - if ($secureUploads) $imageName = str_random(16) . '-' . $imageName; + if ($secureUploads) { + $imageName = str_random(16) . '-' . $imageName; + } $imagePath = '/uploads/images/' . $type . '/' . Date('Y-m-M') . '/'; @@ -236,6 +240,7 @@ class ImageService extends UploadService * Destroys an Image object along with its files and thumbnails. * @param Image $image * @return bool + * @throws Exception */ public function destroyImage(Image $image) { @@ -254,9 +259,13 @@ class ImageService extends UploadService // Cleanup of empty folders foreach ($storage->directories($imageFolder) as $directory) { - if ($this->isFolderEmpty($directory)) $storage->deleteDirectory($directory); + if ($this->isFolderEmpty($directory)) { + $storage->deleteDirectory($directory); + } + } + if ($this->isFolderEmpty($imageFolder)) { + $storage->deleteDirectory($imageFolder); } - if ($this->isFolderEmpty($imageFolder)) $storage->deleteDirectory($imageFolder); $image->delete(); return true; @@ -307,6 +316,4 @@ class ImageService extends UploadService $basePath = ($this->storageUrl == false) ? baseUrl('/') : $this->storageUrl; return rtrim($basePath, '/') . $filePath; } - - }