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;
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,
+ ) {
}
/**
$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);
$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;