1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Actions\ActivityType;
4 use BookStack\Entities\Deletion;
5 use BookStack\Entities\Managers\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);
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 $this->setPageTitle(trans('settings.recycle_bin'));
35 return view('settings.recycle-bin.index', [
36 'deletions' => $deletions,
41 * Show the page to confirm a restore of the deletion of the given id.
43 public function showRestore(string $id)
45 /** @var Deletion $deletion */
46 $deletion = Deletion::query()->findOrFail($id);
48 return view('settings.recycle-bin.restore', [
49 'deletion' => $deletion,
54 * Restore the element attached to the given deletion.
57 public function restore(string $id)
59 /** @var Deletion $deletion */
60 $deletion = Deletion::query()->findOrFail($id);
61 $this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion);
62 $restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
64 $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
65 return redirect($this->recycleBinBaseUrl);
69 * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
71 public function showDestroy(string $id)
73 /** @var Deletion $deletion */
74 $deletion = Deletion::query()->findOrFail($id);
76 return view('settings.recycle-bin.destroy', [
77 'deletion' => $deletion,
82 * Permanently delete the content associated with the given deletion.
85 public function destroy(string $id)
87 /** @var Deletion $deletion */
88 $deletion = Deletion::query()->findOrFail($id);
89 $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
90 $deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
92 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
93 return redirect($this->recycleBinBaseUrl);
97 * Empty out the recycle bin.
100 public function empty()
102 $deleteCount = (new TrashCan())->empty();
104 $this->logActivity(ActivityType::RECYCLE_BIN_EMPTY);
105 $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
106 return redirect($this->recycleBinBaseUrl);