3 namespace BookStack\Settings;
5 use BookStack\Activity\ActivityType;
6 use BookStack\App\AppVersion;
7 use BookStack\Entities\Tools\TrashCan;
8 use BookStack\Http\Controller;
9 use BookStack\Permissions\Permission;
10 use BookStack\References\ReferenceStore;
11 use BookStack\Uploads\ImageService;
12 use Illuminate\Http\Request;
14 class MaintenanceController extends Controller
17 * Show the page for application maintenance.
19 public function index(TrashCan $trashCan)
21 $this->checkPermission(Permission::SettingsManage);
22 $this->setPageTitle(trans('settings.maint'));
24 // Recycle bin details
25 $recycleStats = $trashCan->getTrashedCounts();
27 return view('settings.maintenance', [
28 'version' => AppVersion::get(),
29 'recycleStats' => $recycleStats,
34 * Action to clean-up images in the system.
36 public function cleanupImages(Request $request, ImageService $imageService)
38 $this->checkPermission(Permission::SettingsManage);
39 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images');
41 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
42 $dryRun = !($request->has('confirm'));
44 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
45 $deleteCount = count($imagesToDelete);
46 if ($deleteCount === 0) {
47 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
49 return redirect('/settings/maintenance')->withInput();
53 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
55 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
58 return redirect('/settings/maintenance#image-cleanup')->withInput();
62 * Action to send a test e-mail to the current user.
64 public function sendTestEmail()
66 $this->checkPermission(Permission::SettingsManage);
67 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
70 user()->notifyNow(new TestEmailNotification());
71 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
72 } catch (\Exception $exception) {
73 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
74 $this->showErrorNotification($errorMessage);
77 return redirect('/settings/maintenance#image-cleanup');
81 * Action to regenerate the reference index in the system.
83 public function regenerateReferences(ReferenceStore $referenceStore)
85 $this->checkPermission(Permission::SettingsManage);
86 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'regenerate-references');
89 $referenceStore->updateForAll();
90 $this->showSuccessNotification(trans('settings.maint_regen_references_success'));
91 } catch (\Exception $exception) {
92 $this->showErrorNotification($exception->getMessage());
95 return redirect('/settings/maintenance#regenerate-references');