use BookStack\Uploads\AttachmentService;
use BookStack\Uploads\ImageService;
use Exception;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
class TrashCan
{
$count = 0;
$pages = $chapter->pages()->withTrashed()->get();
- if (count($pages)) {
- foreach ($pages as $page) {
- $this->destroyPage($page);
- $count++;
- }
+ foreach ($pages as $page) {
+ $this->destroyPage($page);
+ $count++;
}
$this->destroyCommonRelations($chapter);
{
$counts = [];
- /** @var Entity $instance */
foreach ((new EntityProvider())->all() as $key => $instance) {
- $counts[$key] = $instance->newQuery()->onlyTrashed()->count();
+ /** @var Builder<Entity> $query */
+ $query = $instance->newQuery();
+ $counts[$key] = $query->onlyTrashed()->count();
}
return $counts;
{
$shouldRestore = true;
$restoreCount = 0;
- $parent = $deletion->deletable->getParent();
- if ($parent && $parent->trashed()) {
- $shouldRestore = false;
+ if ($deletion->deletable instanceof Entity) {
+ $parent = $deletion->deletable->getParent();
+ if ($parent && $parent->trashed()) {
+ $shouldRestore = false;
+ }
}
- if ($shouldRestore) {
+ if ($deletion->deletable instanceof Entity && $shouldRestore) {
$restoreCount = $this->restoreEntity($deletion->deletable);
}
if ($entity instanceof Bookshelf) {
return $this->destroyShelf($entity);
}
+
+ return 0;
}
/**
$entity->deletions()->delete();
$entity->favourites()->delete();
- if ($entity instanceof HasCoverImage && $entity->cover) {
+ if ($entity instanceof HasCoverImage && $entity->cover()->exists()) {
$imageService = app()->make(ImageService::class);
- $imageService->destroy($entity->cover);
+ $imageService->destroy($entity->cover()->first());
}
}
}