]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/RecycleBinController.php
LDAP: Added TLS support
[bookstack] / app / Http / Controllers / RecycleBinController.php
1 <?php namespace BookStack\Http\Controllers;
2
3 use BookStack\Entities\Deletion;
4 use BookStack\Entities\Managers\TrashCan;
5
6 class RecycleBinController extends Controller
7 {
8
9     protected $recycleBinBaseUrl = '/settings/recycle-bin';
10
11     /**
12      * On each request to a method of this controller check permissions
13      * using a middleware closure.
14      */
15     public function __construct()
16     {
17         $this->middleware(function ($request, $next) {
18             $this->checkPermission('settings-manage');
19             $this->checkPermission('restrictions-manage-all');
20             return $next($request);
21         });
22         parent::__construct();
23     }
24
25
26     /**
27      * Show the top-level listing for the recycle bin.
28      */
29     public function index()
30     {
31         $deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
32
33         return view('settings.recycle-bin.index', [
34             'deletions' => $deletions,
35         ]);
36     }
37
38     /**
39      * Show the page to confirm a restore of the deletion of the given id.
40      */
41     public function showRestore(string $id)
42     {
43         /** @var Deletion $deletion */
44         $deletion = Deletion::query()->findOrFail($id);
45
46         return view('settings.recycle-bin.restore', [
47             'deletion' => $deletion,
48         ]);
49     }
50
51     /**
52      * Restore the element attached to the given deletion.
53      * @throws \Exception
54      */
55     public function restore(string $id)
56     {
57         /** @var Deletion $deletion */
58         $deletion = Deletion::query()->findOrFail($id);
59         $restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
60
61         $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
62         return redirect($this->recycleBinBaseUrl);
63     }
64
65     /**
66      * Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
67      */
68     public function showDestroy(string $id)
69     {
70         /** @var Deletion $deletion */
71         $deletion = Deletion::query()->findOrFail($id);
72
73         return view('settings.recycle-bin.destroy', [
74             'deletion' => $deletion,
75         ]);
76     }
77
78     /**
79      * Permanently delete the content associated with the given deletion.
80      * @throws \Exception
81      */
82     public function destroy(string $id)
83     {
84         /** @var Deletion $deletion */
85         $deletion = Deletion::query()->findOrFail($id);
86         $deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
87
88         $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
89         return redirect($this->recycleBinBaseUrl);
90     }
91
92     /**
93      * Empty out the recycle bin.
94      * @throws \Exception
95      */
96     public function empty()
97     {
98         $deleteCount = (new TrashCan())->empty();
99
100         $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
101         return redirect($this->recycleBinBaseUrl);
102     }
103 }