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 * Display a listing of the settings.
24 public function index(string $category)
26 $this->ensureCategoryExists($category);
27 $this->checkPermission('settings-manage');
28 $this->setPageTitle(trans('settings.settings'));
30 // Get application version
31 $version = trim(file_get_contents(base_path('version')));
33 return view('settings.' . $category, [
34 'category' => $category,
35 'version' => $version,
36 'guestUser' => User::getDefault(),
41 * Update the specified settings in storage.
43 public function update(Request $request, string $category)
45 $this->ensureCategoryExists($category);
46 $this->preventAccessInDemoMode();
47 $this->checkPermission('settings-manage');
48 $this->validate($request, [
49 'app_logo' => array_merge(['nullable'], $this->getImageValidationRules()),
52 // Cycles through posted settings and update them
53 foreach ($request->all() as $name => $value) {
54 $key = str_replace('setting-', '', trim($name));
55 if (strpos($name, 'setting-') !== 0) {
58 setting()->put($key, $value);
61 // Update logo image if set
62 if ($category === 'customization' && $request->hasFile('app_logo')) {
63 $logoFile = $request->file('app_logo');
64 $this->imageRepo->destroyByType('system');
65 $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
66 setting()->put('app-logo', $image->url);
69 // Clear logo image if requested
70 if ($category === 'customization' && $request->get('app_logo_reset', null)) {
71 $this->imageRepo->destroyByType('system');
72 setting()->remove('app-logo');
75 $this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
76 $this->showSuccessNotification(trans('settings.settings_save_success'));
78 return redirect("/settings/${category}");
81 protected function ensureCategoryExists(string $category): void
83 if (!in_array($category, $this->settingCategories)) {