+
+ return redirect($chapter->book->getUrl());
+ }
+
+ /**
+ * Show the page for moving a chapter.
+ * @throws NotFoundException
+ */
+ public function showMove(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->setPageTitle(trans('entities.chapters_move_named', ['chapterName' => $chapter->getShortName()]));
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ $this->checkOwnablePermission('chapter-delete', $chapter);
+
+ return view('chapters.move', [
+ 'chapter' => $chapter,
+ 'book' => $chapter->book
+ ]);
+ }
+
+ /**
+ * Perform the move action for a chapter.
+ * @throws NotFoundException
+ */
+ public function move(Request $request, string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ $this->checkOwnablePermission('chapter-delete', $chapter);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($chapter->getUrl());
+ }
+
+ try {
+ $newBook = $this->chapterRepo->move($chapter, $entitySelection);
+ } catch (MoveOperationException $exception) {
+ $this->showErrorNotification(trans('errors.selected_book_not_found'));
+ return redirect()->back();
+ }
+
+ Activity::add($chapter, 'chapter_move', $newBook->id);
+
+ $this->showSuccessNotification(trans('entities.chapter_move_success', ['bookName' => $newBook->name]));
+ return redirect($chapter->getUrl());