X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ff7cbd14fcdad963a7f53f788dabbb43ccd73b8b..refs/pull/2700/head:/app/Http/Controllers/RecycleBinController.php diff --git a/app/Http/Controllers/RecycleBinController.php b/app/Http/Controllers/RecycleBinController.php index 3cbc99df3..a644a2889 100644 --- a/app/Http/Controllers/RecycleBinController.php +++ b/app/Http/Controllers/RecycleBinController.php @@ -1,37 +1,107 @@ 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. */ public function index() { - $this->checkPermission('settings-manage'); - $this->checkPermission('restrictions-manage-all'); - $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10); - return view('settings.recycle-bin', [ + $this->setPageTitle(trans('settings.recycle_bin')); + return view('settings.recycle-bin.index', [ 'deletions' => $deletions, ]); } + /** + * Show the page to confirm a restore of the deletion of the given id. + */ + public function showRestore(string $id) + { + /** @var Deletion $deletion */ + $deletion = Deletion::query()->findOrFail($id); + + return view('settings.recycle-bin.restore', [ + 'deletion' => $deletion, + ]); + } + + /** + * Restore the element attached to the given deletion. + * @throws \Exception + */ + public function restore(string $id) + { + /** @var Deletion $deletion */ + $deletion = Deletion::query()->findOrFail($id); + $this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion); + $restoreCount = (new TrashCan())->restoreFromDeletion($deletion); + + $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount])); + return redirect($this->recycleBinBaseUrl); + } + + /** + * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id. + */ + public function showDestroy(string $id) + { + /** @var Deletion $deletion */ + $deletion = Deletion::query()->findOrFail($id); + + return view('settings.recycle-bin.destroy', [ + 'deletion' => $deletion, + ]); + } + + /** + * Permanently delete the content associated with the given deletion. + * @throws \Exception + */ + public function destroy(string $id) + { + /** @var Deletion $deletion */ + $deletion = Deletion::query()->findOrFail($id); + $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion); + $deleteCount = (new TrashCan())->destroyFromDeletion($deletion); + + $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); + return redirect($this->recycleBinBaseUrl); + } + /** * Empty out the recycle bin. + * @throws \Exception */ public function empty() { - $this->checkPermission('settings-manage'); - $this->checkPermission('restrictions-manage-all'); - - $deleteCount = (new TrashCan())->destroyFromAllDeletions(); + $deleteCount = (new TrashCan())->empty(); - $this->showSuccessNotification(trans('settings.recycle_bin_empty_notification', ['count' => $deleteCount])); - return redirect('/settings/recycle-bin'); + $this->logActivity(ActivityType::RECYCLE_BIN_EMPTY); + $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); + return redirect($this->recycleBinBaseUrl); } }