]> BookStack Code Mirror - bookstack/commitdiff
Queries: Addressed failing test cases from recent changes
authorDan Brown <redacted>
Thu, 8 Feb 2024 17:18:03 +0000 (17:18 +0000)
committerDan Brown <redacted>
Thu, 8 Feb 2024 17:18:03 +0000 (17:18 +0000)
app/Activity/Controllers/FavouriteController.php
app/Entities/Queries/BookQueries.php
app/Entities/Queries/BookshelfQueries.php
app/Entities/Queries/ChapterQueries.php
app/Entities/Queries/PageQueries.php
app/Entities/Tools/PageContent.php
app/Entities/Tools/PageEditorData.php
app/Entities/Tools/SiblingFetcher.php

index 3125a25ad33d313bb587df02ee804517ee81a68a..deeb4b0afb45265b635fc16c9ac454236ef1c19d 100644 (file)
@@ -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;
 
index 8f62e513c7c9d9ff4f90dcbfc37aaca9d40be26a..534640621eec1d206b05f2d4c12071850587a84c 100644 (file)
@@ -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
index 47ff068a93b4024d62495dfb43ad065462190a49..19717fb7cd4daf0bd8b3fd1d530dc6ffe239b49c 100644 (file)
@@ -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
index 34f762a158106f916abaea6a30789cce489f7736..53c5bc9d8423a7fe380d7eb67bd2cd9ab27ab040 100644 (file)
@@ -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
index 8fb02075ae37f796cf8aeb54c5cd27c98450368a..a5938f754ef8a418ba63e04134522a9e07dc0b9c 100644 (file)
@@ -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
index 88987f054e86685e9576920f2bb4a7e33c92dbb9..4f68b828fc56e794bfd196535e338d3632df4d98 100644 (file)
@@ -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)) {
index 20bf19eb2f4bc7a25b1935970624f427ebbe735d..f0bd235897d97017e45f0eb22fd37142cd1fa54d 100644 (file)
@@ -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;
index 7b8ac37ad8792429038bb9645355488d4dbcf853..34d0fc6b07e465c3bdc85dbaf7174fdc668ecf24 100644 (file)
@@ -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 {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.