Started testing work for recycle bin implementation

This commit is contained in:
Dan Brown
2020-11-06 12:54:39 +00:00
parent 3e70c661a1
commit 483cb41665
18 changed files with 235 additions and 93 deletions

View File

@ -295,7 +295,7 @@ class Entity extends Ownable
public function getParent(): ?Entity
{
if ($this->isA('page')) {
return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book->withTrashed()->first();
return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
}
if ($this->isA('chapter')) {
return $this->book->withTrashed()->first();

View File

@ -90,7 +90,7 @@ class TrashCan
* Remove a bookshelf from the system.
* @throws Exception
*/
public function destroyShelf(Bookshelf $shelf): int
protected function destroyShelf(Bookshelf $shelf): int
{
$this->destroyCommonRelations($shelf);
$shelf->forceDelete();
@ -102,7 +102,7 @@ class TrashCan
* Destroys any child chapters and pages.
* @throws Exception
*/
public function destroyBook(Book $book): int
protected function destroyBook(Book $book): int
{
$count = 0;
$pages = $book->pages()->withTrashed()->get();
@ -127,7 +127,7 @@ class TrashCan
* Destroys all pages within.
* @throws Exception
*/
public function destroyChapter(Chapter $chapter): int
protected function destroyChapter(Chapter $chapter): int
{
$count = 0;
$pages = $chapter->pages()->withTrashed()->get();
@ -147,7 +147,7 @@ class TrashCan
* Remove a page from the system.
* @throws Exception
*/
public function destroyPage(Page $page): int
protected function destroyPage(Page $page): int
{
$this->destroyCommonRelations($page);
@ -182,7 +182,7 @@ class TrashCan
* Destroy all items that have pending deletions.
* @throws Exception
*/
public function destroyFromAllDeletions(): int
public function empty(): int
{
$deletions = Deletion::all();
$deleteCount = 0;

View File

@ -23,7 +23,12 @@ class AuditLogController extends Controller
];
$query = Activity::query()
->with(['entity', 'user'])
->with([
'entity' => function ($query) {
$query->withTrashed();
},
'user'
])
->orderBy($listDetails['sort'], $listDetails['order']);
if ($listDetails['event']) {

View File

@ -181,14 +181,13 @@ class BookController extends Controller
/**
* Remove the specified book from the system.
* @throws Throwable
* @throws NotifyException
*/
public function destroy(string $bookSlug)
{
$book = $this->bookRepo->getBySlug($bookSlug);
$this->checkOwnablePermission('book-delete', $book);
Activity::addMessage('book_delete', $book->name);
Activity::add($book, 'book_delete', $book->id);
$this->bookRepo->destroy($book);
return redirect('/books');

View File

@ -182,7 +182,7 @@ class BookshelfController extends Controller
$shelf = $this->bookshelfRepo->getBySlug($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);
Activity::addMessage('bookshelf_delete', $shelf->name);
Activity::add($shelf, 'bookshelf_delete');
$this->bookshelfRepo->destroy($shelf);
return redirect('/shelves');

View File

@ -128,7 +128,7 @@ class ChapterController extends Controller
$chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
$this->checkOwnablePermission('chapter-delete', $chapter);
Activity::addMessage('chapter_delete', $chapter->name, $chapter->book->id);
Activity::add($chapter, 'chapter_delete', $chapter->book->id);
$this->chapterRepo->destroy($chapter);
return redirect($chapter->book->getUrl());

View File

@ -308,9 +308,8 @@ class PageController extends Controller
$book = $page->book;
$parent = $page->chapter ?? $book;
$this->pageRepo->destroy($page);
Activity::addMessage('page_delete', $page->name, $book->id);
Activity::add($page, 'page_delete', $page->book_id);
$this->showSuccessNotification(trans('entities.pages_delete_success'));
return redirect($parent->getUrl());
}

View File

@ -14,7 +14,6 @@ class RecycleBinController extends Controller
*/
public function __construct()
{
// TODO - Check this is enforced.
$this->middleware(function ($request, $next) {
$this->checkPermission('settings-manage');
$this->checkPermission('restrictions-manage-all');
@ -96,7 +95,7 @@ class RecycleBinController extends Controller
*/
public function empty()
{
$deleteCount = (new TrashCan())->destroyFromAllDeletions();
$deleteCount = (new TrashCan())->empty();
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
return redirect($this->recycleBinBaseUrl);