X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/857d9ed3f129e1278973939ca10f3358d447effe..refs/pull/2511/head:/app/Entities/Repos/PageRepo.php diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 8840c06db..ca5748c86 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -210,17 +210,17 @@ class PageRepo } $pageContent = new PageContent($page); - if (isset($input['html'])) { - $pageContent->setNewHTML($input['html']); - } else { + if (!empty($input['markdown'] ?? '')) { $pageContent->setNewMarkdown($input['markdown']); + } else { + $pageContent->setNewHTML($input['html']); } } /** * Saves a page revision into the system. */ - protected function savePageRevision(Page $page, string $summary = null) + protected function savePageRevision(Page $page, string $summary = null): PageRevision { $revision = new PageRevision($page->getAttributes()); @@ -286,17 +286,19 @@ class PageRepo public function restoreRevision(Page $page, int $revisionId): Page { $page->revision_count++; - $this->savePageRevision($page); - $revision = $page->revisions()->where('id', '=', $revisionId)->first(); + $page->fill($revision->toArray()); $content = new PageContent($page); $content->setNewHTML($revision->html); $page->updated_by = user()->id; $page->refreshSlug(); $page->save(); - $page->indexForSearch(); + + $summary = trans('entities.pages_revision_restored_from', ['id' => strval($revisionId), 'summary' => $revision->summary]); + $this->savePageRevision($page, $summary); + Activity::addForEntity($page, ActivityType::PAGE_RESTORE); return $page; } @@ -465,4 +467,10 @@ class PageRepo ->where('page_id', '=', $page->id) ->orderBy('created_at', 'desc'); } + /** + * Get page details by chapter ID. + */ + public function getPageByChapterID(int $id){ + return Page::visible()->where('chapter_id', '=', $id)->get(['id','slug']); + } }