3 namespace BookStack\Settings;
5 use BookStack\Activity\ActivityType;
6 use BookStack\Entities\Tools\TrashCan;
7 use BookStack\Http\Controller;
8 use BookStack\Notifications\TestEmail;
9 use BookStack\References\ReferenceStore;
10 use BookStack\Uploads\ImageService;
11 use Illuminate\Http\Request;
13 class MaintenanceController extends Controller
16 * Show the page for application maintenance.
18 public function index()
20 $this->checkPermission('settings-manage');
21 $this->setPageTitle(trans('settings.maint'));
23 // Get application version
24 $version = trim(file_get_contents(base_path('version')));
26 // Recycle bin details
27 $recycleStats = (new TrashCan())->getTrashedCounts();
29 return view('settings.maintenance', [
30 'version' => $version,
31 'recycleStats' => $recycleStats,
36 * Action to clean-up images in the system.
38 public function cleanupImages(Request $request, ImageService $imageService)
40 $this->checkPermission('settings-manage');
41 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images');
43 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
44 $dryRun = !($request->has('confirm'));
46 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
47 $deleteCount = count($imagesToDelete);
48 if ($deleteCount === 0) {
49 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
51 return redirect('/settings/maintenance')->withInput();
55 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
57 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
60 return redirect('/settings/maintenance#image-cleanup')->withInput();
64 * Action to send a test e-mail to the current user.
66 public function sendTestEmail()
68 $this->checkPermission('settings-manage');
69 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
72 user()->notifyNow(new TestEmail());
73 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
74 } catch (\Exception $exception) {
75 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
76 $this->showErrorNotification($errorMessage);
79 return redirect('/settings/maintenance#image-cleanup');
83 * Action to regenerate the reference index in the system.
85 public function regenerateReferences(ReferenceStore $referenceStore)
87 $this->checkPermission('settings-manage');
88 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'regenerate-references');
91 $referenceStore->updateForAllPages();
92 $this->showSuccessNotification(trans('settings.maint_regen_references_success'));
93 } catch (\Exception $exception) {
94 $this->showErrorNotification($exception->getMessage());
97 return redirect('/settings/maintenance#regenerate-references');