1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Auth\User;
4 use BookStack\Notifications\TestEmail;
5 use BookStack\Uploads\ImageRepo;
6 use BookStack\Uploads\ImageService;
7 use Illuminate\Http\Request;
9 class SettingController extends Controller
14 * SettingController constructor.
16 public function __construct(ImageRepo $imageRepo)
18 $this->imageRepo = $imageRepo;
19 parent::__construct();
23 * Display a listing of the settings.
25 public function index()
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.index', [
34 'version' => $version,
35 'guestUser' => User::getDefault()
40 * Update the specified settings in storage.
42 public function update(Request $request)
44 $this->preventAccessInDemoMode();
45 $this->checkPermission('settings-manage');
46 $this->validate($request, [
47 'app_logo' => 'nullable|' . $this->getImageValidationRules(),
50 // Cycles through posted settings and update them
51 foreach ($request->all() as $name => $value) {
52 if (strpos($name, 'setting-') !== 0) {
55 $key = str_replace('setting-', '', trim($name));
56 setting()->put($key, $value);
59 // Update logo image if set
60 if ($request->hasFile('app_logo')) {
61 $logoFile = $request->file('app_logo');
62 $this->imageRepo->destroyByType('system');
63 $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
64 setting()->put('app-logo', $image->url);
67 // Clear logo image if requested
68 if ($request->get('app_logo_reset', null)) {
69 $this->imageRepo->destroyByType('system');
70 setting()->remove('app-logo');
73 $this->showSuccessNotification(trans('settings.settings_save_success'));
74 $redirectLocation = '/settings#' . $request->get('section', '');
75 return redirect(rtrim($redirectLocation, '#'));
79 * Show the page for application maintenance.
81 public function showMaintenance()
83 $this->checkPermission('settings-manage');
84 $this->setPageTitle(trans('settings.maint'));
86 // Get application version
87 $version = trim(file_get_contents(base_path('version')));
89 return view('settings.maintenance', ['version' => $version]);
93 * Action to clean-up images in the system.
95 public function cleanupImages(Request $request, ImageService $imageService)
97 $this->checkPermission('settings-manage');
99 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
100 $dryRun = !($request->has('confirm'));
102 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
103 $deleteCount = count($imagesToDelete);
104 if ($deleteCount === 0) {
105 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
106 return redirect('/settings/maintenance')->withInput();
110 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
112 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
115 return redirect('/settings/maintenance#image-cleanup')->withInput();
119 * Action to send a test e-mail to the current user.
121 public function sendTestEmail()
123 $this->checkPermission('settings-manage');
126 user()->notify(new TestEmail());
127 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
128 } catch (\Exception $exception) {
129 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
130 $this->showErrorNotification($errorMessage);
134 return redirect('/settings/maintenance#image-cleanup')->withInput();