]> BookStack Code Mirror - bookstack/commitdiff
Check if parent is a chapter. If so, move into Book and assing page to chapter.
authorjakob <redacted>
Mon, 28 Oct 2019 14:33:28 +0000 (15:33 +0100)
committerjakob <redacted>
Mon, 28 Oct 2019 14:33:28 +0000 (15:33 +0100)
app/Entities/Repos/PageRepo.php

index 0fc68f95345189d6767087f04db9ec5ace2bb673..5d6fc8fa81a5afbb8c3f5ac7f6fbf902dbff45f2 100644 (file)
@@ -306,6 +306,13 @@ class PageRepo
             throw new PermissionsException('User does not have permission to create a page within the new parent');
         }
 
+        if ($parent instanceof Chapter) {
+            $parentChapter = $parent;
+            $parent = $parent->book;
+            $page->chapter_id = $parentChapter->id;
+            $page->save();
+        }
+
         $page->changeBook($parent instanceof Book ? $parent->id : $parent->book->id);
         $page->rebuildPermissions();
         return $parent;