- $chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
- $this->checkOwnablePermission('restrictions-manage', $chapter);
- $this->entityRepo->updateEntityPermissionsFromRequest($request, $chapter);
- $this->showSuccessNotification( trans('entities.chapters_permissions_success'));
- return redirect($chapter->getUrl());
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->checkOwnablePermission('chapter-view', $chapter);
+
+ $entitySelection = $request->get('entity_selection') ?: null;
+ $newParentBook = $entitySelection ? $this->chapterRepo->findParentByIdentifier($entitySelection) : $chapter->getParent();
+
+ if (is_null($newParentBook)) {
+ $this->showErrorNotification(trans('errors.selected_book_not_found'));
+
+ return redirect()->back();
+ }
+
+ $this->checkOwnablePermission('chapter-create', $newParentBook);
+
+ $newName = $request->get('name') ?: $chapter->name;
+ $chapterCopy = $cloner->cloneChapter($chapter, $newParentBook, $newName);
+ $this->showSuccessNotification(trans('entities.chapters_copy_success'));
+
+ return redirect($chapterCopy->getUrl());
+ }
+
+ /**
+ * Convert the chapter to a book.
+ */
+ public function convertToBook(HierarchyTransformer $transformer, string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ $this->checkOwnablePermission('chapter-delete', $chapter);
+ $this->checkPermission('book-create-all');
+
+ $book = $transformer->transformChapterToBook($chapter);
+
+ return redirect($book->getUrl());