mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-16 13:31:25 +00:00
Queries: Addressed failing test cases from recent changes
This commit is contained in:
parent
ed21a6d798
commit
ed9c013f6e
8 changed files with 18 additions and 12 deletions
app
Activity/Controllers
Entities
|
@ -17,11 +17,11 @@ class FavouriteController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show a listing of all favourite items for the current user.
|
* 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;
|
$viewCount = 20;
|
||||||
$page = intval($request->get('page', 1));
|
$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;
|
$hasMoreLink = ($favourites->count() > $viewCount) ? url('/favourites?page=' . ($page + 1)) : null;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder;
|
||||||
class BookQueries implements ProvidesEntityQueries
|
class BookQueries implements ProvidesEntityQueries
|
||||||
{
|
{
|
||||||
protected static array $listAttributes = [
|
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
|
public function start(): Builder
|
||||||
|
|
|
@ -9,7 +9,8 @@ use Illuminate\Database\Eloquent\Builder;
|
||||||
class BookshelfQueries implements ProvidesEntityQueries
|
class BookshelfQueries implements ProvidesEntityQueries
|
||||||
{
|
{
|
||||||
protected static array $listAttributes = [
|
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
|
public function start(): Builder
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ChapterQueries implements ProvidesEntityQueries
|
||||||
{
|
{
|
||||||
protected static array $listAttributes = [
|
protected static array $listAttributes = [
|
||||||
'id', 'slug', 'name', 'description', 'priority',
|
'id', 'slug', 'name', 'description', 'priority',
|
||||||
'created_at', 'updated_at'
|
'book_id', 'created_at', 'updated_at', 'owned_by',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function start(): Builder
|
public function start(): Builder
|
||||||
|
|
|
@ -10,11 +10,12 @@ class PageQueries implements ProvidesEntityQueries
|
||||||
{
|
{
|
||||||
protected static array $contentAttributes = [
|
protected static array $contentAttributes = [
|
||||||
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
|
'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 = [
|
protected static array $listAttributes = [
|
||||||
'name', 'id', 'slug', 'book_id', 'chapter_id', 'draft',
|
'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
|
public function start(): Builder
|
||||||
|
|
|
@ -329,13 +329,14 @@ class PageContent
|
||||||
protected function getContentProviderClosure(bool $blankIncludes): Closure
|
protected function getContentProviderClosure(bool $blankIncludes): Closure
|
||||||
{
|
{
|
||||||
$contextPage = $this->page;
|
$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) {
|
if ($blankIncludes) {
|
||||||
return PageIncludeContent::fromHtmlAndTag('', $tag);
|
return PageIncludeContent::fromHtmlAndTag('', $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
$matchedPage = $this->pageQueries->findVisibleById($tag->getPageId());
|
$matchedPage = $queries->findVisibleById($tag->getPageId());
|
||||||
$content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag);
|
$content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag);
|
||||||
|
|
||||||
if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) {
|
if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) {
|
||||||
|
|
|
@ -38,7 +38,8 @@ class PageEditorData
|
||||||
$templates = $this->queries->pages->visibleTemplates()
|
$templates = $this->queries->pages->visibleTemplates()
|
||||||
->orderBy('name', 'asc')
|
->orderBy('name', 'asc')
|
||||||
->take(10)
|
->take(10)
|
||||||
->get();
|
->paginate()
|
||||||
|
->withPath('/templates');
|
||||||
|
|
||||||
$draftsEnabled = auth()->check();
|
$draftsEnabled = auth()->check();
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ class PageEditorData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a current draft version for this user
|
// 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)) {
|
if (!is_null($userDraft)) {
|
||||||
$page->forceFill($userDraft->only(['name', 'html', 'markdown']));
|
$page->forceFill($userDraft->only(['name', 'html', 'markdown']));
|
||||||
$isDraftRevision = true;
|
$isDraftRevision = true;
|
||||||
|
|
|
@ -14,6 +14,7 @@ class SiblingFetcher
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected EntityQueries $queries,
|
protected EntityQueries $queries,
|
||||||
|
protected ShelfContext $shelfContext,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ class SiblingFetcher
|
||||||
// Book
|
// Book
|
||||||
// Gets just the books in a shelf if shelf is in context
|
// Gets just the books in a shelf if shelf is in context
|
||||||
if ($entity instanceof Book) {
|
if ($entity instanceof Book) {
|
||||||
$contextShelf = (new ShelfContext())->getContextualShelfForBook($entity);
|
$contextShelf = $this->shelfContext->getContextualShelfForBook($entity);
|
||||||
if ($contextShelf) {
|
if ($contextShelf) {
|
||||||
$entities = $contextShelf->visibleBooks()->get();
|
$entities = $contextShelf->visibleBooks()->get();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue