]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/ChapterRepo.php
Update Ldap.php
[bookstack] / app / Repos / ChapterRepo.php
index 1a8cbdf0fdada690eae187ad5a6c9db4fd5e37ba..4c13b9aafd3c4c95d0c13367261629e43329cd3e 100644 (file)
@@ -98,8 +98,8 @@ class ChapterRepo extends EntityRepo
     {
         $chapter = $this->chapter->newInstance($input);
         $chapter->slug = $this->findSuitableSlug($chapter->name, $book->id);
-        $chapter->created_by = auth()->user()->id;
-        $chapter->updated_by = auth()->user()->id;
+        $chapter->created_by = user()->id;
+        $chapter->updated_by = user()->id;
         $chapter = $book->chapters()->save($chapter);
         $this->permissionService->buildJointPermissionsForEntity($chapter);
         return $chapter;
@@ -150,8 +150,7 @@ class ChapterRepo extends EntityRepo
      */
     public function findSuitableSlug($name, $bookId, $currentId = false)
     {
-        $slug = Str::slug($name);
-        if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
+        $slug = $this->nameToSlug($name);
         while ($this->doesSlugExist($slug, $bookId, $currentId)) {
             $slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
         }
@@ -195,11 +194,12 @@ class ChapterRepo extends EntityRepo
 
     /**
      * Changes the book relation of this chapter.
-     * @param         $bookId
+     * @param $bookId
      * @param Chapter $chapter
+     * @param bool $rebuildPermissions
      * @return Chapter
      */
-    public function changeBook($bookId, Chapter $chapter)
+    public function changeBook($bookId, Chapter $chapter, $rebuildPermissions = false)
     {
         $chapter->book_id = $bookId;
         // Update related activity
@@ -213,9 +213,12 @@ class ChapterRepo extends EntityRepo
         foreach ($chapter->pages as $page) {
             $this->pageRepo->changeBook($bookId, $page);
         }
-        // Update permissions
-        $chapter->load('book');
-        $this->permissionService->buildJointPermissionsForEntity($chapter->book);
+
+        // Update permissions if applicable
+        if ($rebuildPermissions) {
+            $chapter->load('book');
+            $this->permissionService->buildJointPermissionsForEntity($chapter->book);
+        }
 
         return $chapter;
     }