Queries: Extracted static page,chapter,shelf queries to classes

This commit is contained in:
Dan Brown
2024-02-07 21:58:27 +00:00
parent 483410749b
commit 546cfb0dcc
15 changed files with 93 additions and 60 deletions

View File

@@ -3,6 +3,7 @@
namespace BookStack\Entities\Tools;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Queries\PageQueries;
use BookStack\Entities\Tools\Markdown\MarkdownToHtml;
use BookStack\Exceptions\ImageUploadException;
use BookStack\Facades\Theme;
@@ -21,9 +22,12 @@ use Illuminate\Support\Str;
class PageContent
{
protected PageQueries $pageQueries;
public function __construct(
protected Page $page
) {
$this->pageQueries = app()->make(PageQueries::class);
}
/**
@@ -331,7 +335,7 @@ class PageContent
return PageIncludeContent::fromHtmlAndTag('', $tag);
}
$matchedPage = Page::visible()->find($tag->getPageId());
$matchedPage = $this->pageQueries->findVisibleById($tag->getPageId());
$content = PageIncludeContent::fromHtmlAndTag($matchedPage->html ?? '', $tag);
if (Theme::hasListeners(ThemeEvents::PAGE_INCLUDE_PARSE)) {

View File

@@ -4,10 +4,16 @@ namespace BookStack\Entities\Tools;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Queries\BookshelfQueries;
class ShelfContext
{
protected $KEY_SHELF_CONTEXT_ID = 'context_bookshelf_id';
protected string $KEY_SHELF_CONTEXT_ID = 'context_bookshelf_id';
public function __construct(
protected BookshelfQueries $shelfQueries,
) {
}
/**
* Get the current bookshelf context for the given book.
@@ -20,8 +26,7 @@ class ShelfContext
return null;
}
/** @var Bookshelf $shelf */
$shelf = Bookshelf::visible()->find($contextBookshelfId);
$shelf = $this->shelfQueries->findVisibleById($contextBookshelfId);
$shelfContainsBook = $shelf && $shelf->contains($book);
return $shelfContainsBook ? $shelf : null;
@@ -30,7 +35,7 @@ class ShelfContext
/**
* Store the current contextual shelf ID.
*/
public function setShelfContext(int $shelfId)
public function setShelfContext(int $shelfId): void
{
session()->put($this->KEY_SHELF_CONTEXT_ID, $shelfId);
}
@@ -38,7 +43,7 @@ class ShelfContext
/**
* Clear the session stored shelf context id.
*/
public function clearShelfContext()
public function clearShelfContext(): void
{
session()->forget($this->KEY_SHELF_CONTEXT_ID);
}