use DOMDocument;
use DOMElement;
use DOMXPath;
-use Illuminate\Support\Collection;
class PageRepo extends EntityRepo
{
* @return Page
* @throws \BookStack\Exceptions\NotFoundException
*/
- public function getPageBySlug(string $pageSlug, string $bookSlug)
+ public function getBySlug(string $pageSlug, string $bookSlug)
{
- return $this->getBySlug('page', $pageSlug, $bookSlug);
+ return $this->getEntityBySlug('page', $pageSlug, $bookSlug);
}
/**
$oldHtml = $page->html;
$oldName = $page->name;
- // Prevent slug being updated if no name change
- if ($page->name !== $input['name']) {
- $page->slug = $this->findSuitableSlug('page', $input['name'], $page->id, $book_id);
- }
-
// Save page tags if present
if (isset($input['tags'])) {
$this->tagRepo->saveTagsToEntity($page, $input['tags']);
$page->fill($input);
$page->html = $this->formatHtml($input['html']);
$page->text = $this->pageToPlainText($page);
+ $page->updated_by = $userId;
+ $page->revision_count++;
+
if (setting('app-editor') !== 'markdown') {
$page->markdown = '';
}
- $page->updated_by = $userId;
- $page->revision_count++;
+
+ if ($page->isDirty('name')) {
+ $page->refreshSlug();
+ }
+
$page->save();
// Remove all update drafts for this user & page.
}
$book->pages()->save($page);
- $page = $this->entityProvider->page->find($page->id);
- $this->permissionService->buildJointPermissionsForEntity($page);
+ $page->refresh()->rebuildPermissions();
return $page;
}
$draftPage->template = ($input['template'] === 'true');
}
- $draftPage->slug = $this->findSuitableSlug('page', $draftPage->name, false, $draftPage->book->id);
$draftPage->html = $this->formatHtml($input['html']);
$draftPage->text = $this->pageToPlainText($draftPage);
$draftPage->draft = false;
$draftPage->revision_count = 1;
-
+ $draftPage->refreshSlug();
$draftPage->save();
$this->savePageRevision($draftPage, trans('entities.pages_initial_revision'));
$this->searchService->indexEntity($draftPage);
return [];
}
- $tree = collect($headers)->map(function($header) {
+ $tree = collect($headers)->map(function ($header) {
$text = trim(str_replace("\xc2\xa0", '', $header->nodeValue));
$text = mb_substr($text, 0, 100);
'link' => '#' . $header->getAttribute('id'),
'text' => $text,
];
- })->filter(function($header) {
+ })->filter(function ($header) {
return mb_strlen($header['text']) > 0;
});
{
$page->revision_count++;
$this->savePageRevision($page);
+
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
$page->fill($revision->toArray());
- $page->slug = $this->findSuitableSlug('page', $page->name, $page->id, $book->id);
$page->text = $this->pageToPlainText($page);
$page->updated_by = user()->id;
+ $page->refreshSlug();
$page->save();
+
$this->searchService->indexEntity($page);
return $page;
}
* Change the page's parent to the given entity.
* @param Page $page
* @param Entity $parent
- * @throws \Throwable
*/
public function changePageParent(Page $page, Entity $parent)
{
$book = $parent->isA('book') ? $parent : $parent->book;
$page->chapter_id = $parent->isA('chapter') ? $parent->id : 0;
$page->save();
+
if ($page->book->id !== $book->id) {
- $page = $this->changeBook('page', $book->id, $page);
+ $page = $this->changeBook($page, $book->id);
}
+
$page->load('book');
- $this->permissionService->buildJointPermissionsForEntity($book);
+ $book->rebuildPermissions();
}
/**
* @param string $search
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
- public function getPageTemplates(int $count = 10, int $page = 1, string $search = '')
+ public function getPageTemplates(int $count = 10, int $page = 1, string $search = '')
{
$query = $this->entityQuery('page')
->where('template', '=', true)
->orderBy('name', 'asc')
- ->skip( ($page - 1) * $count)
+ ->skip(($page - 1) * $count)
->take($count);
if ($search) {