1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Actions\ActivityType;
4 use BookStack\Entities\Models\Deletion;
5 use BookStack\Entities\Tools\TrashCan;
7 class RecycleBinController extends Controller
10 protected $recycleBinBaseUrl = '/settings/recycle-bin';
13 * On each request to a method of this controller check permissions
14 * using a middleware closure.
16 public function __construct()
18 $this->middleware(function ($request, $next) {
19 $this->checkPermission('settings-manage');
20 $this->checkPermission('restrictions-manage-all');
21 return $next($request);
27 * Show the top-level listing for the recycle bin.
29 public function index()
31 $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
33 $this->setPageTitle(trans('settings.recycle_bin'));
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 $this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion);
61 $restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
63 $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
64 return redirect($this->recycleBinBaseUrl);
68 * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
70 public function showDestroy(string $id)
72 /** @var Deletion $deletion */
73 $deletion = Deletion::query()->findOrFail($id);
75 return view('settings.recycle-bin.destroy', [
76 'deletion' => $deletion,
81 * Permanently delete the content associated with the given deletion.
84 public function destroy(string $id)
86 /** @var Deletion $deletion */
87 $deletion = Deletion::query()->findOrFail($id);
88 $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
89 $deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
91 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
92 return redirect($this->recycleBinBaseUrl);
96 * Empty out the recycle bin.
99 public function empty()
101 $deleteCount = (new TrashCan())->empty();
103 $this->logActivity(ActivityType::RECYCLE_BIN_EMPTY);
104 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
105 return redirect($this->recycleBinBaseUrl);