X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/cbff2c6035aa6204092b7b93061b1c941fb95eb8..refs/pull/261/head:/app/Repos/ImageRepo.php diff --git a/app/Repos/ImageRepo.php b/app/Repos/ImageRepo.php index 8dd4d346d..8ddde7b0f 100644 --- a/app/Repos/ImageRepo.php +++ b/app/Repos/ImageRepo.php @@ -4,7 +4,8 @@ use BookStack\Image; use BookStack\Page; use BookStack\Services\ImageService; -use BookStack\Services\RestrictionService; +use BookStack\Services\PermissionService; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Setting; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -13,21 +14,21 @@ class ImageRepo protected $image; protected $imageService; - protected $restictionService; + protected $restrictionService; protected $page; /** * ImageRepo constructor. * @param Image $image * @param ImageService $imageService - * @param RestrictionService $restrictionService + * @param PermissionService $permissionService * @param Page $page */ - public function __construct(Image $image, ImageService $imageService, RestrictionService $restrictionService, Page $page) + public function __construct(Image $image, ImageService $imageService, PermissionService $permissionService, Page $page) { $this->image = $image; $this->imageService = $imageService; - $this->restictionService = $restrictionService; + $this->restrictionService = $permissionService; $this->page = $page; } @@ -52,7 +53,7 @@ class ImageRepo */ private function returnPaginated($query, $page = 0, $pageSize = 24) { - $images = $this->restictionService->filterRelatedPages($query, 'images', 'uploaded_to'); + $images = $this->restrictionService->filterRelatedPages($query, 'images', 'uploaded_to'); $images = $images->orderBy('created_at', 'desc')->skip($pageSize * $page)->take($pageSize + 1)->get(); $hasMore = count($images) > $pageSize; @@ -191,7 +192,12 @@ class ImageRepo */ public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false) { - return $this->imageService->getThumbnail($image, $width, $height, $keepRatio); + try { + return $this->imageService->getThumbnail($image, $width, $height, $keepRatio); + } catch (FileNotFoundException $exception) { + $image->delete(); + return []; + } }