From: jakob Date: Mon, 28 Oct 2019 14:33:28 +0000 (+0100) Subject: Check if parent is a chapter. If so, move into Book and assing page to chapter. X-Git-Tag: v0.28.0~1^2~49^2~1^2~1 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/4daeb9daa6c980d97126293c972245d8e08711e8 Check if parent is a chapter. If so, move into Book and assing page to chapter. --- diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 0fc68f953..5d6fc8fa8 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -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;