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 $this->middleware(function ($request, $next) {
18 $this->checkPermission('settings-manage');
19 $this->checkPermission('restrictions-manage-all');
20 return $next($request);
22 parent::__construct();
27 * Show the top-level listing for the recycle bin.
29 public function index()
31 $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
33 return view('settings.recycle-bin.index', [
34 'deletions' => $deletions,
39 * Show the page to confirm a restore of the deletion of the given id.
41 public function showRestore(string $id)
43 /** @var Deletion $deletion */
44 $deletion = Deletion::query()->findOrFail($id);
46 return view('settings.recycle-bin.restore', [
47 'deletion' => $deletion,
52 * Restore the element attached to the given deletion.
55 public function restore(string $id)
57 /** @var Deletion $deletion */
58 $deletion = Deletion::query()->findOrFail($id);
59 $restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
61 $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
62 return redirect($this->recycleBinBaseUrl);
66 * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
68 public function showDestroy(string $id)
70 /** @var Deletion $deletion */
71 $deletion = Deletion::query()->findOrFail($id);
73 return view('settings.recycle-bin.destroy', [
74 'deletion' => $deletion,
79 * Permanently delete the content associated with the given deletion.
82 public function destroy(string $id)
84 /** @var Deletion $deletion */
85 $deletion = Deletion::query()->findOrFail($id);
86 $deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
88 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
89 return redirect($this->recycleBinBaseUrl);
93 * Empty out the recycle bin.
96 public function empty()
98 $deleteCount = (new TrashCan())->empty();
100 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
101 return redirect($this->recycleBinBaseUrl);