X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/9baa96d41ce6b4f7949c5a1f4b2b9fa699d3d679..refs/pull/236/head:/app/Http/Controllers/ChapterController.php diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php index a3a939f61..a3fb600fd 100644 --- a/app/Http/Controllers/ChapterController.php +++ b/app/Http/Controllers/ChapterController.php @@ -59,7 +59,7 @@ class ChapterController extends Controller $input = $request->all(); $input['priority'] = $this->bookRepo->getNewPriority($book); - $chapter = $this->chapterRepo->createFromInput($request->all(), $book); + $chapter = $this->chapterRepo->createFromInput($input, $book); Activity::add($chapter, 'chapter_create', $book->id); return redirect($chapter->getUrl()); } @@ -115,9 +115,11 @@ class ChapterController extends Controller $book = $this->bookRepo->getBySlug($bookSlug); $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); $this->checkOwnablePermission('chapter-update', $chapter); + if ($chapter->name !== $request->get('name')) { + $chapter->slug = $this->chapterRepo->findSuitableSlug($request->get('name'), $book->id, $chapter->id); + } $chapter->fill($request->all()); - $chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id, $chapter->id); - $chapter->updated_by = auth()->user()->id; + $chapter->updated_by = user()->id; $chapter->save(); Activity::add($chapter, 'chapter_update', $book->id); return redirect($chapter->getUrl()); @@ -171,6 +173,14 @@ class ChapterController extends Controller ]); } + /** + * 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) { $book = $this->bookRepo->getBySlug($bookSlug); $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id); @@ -196,7 +206,7 @@ class ChapterController extends Controller return redirect()->back(); } - $this->chapterRepo->changeBook($parent->id, $chapter); + $this->chapterRepo->changeBook($parent->id, $chapter, true); Activity::add($chapter, 'chapter_move', $chapter->book->id); session()->flash('success', sprintf('Chapter moved to "%s"', $parent->name));