2016-03-06 11:52:10 +01:00
|
|
|
<?php namespace BookStack\Http\Controllers;
|
2015-08-30 16:31:16 +02:00
|
|
|
|
2019-02-16 15:17:35 +01:00
|
|
|
use BookStack\Auth\User;
|
2019-05-04 16:48:15 +02:00
|
|
|
use BookStack\Uploads\ImageRepo;
|
2018-09-25 13:30:50 +02:00
|
|
|
use BookStack\Uploads\ImageService;
|
2015-08-30 16:31:16 +02:00
|
|
|
use Illuminate\Http\Request;
|
2016-12-04 17:51:39 +01:00
|
|
|
use Illuminate\Http\Response;
|
2015-08-30 16:31:16 +02:00
|
|
|
use Setting;
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
{
|
2019-05-04 16:48:15 +02:00
|
|
|
protected $imageRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SettingController constructor.
|
|
|
|
* @param $imageRepo
|
|
|
|
*/
|
|
|
|
public function __construct(ImageRepo $imageRepo)
|
|
|
|
{
|
|
|
|
$this->imageRepo = $imageRepo;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-30 16:31:16 +02:00
|
|
|
/**
|
|
|
|
* Display a listing of the settings.
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2016-02-27 20:24:42 +01:00
|
|
|
$this->checkPermission('settings-manage');
|
2018-05-27 20:40:07 +02:00
|
|
|
$this->setPageTitle(trans('settings.settings'));
|
2016-05-03 22:10:05 +02:00
|
|
|
|
|
|
|
// Get application version
|
2016-10-30 18:44:00 +01:00
|
|
|
$version = trim(file_get_contents(base_path('version')));
|
2016-05-03 22:10:05 +02:00
|
|
|
|
2019-02-16 15:17:35 +01:00
|
|
|
return view('settings.index', [
|
|
|
|
'version' => $version,
|
|
|
|
'guestUser' => User::getDefault()
|
|
|
|
]);
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified settings in storage.
|
2016-03-06 11:52:10 +01:00
|
|
|
* @param Request $request
|
2015-08-30 16:31:16 +02:00
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request)
|
|
|
|
{
|
2015-12-31 18:57:34 +01:00
|
|
|
$this->preventAccessForDemoUsers();
|
2016-02-27 20:24:42 +01:00
|
|
|
$this->checkPermission('settings-manage');
|
2019-05-04 16:48:15 +02:00
|
|
|
$this->validate($request, [
|
|
|
|
'app_logo' => $this->imageRepo->getImageValidationRules(),
|
|
|
|
]);
|
2015-12-31 18:57:34 +01:00
|
|
|
|
2015-08-30 16:31:16 +02:00
|
|
|
// Cycles through posted settings and update them
|
2016-03-06 11:52:10 +01:00
|
|
|
foreach ($request->all() as $name => $value) {
|
2018-01-28 17:58:52 +01:00
|
|
|
if (strpos($name, 'setting-') !== 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-30 16:31:16 +02:00
|
|
|
$key = str_replace('setting-', '', trim($name));
|
2019-05-04 16:48:15 +02:00
|
|
|
setting()->put($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update logo image if set
|
|
|
|
if ($request->has('app_logo')) {
|
|
|
|
$logoFile = $request->file('app_logo');
|
|
|
|
$this->imageRepo->destroyByType('system');
|
|
|
|
$image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
|
|
|
|
setting()->put('app-logo', $image->url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear logo image if requested
|
|
|
|
if ($request->get('app_logo_reset', null)) {
|
|
|
|
$this->imageRepo->destroyByType('system');
|
|
|
|
setting()->remove('app-logo');
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|
2015-12-31 18:57:34 +01:00
|
|
|
|
2016-12-04 17:51:39 +01:00
|
|
|
session()->flash('success', trans('settings.settings_save_success'));
|
2015-08-30 16:31:16 +02:00
|
|
|
return redirect('/settings');
|
|
|
|
}
|
2018-05-27 20:40:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page for application maintenance.
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showMaintenance()
|
|
|
|
{
|
|
|
|
$this->checkPermission('settings-manage');
|
|
|
|
$this->setPageTitle(trans('settings.maint'));
|
|
|
|
|
|
|
|
// Get application version
|
|
|
|
$version = trim(file_get_contents(base_path('version')));
|
|
|
|
|
2019-02-16 15:17:35 +01:00
|
|
|
return view('settings.maintenance', ['version' => $version]);
|
2018-05-27 20:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to clean-up images in the system.
|
|
|
|
* @param Request $request
|
|
|
|
* @param ImageService $imageService
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function cleanupImages(Request $request, ImageService $imageService)
|
|
|
|
{
|
|
|
|
$this->checkPermission('settings-manage');
|
|
|
|
|
|
|
|
$checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
|
|
|
|
$dryRun = !($request->has('confirm'));
|
|
|
|
|
|
|
|
$imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
|
|
|
|
$deleteCount = count($imagesToDelete);
|
|
|
|
if ($deleteCount === 0) {
|
|
|
|
session()->flash('warning', trans('settings.maint_image_cleanup_nothing_found'));
|
|
|
|
return redirect('/settings/maintenance')->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dryRun) {
|
|
|
|
session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
|
|
|
|
} else {
|
|
|
|
session()->flash('success', trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/settings/maintenance#image-cleanup')->withInput();
|
|
|
|
}
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|