X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/222c665018cd7fc231d2970307e3a7423e4a377f..b80992ca59a4803fe81d577add6a0611e976c83b:/app/Entities/Controllers/BookController.php diff --git a/app/Entities/Controllers/BookController.php b/app/Entities/Controllers/BookController.php index 0e9346dbd..b1685081a 100644 --- a/app/Entities/Controllers/BookController.php +++ b/app/Entities/Controllers/BookController.php @@ -6,8 +6,8 @@ use BookStack\Activity\ActivityQueries; use BookStack\Activity\ActivityType; use BookStack\Activity\Models\View; use BookStack\Activity\Tools\UserEntityWatchOptions; -use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Queries\BookQueries; +use BookStack\Entities\Queries\BookshelfQueries; use BookStack\Entities\Repos\BookRepo; use BookStack\Entities\Tools\BookContents; use BookStack\Entities\Tools\Cloner; @@ -29,6 +29,7 @@ class BookController extends Controller protected ShelfContext $shelfContext, protected BookRepo $bookRepo, protected BookQueries $queries, + protected BookshelfQueries $shelfQueries, protected ReferenceFetcher $referenceFetcher, ) { } @@ -69,13 +70,13 @@ class BookController extends Controller /** * Show the form for creating a new book. */ - public function create(string $shelfSlug = null) + public function create(?string $shelfSlug = null) { $this->checkPermission('book-create-all'); $bookshelf = null; if ($shelfSlug !== null) { - $bookshelf = Bookshelf::visible()->where('slug', '=', $shelfSlug)->firstOrFail(); + $bookshelf = $this->shelfQueries->findVisibleBySlugOrFail($shelfSlug); $this->checkOwnablePermission('bookshelf-update', $bookshelf); } @@ -92,7 +93,7 @@ class BookController extends Controller * @throws ImageUploadException * @throws ValidationException */ - public function store(Request $request, string $shelfSlug = null) + public function store(Request $request, ?string $shelfSlug = null) { $this->checkPermission('book-create-all'); $validated = $this->validate($request, [ @@ -105,7 +106,7 @@ class BookController extends Controller $bookshelf = null; if ($shelfSlug !== null) { - $bookshelf = Bookshelf::visible()->where('slug', '=', $shelfSlug)->firstOrFail(); + $bookshelf = $this->shelfQueries->findVisibleBySlugOrFail($shelfSlug); $this->checkOwnablePermission('bookshelf-update', $bookshelf); }