3 namespace BookStack\Http\Controllers;
5 use BookStack\Actions\ActivityType;
6 use BookStack\Auth\User;
7 use BookStack\Uploads\ImageRepo;
8 use Illuminate\Http\Request;
10 class SettingController extends Controller
12 protected ImageRepo $imageRepo;
14 protected array $settingCategories = ['features', 'customization', 'registration'];
16 public function __construct(ImageRepo $imageRepo)
18 $this->imageRepo = $imageRepo;
22 * Handle requests to the settings index path.
24 public function index()
26 return redirect('/settings/features');
30 * Display the settings for the given category.
32 public function category(string $category)
34 $this->ensureCategoryExists($category);
35 $this->checkPermission('settings-manage');
36 $this->setPageTitle(trans('settings.settings'));
38 // Get application version
39 $version = trim(file_get_contents(base_path('version')));
41 return view('settings.' . $category, [
42 'category' => $category,
43 'version' => $version,
44 'guestUser' => User::getDefault(),
49 * Update the specified settings in storage.
51 public function update(Request $request, string $category)
53 $this->ensureCategoryExists($category);
54 $this->preventAccessInDemoMode();
55 $this->checkPermission('settings-manage');
56 $this->validate($request, [
57 'app_logo' => array_merge(['nullable'], $this->getImageValidationRules()),
60 // Cycles through posted settings and update them
61 foreach ($request->all() as $name => $value) {
62 $key = str_replace('setting-', '', trim($name));
63 if (strpos($name, 'setting-') !== 0) {
66 setting()->put($key, $value);
69 // Update logo image if set
70 if ($category === 'customization' && $request->hasFile('app_logo')) {
71 $logoFile = $request->file('app_logo');
72 $this->imageRepo->destroyByType('system');
73 $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
74 setting()->put('app-logo', $image->url);
77 // Clear logo image if requested
78 if ($category === 'customization' && $request->get('app_logo_reset', null)) {
79 $this->imageRepo->destroyByType('system');
80 setting()->remove('app-logo');
83 $this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
84 $this->showSuccessNotification(trans('settings.settings_save_success'));
86 return redirect("/settings/{$category}");
89 protected function ensureCategoryExists(string $category): void
91 if (!in_array($category, $this->settingCategories)) {