X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a6633642232efd164d4708967ab59e498fbff896..refs/pull/4145/head:/app/Http/Controllers/RecycleBinController.php diff --git a/app/Http/Controllers/RecycleBinController.php b/app/Http/Controllers/RecycleBinController.php index a644a2889..82e3f660b 100644 --- a/app/Http/Controllers/RecycleBinController.php +++ b/app/Http/Controllers/RecycleBinController.php @@ -1,12 +1,15 @@ -middleware(function ($request, $next) { $this->checkPermission('settings-manage'); $this->checkPermission('restrictions-manage-all'); + return $next($request); }); } - /** * Show the top-level listing for the recycle bin. */ @@ -31,6 +34,7 @@ class RecycleBinController extends Controller $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10); $this->setPageTitle(trans('settings.recycle_bin')); + return view('settings.recycle-bin.index', [ 'deletions' => $deletions, ]); @@ -44,23 +48,38 @@ class RecycleBinController extends Controller /** @var Deletion $deletion */ $deletion = Deletion::query()->findOrFail($id); + // Walk the parent chain to find any cascading parent deletions + $currentDeletable = $deletion->deletable; + $searching = true; + while ($searching && $currentDeletable instanceof Entity) { + $parent = $currentDeletable->getParent(); + if ($parent && $parent->trashed()) { + $currentDeletable = $parent; + } else { + $searching = false; + } + } + + /** @var ?Deletion $parentDeletion */ + $parentDeletion = ($currentDeletable === $deletion->deletable) ? null : $currentDeletable->deletions()->first(); + return view('settings.recycle-bin.restore', [ - 'deletion' => $deletion, + 'deletion' => $deletion, + 'parentDeletion' => $parentDeletion, ]); } /** * Restore the element attached to the given deletion. + * * @throws \Exception */ - public function restore(string $id) + public function restore(DeletionRepo $deletionRepo, string $id) { - /** @var Deletion $deletion */ - $deletion = Deletion::query()->findOrFail($id); - $this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion); - $restoreCount = (new TrashCan())->restoreFromDeletion($deletion); + $restoreCount = $deletionRepo->restore((int) $id); $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount])); + return redirect($this->recycleBinBaseUrl); } @@ -79,21 +98,21 @@ class RecycleBinController extends Controller /** * Permanently delete the content associated with the given deletion. + * * @throws \Exception */ - public function destroy(string $id) + public function destroy(DeletionRepo $deletionRepo, string $id) { - /** @var Deletion $deletion */ - $deletion = Deletion::query()->findOrFail($id); - $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion); - $deleteCount = (new TrashCan())->destroyFromDeletion($deletion); + $deleteCount = $deletionRepo->destroy((int) $id); $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); + return redirect($this->recycleBinBaseUrl); } /** * Empty out the recycle bin. + * * @throws \Exception */ public function empty() @@ -102,6 +121,7 @@ class RecycleBinController extends Controller $this->logActivity(ActivityType::RECYCLE_BIN_EMPTY); $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); + return redirect($this->recycleBinBaseUrl); } }