3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Managers\TrashCan;
6 use BookStack\Notifications\TestEmail;
7 use BookStack\Uploads\ImageService;
8 use Illuminate\Http\Request;
10 class MaintenanceController extends Controller
13 * Show the page for application maintenance.
15 public function index()
17 $this->checkPermission('settings-manage');
18 $this->setPageTitle(trans('settings.maint'));
20 // Get application version
21 $version = trim(file_get_contents(base_path('version')));
23 // Recycle bin details
24 $recycleStats = (new TrashCan())->getTrashedCounts();
26 return view('settings.maintenance', [
27 'version' => $version,
28 'recycleStats' => $recycleStats,
33 * Action to clean-up images in the system.
35 public function cleanupImages(Request $request, ImageService $imageService)
37 $this->checkPermission('settings-manage');
39 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
40 $dryRun = !($request->has('confirm'));
42 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
43 $deleteCount = count($imagesToDelete);
44 if ($deleteCount === 0) {
45 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
46 return redirect('/settings/maintenance')->withInput();
50 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
52 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
55 return redirect('/settings/maintenance#image-cleanup')->withInput();
59 * Action to send a test e-mail to the current user.
61 public function sendTestEmail()
63 $this->checkPermission('settings-manage');
66 user()->notify(new TestEmail());
67 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
68 } catch (\Exception $exception) {
69 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
70 $this->showErrorNotification($errorMessage);
73 return redirect('/settings/maintenance#image-cleanup')->withInput();