]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/SettingController.php
Started widening of activity logging
[bookstack] / app / Http / Controllers / SettingController.php
1 <?php namespace BookStack\Http\Controllers;
2
3 use BookStack\Actions\ActivityType;
4 use BookStack\Auth\User;
5 use BookStack\Uploads\ImageRepo;
6 use Illuminate\Http\Request;
7
8 class SettingController extends Controller
9 {
10     protected $imageRepo;
11
12     /**
13      * SettingController constructor.
14      */
15     public function __construct(ImageRepo $imageRepo)
16     {
17         $this->imageRepo = $imageRepo;
18         parent::__construct();
19     }
20
21     /**
22      * Display a listing of the settings.
23      */
24     public function index()
25     {
26         $this->checkPermission('settings-manage');
27         $this->setPageTitle(trans('settings.settings'));
28
29         // Get application version
30         $version = trim(file_get_contents(base_path('version')));
31
32         return view('settings.index', [
33             'version' => $version,
34             'guestUser' => User::getDefault()
35         ]);
36     }
37
38     /**
39      * Update the specified settings in storage.
40      */
41     public function update(Request $request)
42     {
43         $this->preventAccessInDemoMode();
44         $this->checkPermission('settings-manage');
45         $this->validate($request, [
46             'app_logo' => 'nullable|' . $this->getImageValidationRules(),
47         ]);
48
49         // Cycles through posted settings and update them
50         foreach ($request->all() as $name => $value) {
51             $key = str_replace('setting-', '', trim($name));
52             if (strpos($name, 'setting-') !== 0) {
53                 continue;
54             }
55             setting()->put($key, $value);
56         }
57
58         // Update logo image if set
59         if ($request->hasFile('app_logo')) {
60             $logoFile = $request->file('app_logo');
61             $this->imageRepo->destroyByType('system');
62             $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
63             setting()->put('app-logo', $image->url);
64         }
65
66         // Clear logo image if requested
67         if ($request->get('app_logo_reset', null)) {
68             $this->imageRepo->destroyByType('system');
69             setting()->remove('app-logo');
70         }
71
72         $section = $request->get('section', '');
73         $this->logActivity(ActivityType::SETTINGS_UPDATE, $section);
74         $this->showSuccessNotification(trans('settings.settings_save_success'));
75         $redirectLocation = '/settings#' . $section;
76         return redirect(rtrim($redirectLocation, '#'));
77     }
78 }