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' => $this->imageRepo->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->has('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 return redirect('/settings#' . $request->get('section', ''));
78 * Show the page for application maintenance.
80 public function showMaintenance()
82 $this->checkPermission('settings-manage');
83 $this->setPageTitle(trans('settings.maint'));
85 // Get application version
86 $version = trim(file_get_contents(base_path('version')));
88 return view('settings.maintenance', ['version' => $version]);
92 * Action to clean-up images in the system.
94 public function cleanupImages(Request $request, ImageService $imageService)
96 $this->checkPermission('settings-manage');
98 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
99 $dryRun = !($request->has('confirm'));
101 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
102 $deleteCount = count($imagesToDelete);
103 if ($deleteCount === 0) {
104 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
105 return redirect('/settings/maintenance')->withInput();
109 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
111 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
114 return redirect('/settings/maintenance#image-cleanup')->withInput();
118 * Action to send a test e-mail to the current user.
120 public function sendTestEmail()
122 $this->checkPermission('settings-manage');
124 user()->notify(new TestEmail());
125 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
127 return redirect('/settings/maintenance#image-cleanup')->withInput();