]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/EntityRepo.php
#47 - Fixes the issues with the test case.
[bookstack] / app / Repos / EntityRepo.php
index f1041f126bd5477dcb4e41189a4c75ffe38a66d2..7bc5fc4fc159f2a2984e8b2fe62eda5593416b44 100644 (file)
@@ -348,6 +348,10 @@ class EntityRepo
         foreach ($entities as $entity) {
             if ($entity->chapter_id === 0 || $entity->chapter_id === '0') continue;
             $parentKey = 'BookStack\\Chapter:' . $entity->chapter_id;
+            if (!isset($parents[$parentKey])) {
+                $tree[] = $entity;
+                continue;
+            }
             $chapter = $parents[$parentKey];
             $chapter->pages->push($entity);
         }
@@ -529,11 +533,11 @@ class EntityRepo
 
     /**
      * Alias method to update the book jointPermissions in the PermissionService.
-     * @param Collection $collection collection on entities
+     * @param Book $book
      */
-    public function buildJointPermissions(Collection $collection)
+    public function buildJointPermissionsForBook(Book $book)
     {
-        $this->permissionService->buildJointPermissionsForEntities($collection);
+        $this->permissionService->buildJointPermissionsForEntity($book);
     }
 
     /**
@@ -726,6 +730,7 @@ class EntityRepo
         if ($chapter) $page->chapter_id = $chapter->id;
 
         $book->pages()->save($page);
+        $page = $this->page->find($page->id);
         $this->permissionService->buildJointPermissionsForEntity($page);
         return $page;
     }