diff --git a/app/Console/Commands/CleanupImages.php b/app/Console/Commands/CleanupImages.php index 5eadf2751..e05508d5e 100644 --- a/app/Console/Commands/CleanupImages.php +++ b/app/Console/Commands/CleanupImages.php @@ -55,7 +55,7 @@ class CleanupImages extends Command } } - $deleted = $this->imageService->deleteUnusedImages($checkRevisions, ['gallery', 'drawio'], $dryRun); + $deleted = $this->imageService->deleteUnusedImages($checkRevisions, $dryRun); $deleteCount = count($deleted); if ($dryRun) { diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index e0e351458..d9d66042e 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -1,5 +1,6 @@ checkPermission('settings-manage'); - $this->setPageTitle('Settings'); + $this->setPageTitle(trans('settings.settings')); // Get application version $version = trim(file_get_contents(base_path('version'))); @@ -43,4 +44,48 @@ class SettingController extends Controller session()->flash('success', trans('settings.settings_save_success')); return redirect('/settings'); } + + /** + * 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'))); + + return view('settings/maintenance', ['version' => $version]); + } + + /** + * 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(); + } } diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index d1193ab4f..73a677ac2 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -306,11 +306,11 @@ class ImageService extends UploadService * * Returns the path of the images that would be/have been deleted. * @param bool $checkRevisions - * @param array $types * @param bool $dryRun + * @param array $types * @return array */ - public function deleteUnusedImages($checkRevisions = true, $types = ['gallery', 'drawio'], $dryRun = true) + public function deleteUnusedImages($checkRevisions = true, $dryRun = true, $types = ['gallery', 'drawio']) { $types = array_intersect($types, ['gallery', 'drawio']); $deletedPaths = []; diff --git a/resources/assets/icons/spanner.svg b/resources/assets/icons/spanner.svg new file mode 100644 index 000000000..8ab25a247 --- /dev/null +++ b/resources/assets/icons/spanner.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index de4894280..3a3dbb9a4 100755 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -50,6 +50,19 @@ return [ 'reg_confirm_restrict_domain_desc' => 'Enter a comma separated list of email domains you would like to restrict registration to. Users will be sent an email to confirm their address before being allowed to interact with the application.
Note that users will be able to change their email addresses after successful registration.', 'reg_confirm_restrict_domain_placeholder' => 'No restriction set', + /** + * Maintenance settings + */ + + 'maint' => 'Maintenance', + 'maint_image_cleanup' => 'Cleanup Images', + 'maint_image_cleanup_desc' => "Scans page & revision content to check which images and drawings are currently in use and which images are redundant. Ensure you create a full database and image backup before running this.", + 'maint_image_cleanup_ignore_revisions' => 'Ignore images in revisions', + 'maint_image_cleanup_run' => 'Run Cleanup', + 'maint_image_cleanup_warning' => ':count potentially unused images were found. Are you sure you want to delete these images?', + 'maint_image_cleanup_success' => ':count potentially unused images found and deleted!', + 'maint_image_cleanup_nothing_found' => 'No unused images found, Nothing deleted!', + /** * Role settings */ diff --git a/resources/views/settings/maintenance.blade.php b/resources/views/settings/maintenance.blade.php new file mode 100644 index 000000000..abf793ade --- /dev/null +++ b/resources/views/settings/maintenance.blade.php @@ -0,0 +1,49 @@ +@extends('simple-layout') + +@section('toolbar') + @include('settings/navbar', ['selected' => 'maintenance']) +@stop + +@section('body') +
+ +
+
+ BookStack @if(strpos($version, 'v') !== 0) version @endif {{ $version }} +
+ + +
+

@icon('images') {{ trans('settings.maint_image_cleanup') }}

+
+
+
+

{{ trans('settings.maint_image_cleanup_desc') }}

+
+
+
+ {!! csrf_field() !!} + +
+ @if(session()->has('cleanup-images-warning')) +

+ {{ session()->get('cleanup-images-warning') }} +

+ + + @else + + @endif +
+ +
+
+
+
+
+ +
+@stop diff --git a/resources/views/settings/navbar.blade.php b/resources/views/settings/navbar.blade.php index 0547b168c..f9db96894 100644 --- a/resources/views/settings/navbar.blade.php +++ b/resources/views/settings/navbar.blade.php @@ -2,6 +2,7 @@