X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/22a91c955d8258c73dd5dbcf7f46cc302d31c4bd..refs/pull/5721/head:/app/Entities/Tools/Cloner.php diff --git a/app/Entities/Tools/Cloner.php b/app/Entities/Tools/Cloner.php index 52a8f4cf0..2be6083e3 100644 --- a/app/Entities/Tools/Cloner.php +++ b/app/Entities/Tools/Cloner.php @@ -2,11 +2,12 @@ namespace BookStack\Entities\Tools; -use BookStack\Actions\Tag; +use BookStack\Activity\Models\Tag; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Entity; +use BookStack\Entities\Models\HasCoverImage; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\BookRepo; use BookStack\Entities\Repos\ChapterRepo; @@ -17,17 +18,12 @@ use Illuminate\Http\UploadedFile; class Cloner { - protected PageRepo $pageRepo; - protected ChapterRepo $chapterRepo; - protected BookRepo $bookRepo; - protected ImageService $imageService; - - public function __construct(PageRepo $pageRepo, ChapterRepo $chapterRepo, BookRepo $bookRepo, ImageService $imageService) - { - $this->pageRepo = $pageRepo; - $this->chapterRepo = $chapterRepo; - $this->bookRepo = $bookRepo; - $this->imageService = $imageService; + public function __construct( + protected PageRepo $pageRepo, + protected ChapterRepo $chapterRepo, + protected BookRepo $bookRepo, + protected ImageService $imageService, + ) { } /** @@ -76,7 +72,7 @@ class Cloner $copyBook = $this->bookRepo->create($bookDetails); // Clone contents - $directChildren = $original->getDirectChildren(); + $directChildren = $original->getDirectVisibleChildren(); foreach ($directChildren as $child) { if ($child instanceof Chapter && userCan('chapter-create', $copyBook)) { $this->cloneChapter($child, $copyBook, $child->name); @@ -109,9 +105,11 @@ class Cloner $inputData['tags'] = $this->entityTagsToInputArray($entity); // Add a cover to the data if existing on the original entity - if ($entity->cover instanceof Image) { - $uploadedFile = $this->imageToUploadedFile($entity->cover); - $inputData['image'] = $uploadedFile; + if ($entity instanceof HasCoverImage) { + $cover = $entity->cover()->first(); + if ($cover) { + $inputData['image'] = $this->imageToUploadedFile($cover); + } } return $inputData;