]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/SettingController.php
Made delete permissions a requirement for move operations
[bookstack] / app / Http / Controllers / SettingController.php
1 <?php namespace BookStack\Http\Controllers;
2
3 use BookStack\Uploads\ImageService;
4 use Illuminate\Http\Request;
5 use Illuminate\Http\Response;
6 use Setting;
7
8 class SettingController extends Controller
9 {
10     /**
11      * Display a listing of the settings.
12      * @return Response
13      */
14     public function index()
15     {
16         $this->checkPermission('settings-manage');
17         $this->setPageTitle(trans('settings.settings'));
18
19         // Get application version
20         $version = trim(file_get_contents(base_path('version')));
21
22         return view('settings/index', ['version' => $version]);
23     }
24
25     /**
26      * Update the specified settings in storage.
27      * @param  Request $request
28      * @return Response
29      */
30     public function update(Request $request)
31     {
32         $this->preventAccessForDemoUsers();
33         $this->checkPermission('settings-manage');
34
35         // Cycles through posted settings and update them
36         foreach ($request->all() as $name => $value) {
37             if (strpos($name, 'setting-') !== 0) {
38                 continue;
39             }
40             $key = str_replace('setting-', '', trim($name));
41             Setting::put($key, $value);
42         }
43
44         session()->flash('success', trans('settings.settings_save_success'));
45         return redirect('/settings');
46     }
47
48     /**
49      * Show the page for application maintenance.
50      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
51      */
52     public function showMaintenance()
53     {
54         $this->checkPermission('settings-manage');
55         $this->setPageTitle(trans('settings.maint'));
56
57         // Get application version
58         $version = trim(file_get_contents(base_path('version')));
59
60         return view('settings/maintenance', ['version' => $version]);
61     }
62
63     /**
64      * Action to clean-up images in the system.
65      * @param Request $request
66      * @param ImageService $imageService
67      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
68      */
69     public function cleanupImages(Request $request, ImageService $imageService)
70     {
71         $this->checkPermission('settings-manage');
72
73         $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
74         $dryRun = !($request->has('confirm'));
75
76         $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
77         $deleteCount = count($imagesToDelete);
78         if ($deleteCount === 0) {
79             session()->flash('warning', trans('settings.maint_image_cleanup_nothing_found'));
80             return redirect('/settings/maintenance')->withInput();
81         }
82
83         if ($dryRun) {
84             session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
85         } else {
86             session()->flash('success', trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
87         }
88
89         return redirect('/settings/maintenance#image-cleanup')->withInput();
90     }
91 }