3 namespace BookStack\Entities\Repos;
5 use BookStack\Activity\ActivityType;
6 use BookStack\Activity\TagRepo;
7 use BookStack\Entities\Models\Book;
8 use BookStack\Entities\Tools\TrashCan;
9 use BookStack\Exceptions\ImageUploadException;
10 use BookStack\Facades\Activity;
11 use BookStack\Uploads\ImageRepo;
13 use Illuminate\Http\UploadedFile;
17 public function __construct(
18 protected BaseRepo $baseRepo,
19 protected TagRepo $tagRepo,
20 protected ImageRepo $imageRepo,
21 protected TrashCan $trashCan,
26 * Create a new book in the system.
28 public function create(array $input): Book
31 $this->baseRepo->create($book, $input);
32 $this->baseRepo->updateCoverImage($book, $input['image'] ?? null);
33 $this->baseRepo->updateDefaultTemplate($book, intval($input['default_template_id'] ?? null));
34 Activity::add(ActivityType::BOOK_CREATE, $book);
40 * Update the given book.
42 public function update(Book $book, array $input): Book
44 $this->baseRepo->update($book, $input);
46 if (array_key_exists('default_template_id', $input)) {
47 $this->baseRepo->updateDefaultTemplate($book, intval($input['default_template_id']));
50 if (array_key_exists('image', $input)) {
51 $this->baseRepo->updateCoverImage($book, $input['image'], $input['image'] === null);
54 Activity::add(ActivityType::BOOK_UPDATE, $book);
60 * Update the given book's cover image, or clear it.
62 * @throws ImageUploadException
65 public function updateCoverImage(Book $book, ?UploadedFile $coverImage, bool $removeImage = false)
67 $this->baseRepo->updateCoverImage($book, $coverImage, $removeImage);
71 * Remove a book from the system.
75 public function destroy(Book $book)
77 $this->trashCan->softDestroyBook($book);
78 Activity::add(ActivityType::BOOK_DELETE, $book);
80 $this->trashCan->autoClearOld();