-<?php namespace BookStack\Entities\Tools;
+<?php
+namespace BookStack\Entities\Tools;
+
+use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Deletion;
use BookStack\Entities\Models\Entity;
-use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\HasCoverImage;
use BookStack\Entities\Models\Page;
use BookStack\Exceptions\NotifyException;
class TrashCan
{
-
/**
* Send a shelf to the recycle bin.
*/
/**
* Send a book to the recycle bin.
+ *
* @throws Exception
*/
public function softDestroyBook(Book $book)
/**
* Send a chapter to the recycle bin.
+ *
* @throws Exception
*/
public function softDestroyChapter(Chapter $chapter, bool $recordDelete = true)
/**
* Send a page to the recycle bin.
+ *
* @throws Exception
*/
public function softDestroyPage(Page $page, bool $recordDelete = true)
/**
* Remove a bookshelf from the system.
+ *
* @throws Exception
*/
protected function destroyShelf(Bookshelf $shelf): int
{
$this->destroyCommonRelations($shelf);
$shelf->forceDelete();
+
return 1;
}
/**
* Remove a book from the system.
* Destroys any child chapters and pages.
+ *
* @throws Exception
*/
protected function destroyBook(Book $book): int
$this->destroyCommonRelations($book);
$book->forceDelete();
+
return $count + 1;
}
/**
* Remove a chapter from the system.
* Destroys all pages within.
+ *
* @throws Exception
*/
protected function destroyChapter(Chapter $chapter): int
$this->destroyCommonRelations($chapter);
$chapter->forceDelete();
+
return $count + 1;
}
/**
* Remove a page from the system.
+ *
* @throws Exception
*/
protected function destroyPage(Page $page): int
}
$page->forceDelete();
+
return 1;
}
$counts = [];
/** @var Entity $instance */
- foreach ((new EntityProvider)->all() as $key => $instance) {
+ foreach ((new EntityProvider())->all() as $key => $instance) {
$counts[$key] = $instance->newQuery()->onlyTrashed()->count();
}
/**
* Destroy all items that have pending deletions.
+ *
* @throws Exception
*/
public function empty(): int
foreach ($deletions as $deletion) {
$deleteCount += $this->destroyFromDeletion($deletion);
}
+
return $deleteCount;
}
/**
* Destroy an element from the given deletion model.
+ *
* @throws Exception
*/
public function destroyFromDeletion(Deletion $deletion): int
$count = $this->destroyEntity($deletion->deletable);
}
$deletion->delete();
+
return $count;
}
/**
* Restore the content within the given deletion.
+ *
* @throws Exception
*/
public function restoreFromDeletion(Deletion $deletion): int
}
$deletion->delete();
+
return $restoreCount;
}
* Automatically clear old content from the recycle bin
* depending on the configured lifetime.
* Returns the total number of deleted elements.
+ *
* @throws Exception
*/
public function autoClearOld(): int
/**
* Destroy the given entity.
+ *
* @throws Exception
*/
protected function destroyEntity(Entity $entity): int
if ($entity instanceof Bookshelf) {
return $this->destroyShelf($entity);
}
+
+ return 0;
}
/**