Skip to content

Commit ed9c013

Browse files
committed
Queries: Addressed failing test cases from recent changes
1 parent ed21a6d commit ed9c013

File tree

8 files changed

+18
-12
lines changed

8 files changed

+18
-12
lines changed

app/Activity/Controllers/FavouriteController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public function __construct(
1717
/**
1818
* Show a listing of all favourite items for the current user.
1919
*/
20-
public function index(Request $request)
20+
public function index(Request $request, QueryTopFavourites $topFavourites)
2121
{
2222
$viewCount = 20;
2323
$page = intval($request->get('page', 1));
24-
$favourites = (new QueryTopFavourites())->run($viewCount + 1, (($page - 1) * $viewCount));
24+
$favourites = $topFavourites->run($viewCount + 1, (($page - 1) * $viewCount));
2525

2626
$hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null;
2727

app/Entities/Queries/BookQueries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
class BookQueries implements ProvidesEntityQueries
1010
{
1111
protected static array $listAttributes = [
12-
'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id'
12+
'id', 'slug', 'name', 'description',
13+
'created_at', 'updated_at', 'image_id', 'owned_by',
1314
];
1415

1516
public function start(): Builder

app/Entities/Queries/BookshelfQueries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
class BookshelfQueries implements ProvidesEntityQueries
1010
{
1111
protected static array $listAttributes = [
12-
'id', 'slug', 'name', 'description', 'created_at', 'updated_at', 'image_id'
12+
'id', 'slug', 'name', 'description',
13+
'created_at', 'updated_at', 'image_id', 'owned_by',
1314
];
1415

1516
public function start(): Builder

app/Entities/Queries/ChapterQueries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ChapterQueries implements ProvidesEntityQueries
1010
{
1111
protected static array $listAttributes = [
1212
'id', 'slug', 'name', 'description', 'priority',
13-
'created_at', 'updated_at'
13+
'book_id', 'created_at', 'updated_at', 'owned_by',
1414
];
1515

1616
public function start(): Builder

app/Entities/Queries/PageQueries.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ class PageQueries implements ProvidesEntityQueries
1010
{
1111
protected static array $contentAttributes = [
1212
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
13-
'template', 'html', 'text', 'created_at', 'updated_at', 'priority'
13+
'template', 'html', 'text', 'created_at', 'updated_at', 'priority',
14+
'created_by', 'updated_by', 'owned_by',
1415
];
1516
protected static array $listAttributes = [
1617
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
17-
'template', 'text', 'created_at', 'updated_at', 'priority'
18+
'template', 'text', 'created_at', 'updated_at', 'priority', 'owned_by',
1819
];
1920

2021
public function start(): Builder

app/Entities/Tools/PageContent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,14 @@ public function render(bool $blankIncludes = false): string
329329
protected function getContentProviderClosure(bool $blankIncludes): Closure
330330
{
331331
$contextPage = $this->page;
332+
$queries = $this->pageQueries;
332333

333-
return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage): PageIncludeContent {
334+
return function (PageIncludeTag $tag) use ($blankIncludes, $contextPage, $queries): PageIncludeContent {
334335
if ($blankIncludes) {
335336
return PageIncludeContent::fromHtmlAndTag('', $tag);
336337
}
337338

338-
$matchedPage = $this->pageQueries->findVisibleById($tag->getPageId());
339+
$matchedPage = $queries->findVisibleById($tag->getPageId());
339340
$content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag);
340341

341342
if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) {

app/Entities/Tools/PageEditorData.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected function build(): array
3838
$templates = $this->queries->pages->visibleTemplates()
3939
->orderBy('name', 'asc')
4040
->take(10)
41-
->get();
41+
->paginate()
42+
->withPath('/templates');
4243

4344
$draftsEnabled = auth()->check();
4445

@@ -51,7 +52,7 @@ protected function build(): array
5152
}
5253

5354
// Check for a current draft version for this user
54-
$userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id)->first();
55+
$userDraft = $this->queries->revisions->findLatestCurrentUserDraftsForPageId($page->id);
5556
if (!is_null($userDraft)) {
5657
$page->forceFill($userDraft->only(['name', 'html', 'markdown']));
5758
$isDraftRevision = true;

app/Entities/Tools/SiblingFetcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class SiblingFetcher
1414
{
1515
public function __construct(
1616
protected EntityQueries $queries,
17+
protected ShelfContext $shelfContext,
1718
) {
1819
}
1920

@@ -38,7 +39,7 @@ public function fetch(string $entityType, int $entityId): Collection
3839
// Book
3940
// Gets just the books in a shelf if shelf is in context
4041
if ($entity instanceof Book) {
41-
$contextShelf = (new ShelfContext())->getContextualShelfForBook($entity);
42+
$contextShelf = $this->shelfContext->getContextualShelfForBook($entity);
4243
if ($contextShelf) {
4344
$entities = $contextShelf->visibleBooks()->get();
4445
} else {

0 commit comments

Comments
 (0)