]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Tools/HierarchyTransformer.php
ZIP Imports: Added API examples, finished testing
[bookstack] / app / Entities / Tools / HierarchyTransformer.php
index 93c5bb9bb7103fb12ab3a60f2d76ebc0d75b22fc..b0d8880f402ecb0efd2a1241cd7d750312061d4e 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace BookStack\Entities\Tools;
 
-use BookStack\Actions\ActivityType;
+use BookStack\Activity\ActivityType;
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
 use BookStack\Entities\Models\Chapter;
@@ -13,17 +13,12 @@ use BookStack\Facades\Activity;
 
 class HierarchyTransformer
 {
-    protected BookRepo $bookRepo;
-    protected BookshelfRepo $shelfRepo;
-    protected Cloner $cloner;
-    protected TrashCan $trashCan;
-
-    public function __construct(BookRepo $bookRepo, BookshelfRepo $shelfRepo, Cloner $cloner, TrashCan $trashCan)
-    {
-        $this->bookRepo = $bookRepo;
-        $this->shelfRepo = $shelfRepo;
-        $this->cloner = $cloner;
-        $this->trashCan = $trashCan;
+    public function __construct(
+        protected BookRepo $bookRepo,
+        protected BookshelfRepo $shelfRepo,
+        protected Cloner $cloner,
+        protected TrashCan $trashCan
+    ) {
     }
 
     /**
@@ -45,6 +40,7 @@ class HierarchyTransformer
         $this->trashCan->destroyEntity($chapter);
 
         Activity::add(ActivityType::BOOK_CREATE_FROM_CHAPTER, $book);
+
         return $book;
     }
 
@@ -64,7 +60,7 @@ class HierarchyTransformer
         foreach ($book->chapters as $index => $chapter) {
             $newBook = $this->transformChapterToBook($chapter);
             $shelfBookSyncData[$newBook->id] = ['order' => $index];
-            if (!$newBook->restricted) {
+            if (!$newBook->hasPermissions()) {
                 $this->cloner->copyEntityPermissions($shelf, $newBook);
             }
         }
@@ -80,6 +76,7 @@ class HierarchyTransformer
         $shelf->books()->sync($shelfBookSyncData);
 
         Activity::add(ActivityType::BOOKSHELF_CREATE_FROM_BOOK, $shelf);
+
         return $shelf;
     }
-}
\ No newline at end of file
+}