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
{
$model->changeBook($newBook->id);
}
- if ($chapterChanged) {
+ if ($model instanceof Page && $chapterChanged) {
$model->chapter_id = $newChapter->id ?? 0;
}
}
$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);