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\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(TrashCan $trashCan)
20 $this->checkPermission('settings-manage');
21 $this->setPageTitle(trans('settings.maint'));
23 // Recycle bin details
24 $recycleStats = $trashCan->getTrashedCounts();
26 return view('settings.maintenance', [
27 'version' => AppVersion::get(),
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');
38 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images');
40 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
41 $dryRun = !($request->has('confirm'));
43 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
44 $deleteCount = count($imagesToDelete);
45 if ($deleteCount === 0) {
46 $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()->notifyNow(new TestEmailNotification());
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');
80 * Action to regenerate the reference index in the system.
82 public function regenerateReferences(ReferenceStore $referenceStore)
84 $this->checkPermission('settings-manage');
85 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'regenerate-references');
88 $referenceStore->updateForAll();
89 $this->showSuccessNotification(trans('settings.maint_regen_references_success'));
90 } catch (\Exception $exception) {
91 $this->showErrorNotification($exception->getMessage());
94 return redirect('/settings/maintenance#regenerate-references');