]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Repos/PageRepo.php
Add prev and next button to navigate through different pages
[bookstack] / app / Entities / Repos / PageRepo.php
index 60ae855109a469ab9e3b94508c0a57c85af0b1e7..ca5748c86569fcf1a388ea91a63ca60174c8c189 100644 (file)
@@ -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());
 
@@ -287,8 +287,6 @@ class PageRepo
     {
         $page->revision_count++;
         $revision = $page->revisions()->where('id', '=', $revisionId)->first();
-        $summary = trans('entities.pages_revision_restored_from', ['id' => strval($revisionId), 'summary' => $revision->summary]);
-        $this->savePageRevision($page, $summary);
 
         $page->fill($revision->toArray());
         $content = new PageContent($page);
@@ -296,8 +294,11 @@ class PageRepo
         $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;
     }
@@ -466,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']);
+    }
 }