2016-03-06 05:52:10 -05:00
|
|
|
<?php namespace BookStack\Http\Controllers;
|
2015-08-30 10:31:16 -04:00
|
|
|
|
2019-02-16 09:17:35 -05:00
|
|
|
use BookStack\Auth\User;
|
2019-10-15 12:41:08 -04:00
|
|
|
use BookStack\Notifications\TestEmail;
|
2019-05-04 10:48:15 -04:00
|
|
|
use BookStack\Uploads\ImageRepo;
|
2018-09-25 07:30:50 -04:00
|
|
|
use BookStack\Uploads\ImageService;
|
2015-08-30 10:31:16 -04:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
{
|
2019-05-04 10:48:15 -04:00
|
|
|
protected $imageRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SettingController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(ImageRepo $imageRepo)
|
|
|
|
{
|
|
|
|
$this->imageRepo = $imageRepo;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
/**
|
|
|
|
* Display a listing of the settings.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2016-02-27 14:24:42 -05:00
|
|
|
$this->checkPermission('settings-manage');
|
2018-05-27 14:40:07 -04:00
|
|
|
$this->setPageTitle(trans('settings.settings'));
|
2016-05-03 16:10:05 -04:00
|
|
|
|
|
|
|
// Get application version
|
2016-10-30 13:44:00 -04:00
|
|
|
$version = trim(file_get_contents(base_path('version')));
|
2016-05-03 16:10:05 -04:00
|
|
|
|
2019-02-16 09:17:35 -05:00
|
|
|
return view('settings.index', [
|
|
|
|
'version' => $version,
|
|
|
|
'guestUser' => User::getDefault()
|
|
|
|
]);
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified settings in storage.
|
|
|
|
*/
|
|
|
|
public function update(Request $request)
|
|
|
|
{
|
2019-09-19 10:12:10 -04:00
|
|
|
$this->preventAccessInDemoMode();
|
2016-02-27 14:24:42 -05:00
|
|
|
$this->checkPermission('settings-manage');
|
2019-05-04 10:48:15 -04:00
|
|
|
$this->validate($request, [
|
2020-03-03 18:05:47 -05:00
|
|
|
'app_logo' => 'nullable|' . $this->getImageValidationRules(),
|
2019-05-04 10:48:15 -04:00
|
|
|
]);
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
// Cycles through posted settings and update them
|
2016-03-06 05:52:10 -05:00
|
|
|
foreach ($request->all() as $name => $value) {
|
2018-01-28 11:58:52 -05:00
|
|
|
if (strpos($name, 'setting-') !== 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-30 10:31:16 -04:00
|
|
|
$key = str_replace('setting-', '', trim($name));
|
2019-05-04 10:48:15 -04:00
|
|
|
setting()->put($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update logo image if set
|
2020-03-03 18:08:01 -05:00
|
|
|
if ($request->hasFile('app_logo')) {
|
2019-05-04 10:48:15 -04:00
|
|
|
$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 10:31:16 -04:00
|
|
|
}
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2019-10-05 07:55:01 -04:00
|
|
|
$this->showSuccessNotification(trans('settings.settings_save_success'));
|
2020-02-02 12:57:21 -05:00
|
|
|
$redirectLocation = '/settings#' . $request->get('section', '');
|
|
|
|
return redirect(rtrim($redirectLocation, '#'));
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|
2018-05-27 14:40:07 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page for application maintenance.
|
|
|
|
*/
|
|
|
|
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 09:17:35 -05:00
|
|
|
return view('settings.maintenance', ['version' => $version]);
|
2018-05-27 14:40:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to clean-up images in the system.
|
|
|
|
*/
|
|
|
|
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) {
|
2019-10-05 07:55:01 -04:00
|
|
|
$this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
|
2018-05-27 14:40:07 -04:00
|
|
|
return redirect('/settings/maintenance')->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dryRun) {
|
|
|
|
session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
|
|
|
|
} else {
|
2019-10-05 07:55:01 -04:00
|
|
|
$this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
|
2018-05-27 14:40:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/settings/maintenance#image-cleanup')->withInput();
|
|
|
|
}
|
2019-10-15 12:41:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to send a test e-mail to the current user.
|
|
|
|
*/
|
2020-02-02 12:35:16 -05:00
|
|
|
public function sendTestEmail()
|
2019-10-15 12:41:08 -04:00
|
|
|
{
|
|
|
|
$this->checkPermission('settings-manage');
|
|
|
|
|
2020-02-15 09:13:15 -05:00
|
|
|
try {
|
|
|
|
user()->notify(new TestEmail());
|
|
|
|
$this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
$errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
|
|
|
|
$this->showErrorNotification($errorMessage);
|
|
|
|
}
|
|
|
|
|
2019-10-15 12:41:08 -04:00
|
|
|
|
|
|
|
return redirect('/settings/maintenance#image-cleanup')->withInput();
|
|
|
|
}
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|