]> BookStack Code Mirror - bookstack/blob - app/Settings/MaintenanceController.php
API: Added system read endpoint
[bookstack] / app / Settings / MaintenanceController.php
1 <?php
2
3 namespace BookStack\Settings;
4
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;
12
13 class MaintenanceController extends Controller
14 {
15     /**
16      * Show the page for application maintenance.
17      */
18     public function index(TrashCan $trashCan)
19     {
20         $this->checkPermission('settings-manage');
21         $this->setPageTitle(trans('settings.maint'));
22
23         // Recycle bin details
24         $recycleStats = $trashCan->getTrashedCounts();
25
26         return view('settings.maintenance', [
27             'version'      => AppVersion::get(),
28             'recycleStats' => $recycleStats,
29         ]);
30     }
31
32     /**
33      * Action to clean-up images in the system.
34      */
35     public function cleanupImages(Request $request, ImageService $imageService)
36     {
37         $this->checkPermission('settings-manage');
38         $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images');
39
40         $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
41         $dryRun = !($request->has('confirm'));
42
43         $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
44         $deleteCount = count($imagesToDelete);
45         if ($deleteCount === 0) {
46             $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
47
48             return redirect('/settings/maintenance')->withInput();
49         }
50
51         if ($dryRun) {
52             session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
53         } else {
54             $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
55         }
56
57         return redirect('/settings/maintenance#image-cleanup')->withInput();
58     }
59
60     /**
61      * Action to send a test e-mail to the current user.
62      */
63     public function sendTestEmail()
64     {
65         $this->checkPermission('settings-manage');
66         $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
67
68         try {
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);
74         }
75
76         return redirect('/settings/maintenance#image-cleanup');
77     }
78
79     /**
80      * Action to regenerate the reference index in the system.
81      */
82     public function regenerateReferences(ReferenceStore $referenceStore)
83     {
84         $this->checkPermission('settings-manage');
85         $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'regenerate-references');
86
87         try {
88             $referenceStore->updateForAll();
89             $this->showSuccessNotification(trans('settings.maint_regen_references_success'));
90         } catch (\Exception $exception) {
91             $this->showErrorNotification($exception->getMessage());
92         }
93
94         return redirect('/settings/maintenance#regenerate-references');
95     }
96 }