X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3886aedf54873a1bf90cfdaa9cafc6f22c1d03fd..refs/pull/5721/head:/app/Entities/Repos/BookshelfRepo.php diff --git a/app/Entities/Repos/BookshelfRepo.php b/app/Entities/Repos/BookshelfRepo.php index 479e6178f..8e60f58c4 100644 --- a/app/Entities/Repos/BookshelfRepo.php +++ b/app/Entities/Repos/BookshelfRepo.php @@ -3,16 +3,19 @@ namespace BookStack\Entities\Repos; use BookStack\Activity\ActivityType; -use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; +use BookStack\Entities\Queries\BookQueries; use BookStack\Entities\Tools\TrashCan; use BookStack\Facades\Activity; +use BookStack\Util\DatabaseTransaction; use Exception; class BookshelfRepo { public function __construct( protected BaseRepo $baseRepo, + protected BookQueries $bookQueries, + protected TrashCan $trashCan, ) { } @@ -21,13 +24,14 @@ class BookshelfRepo */ public function create(array $input, array $bookIds): Bookshelf { - $shelf = new Bookshelf(); - $this->baseRepo->create($shelf, $input); - $this->baseRepo->updateCoverImage($shelf, $input['image'] ?? null); - $this->updateBooks($shelf, $bookIds); - Activity::add(ActivityType::BOOKSHELF_CREATE, $shelf); - - return $shelf; + return (new DatabaseTransaction(function () use ($input, $bookIds) { + $shelf = new Bookshelf(); + $this->baseRepo->create($shelf, $input); + $this->baseRepo->updateCoverImage($shelf, $input['image'] ?? null); + $this->updateBooks($shelf, $bookIds); + Activity::add(ActivityType::BOOKSHELF_CREATE, $shelf); + return $shelf; + }))->run(); } /** @@ -60,7 +64,7 @@ class BookshelfRepo return intval($id); }); - $syncData = Book::visible() + $syncData = $this->bookQueries->visibleForList() ->whereIn('id', $bookIds) ->pluck('id') ->mapWithKeys(function ($bookId) use ($numericIDs) { @@ -77,9 +81,8 @@ class BookshelfRepo */ public function destroy(Bookshelf $shelf) { - $trashCan = new TrashCan(); - $trashCan->softDestroyShelf($shelf); + $this->trashCan->softDestroyShelf($shelf); Activity::add(ActivityType::BOOKSHELF_DELETE, $shelf); - $trashCan->autoClearOld(); + $this->trashCan->autoClearOld(); } }