]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/PageRepo.php
replace GPL diff lib with MIT lib
[bookstack] / app / Repos / PageRepo.php
index 504c3fa3b6f549e0facbaa991e863e80c3a1bcdb..de050e1c7cb8ad245157f81316c6305c2fdff87a 100644 (file)
@@ -3,6 +3,7 @@
 use Activity;
 use BookStack\Book;
 use BookStack\Chapter;
+use BookStack\Entity;
 use BookStack\Exceptions\NotFoundException;
 use Carbon\Carbon;
 use DOMDocument;
@@ -572,6 +573,22 @@ class PageRepo extends EntityRepo
         return $page;
     }
 
+
+    /**
+     * Change the page's parent to the given entity.
+     * @param Page $page
+     * @param Entity $parent
+     */
+    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();
+        $page = $this->changeBook($book->id, $page);
+        $page->load('book');
+        $this->permissionService->buildJointPermissionsForEntity($book);
+    }
+
     /**
      * Gets a suitable slug for the resource
      * @param            $name