3 namespace BookStack\Http\Controllers;
5 use BookStack\Actions\ActivityType;
6 use BookStack\Entities\Tools\TrashCan;
7 use BookStack\Notifications\TestEmail;
8 use BookStack\References\ReferenceStore;
9 use BookStack\Uploads\ImageService;
10 use Illuminate\Http\Request;
12 class MaintenanceController extends Controller
15 * Show the page for application maintenance.
17 public function index()
19 $this->checkPermission('settings-manage');
20 $this->setPageTitle(trans('settings.maint'));
22 // Get application version
23 $version = trim(file_get_contents(base_path('version')));
25 // Recycle bin details
26 $recycleStats = (new TrashCan())->getTrashedCounts();
28 return view('settings.maintenance', [
29 'version' => $version,
30 'recycleStats' => $recycleStats,
35 * Action to clean-up images in the system.
37 public function cleanupImages(Request $request, ImageService $imageService)
39 $this->checkPermission('settings-manage');
40 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images');
42 $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
43 $dryRun = !($request->has('confirm'));
45 $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
46 $deleteCount = count($imagesToDelete);
47 if ($deleteCount === 0) {
48 $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
50 return redirect('/settings/maintenance')->withInput();
54 session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
56 $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
59 return redirect('/settings/maintenance#image-cleanup')->withInput();
63 * Action to send a test e-mail to the current user.
65 public function sendTestEmail()
67 $this->checkPermission('settings-manage');
68 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
71 user()->notifyNow(new TestEmail());
72 $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
73 } catch (\Exception $exception) {
74 $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
75 $this->showErrorNotification($errorMessage);
78 return redirect('/settings/maintenance#image-cleanup');
82 * Action to regenerate the reference index in the system.
84 public function regenerateReferences(ReferenceStore $referenceStore)
86 $this->checkPermission('settings-manage');
87 $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'regenerate-references');
90 $referenceStore->updateForAllPages();
91 $this->showSuccessNotification(trans('settings.maint_regen_references_success'));
92 } catch (\Exception $exception) {
93 $this->showErrorNotification($exception->getMessage());
96 return redirect('/settings/maintenance#regenerate-references');