namespace BookStack\Uploads;
-use BookStack\Entities\Models\Page;
+use BookStack\Entities\Queries\PageQueries;
use BookStack\Exceptions\ImageUploadException;
use BookStack\Permissions\PermissionApplicator;
use Exception;
protected ImageService $imageService,
protected PermissionApplicator $permissions,
protected ImageResizer $imageResizer,
+ protected PageQueries $pageQueries,
) {
}
*/
public function getEntityFiltered(
string $type,
- string $filterType = null,
- int $page = 0,
- int $pageSize = 24,
- int $uploadedTo = null,
- string $search = null
+ ?string $filterType,
+ int $page,
+ int $pageSize,
+ int $uploadedTo,
+ ?string $search
): array {
- /** @var Page $contextPage */
- $contextPage = Page::visible()->findOrFail($uploadedTo);
+ $contextPage = $this->pageQueries->findVisibleByIdOrFail($uploadedTo);
$parentFilter = null;
if ($filterType === 'book' || $filterType === 'page') {
*/
public function updateImageFile(Image $image, UploadedFile $file): void
{
- if ($file->getClientOriginalExtension() !== pathinfo($image->path, PATHINFO_EXTENSION)) {
+ if (strtolower($file->getClientOriginalExtension()) !== strtolower(pathinfo($image->path, PATHINFO_EXTENSION))) {
throw new ImageUploadException(trans('errors.image_upload_replace_type'));
}
*/
public function getPagesUsingImage(Image $image): array
{
- $pages = Page::visible()
+ $pages = $this->pageQueries->visibleForList()
->where('html', 'like', '%' . $image->url . '%')
- ->get(['id', 'name', 'slug', 'book_id']);
+ ->get();
foreach ($pages as $page) {
$page->setAttribute('url', $page->getUrl());