]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/PageController.php
edit summary
[bookstack] / app / Http / Controllers / PageController.php
index 28247185f44923d2bc34724b5160276f1901504a..f35834e6221ea73332b7e88b9187c73b899fb8a5 100644 (file)
@@ -72,7 +72,7 @@ class PageController extends Controller
         $this->checkOwnablePermission('page-create', $book);
         $this->setPageTitle('Edit Page Draft');
 
-        return view('pages/create', ['draft' => $draft, 'book' => $book]);
+        return view('pages/edit', ['page' => $draft, 'book' => $book, 'isDraft' => true]);
     }
 
     /**
@@ -92,7 +92,7 @@ class PageController extends Controller
 
         $draftPage = $this->pageRepo->getById($pageId, true);
 
-        $chapterId = $draftPage->chapter_id;
+        $chapterId = intval($draftPage->chapter_id);
         $parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
         $this->checkOwnablePermission('page-create', $parent);
 
@@ -221,8 +221,8 @@ class PageController extends Controller
         $updateTime = $draft->updated_at->timestamp;
         $utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
         return response()->json([
-            'status' => 'success',
-            'message' => 'Draft saved at ',
+            'status'    => 'success',
+            'message'   => 'Draft saved at ',
             'timestamp' => $utcUpdateTimestamp
         ]);
     }
@@ -451,7 +451,68 @@ class PageController extends Controller
     }
 
     /**
-     * Set the restrictions for this page.
+     * Show the view to choose a new parent to move a page into.
+     * @param $bookSlug
+     * @param $pageSlug
+     * @return mixed
+     * @throws NotFoundException
+     */
+    public function showMove($bookSlug, $pageSlug)
+    {
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+        $this->checkOwnablePermission('page-update', $page);
+        return view('pages/move', [
+            'book' => $book,
+            'page' => $page
+        ]);
+    }
+
+    /**
+     * Does the action of moving the location of a page
+     * @param $bookSlug
+     * @param $pageSlug
+     * @param Request $request
+     * @return mixed
+     * @throws NotFoundException
+     */
+    public function move($bookSlug, $pageSlug, Request $request)
+    {
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+        $this->checkOwnablePermission('page-update', $page);
+
+        $entitySelection = $request->get('entity_selection', null);
+        if ($entitySelection === null || $entitySelection === '') {
+            return redirect($page->getUrl());
+        }
+
+        $stringExploded = explode(':', $entitySelection);
+        $entityType = $stringExploded[0];
+        $entityId = intval($stringExploded[1]);
+
+        $parent = false;
+
+        if ($entityType == 'chapter') {
+            $parent = $this->chapterRepo->getById($entityId);
+        } else if ($entityType == 'book') {
+            $parent = $this->bookRepo->getById($entityId);
+        }
+
+        if ($parent === false || $parent === null) {
+            session()->flash('The selected Book or Chapter was not found');
+            return redirect()->back();
+        }
+
+        $this->pageRepo->changePageParent($page, $parent);
+        Activity::add($page, 'page_move', $page->book->id);
+        session()->flash('success', sprintf('Page moved to "%s"', $parent->name));
+
+        return redirect($page->getUrl());
+    }
+
+    /**
+     * Set the permissions for this page.
      * @param $bookSlug
      * @param $pageSlug
      * @param Request $request
@@ -462,8 +523,8 @@ class PageController extends Controller
         $book = $this->bookRepo->getBySlug($bookSlug);
         $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
         $this->checkOwnablePermission('restrictions-manage', $page);
-        $this->pageRepo->updateRestrictionsFromRequest($request, $page);
-        session()->flash('success', 'Page Restrictions Updated');
+        $this->pageRepo->updateEntityPermissionsFromRequest($request, $page);
+        session()->flash('success', 'Page Permissions Updated');
         return redirect($page->getUrl());
     }