1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Entities\Deletion;
4 use BookStack\Entities\Managers\TrashCan;
6 class RecycleBinController extends Controller
9 protected $recycleBinBaseUrl = '/settings/recycle-bin';
12 * On each request to a method of this controller check permissions
13 * using a middleware closure.
15 public function __construct()
17 // TODO - Check this is enforced.
18 $this->middleware(function ($request, $next) {
19 $this->checkPermission('settings-manage');
20 $this->checkPermission('restrictions-manage-all');
21 return $next($request);
23 parent::__construct();
28 * Show the top-level listing for the recycle bin.
30 public function index()
32 $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
34 return view('settings.recycle-bin.index', [
35 'deletions' => $deletions,
40 * Show the page to confirm a restore of the deletion of the given id.
42 public function showRestore(string $id)
44 /** @var Deletion $deletion */
45 $deletion = Deletion::query()->findOrFail($id);
47 return view('settings.recycle-bin.restore', [
48 'deletion' => $deletion,
53 * Restore the element attached to the given deletion.
56 public function restore(string $id)
58 /** @var Deletion $deletion */
59 $deletion = Deletion::query()->findOrFail($id);
60 $restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
62 $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
63 return redirect($this->recycleBinBaseUrl);
67 * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
69 public function showDestroy(string $id)
71 /** @var Deletion $deletion */
72 $deletion = Deletion::query()->findOrFail($id);
74 return view('settings.recycle-bin.destroy', [
75 'deletion' => $deletion,
80 * Permanently delete the content associated with the given deletion.
83 public function destroy(string $id)
85 /** @var Deletion $deletion */
86 $deletion = Deletion::query()->findOrFail($id);
87 $deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
89 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
90 return redirect($this->recycleBinBaseUrl);
94 * Empty out the recycle bin.
97 public function empty()
99 $deleteCount = (new TrashCan())->destroyFromAllDeletions();
101 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
102 return redirect($this->recycleBinBaseUrl);