X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1a26b477827f2aeaa18647d2398d9340d26626f0..refs/pull/3918/head:/app/Entities/Tools/BookContents.php diff --git a/app/Entities/Tools/BookContents.php b/app/Entities/Tools/BookContents.php index 6f11e8cbe..f45bdfcc1 100644 --- a/app/Entities/Tools/BookContents.php +++ b/app/Entities/Tools/BookContents.php @@ -11,22 +11,15 @@ use Illuminate\Support\Collection; class BookContents { - /** - * @var Book - */ - protected $book; + protected Book $book; - /** - * BookContents constructor. - */ public function __construct(Book $book) { $this->book = $book; } /** - * Get the current priority of the last item - * at the top-level of the book. + * Get the current priority of the last item at the top-level of the book. */ public function getLastPriority(): int { @@ -188,7 +181,7 @@ class BookContents $model->changeBook($newBook->id); } - if ($chapterChanged) { + if ($model instanceof Page && $chapterChanged) { $model->chapter_id = $newChapter->id ?? 0; } @@ -242,7 +235,7 @@ class BookContents } $hasPageEditPermission = userCan('page-update', $model); - $newParentInRightLocation = ($newParent instanceof Book || $newParent->book_id === $newBook->id); + $newParentInRightLocation = ($newParent instanceof Book || ($newParent instanceof Chapter && $newParent->book_id === $newBook->id)); $newParentPermission = ($newParent instanceof Chapter) ? 'chapter-update' : 'book-update'; $hasNewParentPermission = userCan($newParentPermission, $newParent);