3 namespace BookStack\Http\Controllers;
5 use BookStack\Actions\ActivityType;
6 use BookStack\Entities\Tools\TrashCan;
7 use BookStack\Notifications\TestEmail;
8 use BookStack\Uploads\ImageService;
9 use Illuminate\Http\Request;
11 class MaintenanceController extends Controller
14 * Show the page for application maintenance.
16 public function index()
18 $this->checkPermission('settings-manage');
19 $this->setPageTitle(trans('settings.maint'));
21 // Get application version
22 $version = trim(file_get_contents(base_path('version')));
24 // Recycle bin details
25 $recycleStats = (new TrashCan())->getTrashedCounts();
27 return view('settings.maintenance', [
28 'version' => $version,
29 'recycleStats' => $recycleStats,
34 * Action to clean-up images in the system.
36 public function cleanupImages(Request $request, ImageService $imageService)
38 $this->checkPermission('settings-manage');
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'));
48 return redirect('/settings/maintenance')->withInput();
52 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
54 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
57 return redirect('/settings/maintenance#image-cleanup')->withInput();
61 * Action to send a test e-mail to the current user.
63 public function sendTestEmail()
65 $this->checkPermission('settings-manage');
66 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
69 user()->notify(new TestEmail());
70 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
71 } catch (\Exception $exception) {
72 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
73 $this->showErrorNotification($errorMessage);
76 return redirect('/settings/maintenance#image-cleanup')->withInput();