1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Auth\User;
4 use BookStack\Uploads\ImageRepo;
5 use BookStack\Uploads\ImageService;
6 use Illuminate\Http\Request;
7 use Illuminate\Http\Response;
10 class SettingController extends Controller
15 * SettingController constructor.
18 public function __construct(ImageRepo $imageRepo)
20 $this->imageRepo = $imageRepo;
21 parent::__construct();
26 * Display a listing of the settings.
29 public function index()
31 $this->checkPermission('settings-manage');
32 $this->setPageTitle(trans('settings.settings'));
34 // Get application version
35 $version = trim(file_get_contents(base_path('version')));
37 return view('settings.index', [
38 'version' => $version,
39 'guestUser' => User::getDefault()
44 * Update the specified settings in storage.
45 * @param Request $request
48 public function update(Request $request)
50 $this->preventAccessInDemoMode();
51 $this->checkPermission('settings-manage');
52 $this->validate($request, [
53 'app_logo' => $this->imageRepo->getImageValidationRules(),
56 // Cycles through posted settings and update them
57 foreach ($request->all() as $name => $value) {
58 if (strpos($name, 'setting-') !== 0) {
61 $key = str_replace('setting-', '', trim($name));
62 setting()->put($key, $value);
65 // Update logo image if set
66 if ($request->has('app_logo')) {
67 $logoFile = $request->file('app_logo');
68 $this->imageRepo->destroyByType('system');
69 $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
70 setting()->put('app-logo', $image->url);
73 // Clear logo image if requested
74 if ($request->get('app_logo_reset', null)) {
75 $this->imageRepo->destroyByType('system');
76 setting()->remove('app-logo');
79 $this->showSuccessNotification( trans('settings.settings_save_success'));
80 return redirect('/settings');
84 * Show the page for application maintenance.
85 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
87 public function showMaintenance()
89 $this->checkPermission('settings-manage');
90 $this->setPageTitle(trans('settings.maint'));
92 // Get application version
93 $version = trim(file_get_contents(base_path('version')));
95 return view('settings.maintenance', ['version' => $version]);
99 * Action to clean-up images in the system.
100 * @param Request $request
101 * @param ImageService $imageService
102 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
104 public function cleanupImages(Request $request, ImageService $imageService)
106 $this->checkPermission('settings-manage');
108 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
109 $dryRun = !($request->has('confirm'));
111 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
112 $deleteCount = count($imagesToDelete);
113 if ($deleteCount === 0) {
114 $this->showWarningNotification( trans('settings.maint_image_cleanup_nothing_found'));
115 return redirect('/settings/maintenance')->withInput();
119 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
121 $this->showSuccessNotification( trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
124 return redirect('/settings/maintenance#image-cleanup')->withInput();