From ed9c013f6e7ee7a7bfe1c67b4cb1a84ca198b7a6 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Thu, 8 Feb 2024 17:18:03 +0000 Subject: [PATCH] Queries: Addressed failing test cases from recent changes --- app/Activity/Controllers/FavouriteController.php | 4 ++-- app/Entities/Queries/BookQueries.php | 3 ++- app/Entities/Queries/BookshelfQueries.php | 3 ++- app/Entities/Queries/ChapterQueries.php | 2 +- app/Entities/Queries/PageQueries.php | 5 +++-- app/Entities/Tools/PageContent.php | 5 +++-- app/Entities/Tools/PageEditorData.php | 5 +++-- app/Entities/Tools/SiblingFetcher.php | 3 ++- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Activity/Controllers/FavouriteController.php b/app/Activity/Controllers/FavouriteController.php index 3125a25ad..deeb4b0af 100644 --- a/app/Activity/Controllers/FavouriteController.php +++ b/app/Activity/Controllers/FavouriteController.php @@ -17,11 +17,11 @@ class FavouriteController extends Controller /** * Show a listing of all favourite items for the current user. */ - public function index(Request $request) + public function index(Request $request, QueryTopFavourites $topFavourites) { $viewCount = 20; $page = intval($request->get('page', 1)); - $favourites = (new QueryTopFavourites())->run($viewCount + 1, (($page - 1) * $viewCount)); + $favourites = $topFavourites->run($viewCount + 1, (($page - 1) * $viewCount)); $hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null; diff --git a/app/Entities/Queries/BookQueries.php b/app/Entities/Queries/BookQueries.php index 8f62e513c..534640621 100644 --- a/app/Entities/Queries/BookQueries.php +++ b/app/Entities/Queries/BookQueries.php @@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder; class BookQueries implements ProvidesEntityQueries { protected static array $listAttributes = [ - 'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id' + 'id', 'slug', 'name', 'description', + 'created_at', 'updated_at', 'image_id', 'owned_by', ]; public function start(): Builder diff --git a/app/Entities/Queries/BookshelfQueries.php b/app/Entities/Queries/BookshelfQueries.php index 47ff068a9..19717fb7c 100644 --- a/app/Entities/Queries/BookshelfQueries.php +++ b/app/Entities/Queries/BookshelfQueries.php @@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder; class BookshelfQueries implements ProvidesEntityQueries { protected static array $listAttributes = [ - 'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id' + 'id', 'slug', 'name', 'description', + 'created_at', 'updated_at', 'image_id', 'owned_by', ]; public function start(): Builder diff --git a/app/Entities/Queries/ChapterQueries.php b/app/Entities/Queries/ChapterQueries.php index 34f762a15..53c5bc9d8 100644 --- a/app/Entities/Queries/ChapterQueries.php +++ b/app/Entities/Queries/ChapterQueries.php @@ -10,7 +10,7 @@ class ChapterQueries implements ProvidesEntityQueries { protected static array $listAttributes = [ 'id', 'slug', 'name', 'description', 'priority', - 'created_at', 'updated_at' + 'book_id', 'created_at', 'updated_at', 'owned_by', ]; public function start(): Builder diff --git a/app/Entities/Queries/PageQueries.php b/app/Entities/Queries/PageQueries.php index 8fb02075a..a5938f754 100644 --- a/app/Entities/Queries/PageQueries.php +++ b/app/Entities/Queries/PageQueries.php @@ -10,11 +10,12 @@ class PageQueries implements ProvidesEntityQueries { protected static array $contentAttributes = [ 'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft', - 'template', 'html', 'text', 'created_at', 'updated_at', 'priority' + 'template', 'html', 'text', 'created_at', 'updated_at', 'priority', + 'created_by', 'updated_by', 'owned_by', ]; protected static array $listAttributes = [ 'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft', - 'template', 'text', 'created_at', 'updated_at', 'priority' + 'template', 'text', 'created_at', 'updated_at', 'priority', 'owned_by', ]; public function start(): Builder diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php index 88987f054..4f68b828f 100644 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@ -329,13 +329,14 @@ class PageContent protected function getContentProviderClosure(bool $blankIncludes): Closure { $contextPage = $this->page; + $queries = $this->pageQueries; - return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage): PageIncludeContent { + return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage, $queries): PageIncludeContent { if ($blankIncludes) { return PageIncludeContent::fromHtmlAndTag('', $tag); } - $matchedPage = $this->pageQueries->findVisibleById($tag->getPageId()); + $matchedPage = $queries->findVisibleById($tag->getPageId()); $content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag); if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) { diff --git a/app/Entities/Tools/PageEditorData.php b/app/Entities/Tools/PageEditorData.php index 20bf19eb2..f0bd23589 100644 --- a/app/Entities/Tools/PageEditorData.php +++ b/app/Entities/Tools/PageEditorData.php @@ -38,7 +38,8 @@ class PageEditorData $templates = $this->queries->pages->visibleTemplates() ->orderBy('name', 'asc') ->take(10) - ->get(); + ->paginate() + ->withPath('/templates'); $draftsEnabled = auth()->check(); @@ -51,7 +52,7 @@ class PageEditorData } // Check for a current draft version for this user - $userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id)->first(); + $userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id); if (!is_null($userDraft)) { $page->forceFill($userDraft->only(['name', 'html', 'markdown'])); $isDraftRevision = true; diff --git a/app/Entities/Tools/SiblingFetcher.php b/app/Entities/Tools/SiblingFetcher.php index 7b8ac37ad..34d0fc6b0 100644 --- a/app/Entities/Tools/SiblingFetcher.php +++ b/app/Entities/Tools/SiblingFetcher.php @@ -14,6 +14,7 @@ class SiblingFetcher { public function __construct( protected EntityQueries $queries, + protected ShelfContext $shelfContext, ) { } @@ -38,7 +39,7 @@ class SiblingFetcher // Book // Gets just the books in a shelf if shelf is in context if ($entity instanceof Book) { - $contextShelf = (new ShelfContext())->getContextualShelfForBook($entity); + $contextShelf = $this->shelfContext->getContextualShelfForBook($entity); if ($contextShelf) { $entities = $contextShelf->visibleBooks()->get(); } else {