+ /**
+ * Show the page for moving a chapter.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @return mixed
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function showMove($bookSlug, $chapterSlug) {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->setPageTitle(trans('entities.chapters_move_named', ['chapterName' => $chapter->getShortName()]));
+ $this->checkOwnablePermission('chapter-update', $chapter);
+ return view('chapters/move', [
+ 'chapter' => $chapter,
+ 'book' => $chapter->book
+ ]);
+ }
+
+ /**
+ * Perform the move action for a chapter.
+ * @param $bookSlug
+ * @param $chapterSlug
+ * @param Request $request
+ * @return mixed
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function move($bookSlug, $chapterSlug, Request $request) {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($chapter->getUrl());
+ }
+
+ $stringExploded = explode(':', $entitySelection);
+ $entityType = $stringExploded[0];
+ $entityId = intval($stringExploded[1]);
+
+ $parent = false;
+
+ if ($entityType == 'book') {
+ $parent = $this->entityRepo->getById('book', $entityId);
+ }
+
+ if ($parent === false || $parent === null) {
+ session()->flash('error', trans('errors.selected_book_not_found'));
+ return redirect()->back();
+ }
+
+ $this->entityRepo->changeBook('chapter', $parent->id, $chapter, true);
+ Activity::add($chapter, 'chapter_move', $chapter->book->id);
+ session()->flash('success', trans('entities.chapter_move_success', ['bookName' => $parent->name]));
+
+ return redirect($chapter->getUrl());
+ }
+