]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/MaintenanceController.php
Split out Maintenance to separate controller
[bookstack] / app / Http / Controllers / MaintenanceController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Notifications\TestEmail;
6 use BookStack\Uploads\ImageService;
7 use Illuminate\Http\Request;
8
9 class MaintenanceController extends Controller
10 {
11     /**
12      * Show the page for application maintenance.
13      */
14     public function index()
15     {
16         $this->checkPermission('settings-manage');
17         $this->setPageTitle(trans('settings.maint'));
18
19         // Get application version
20         $version = trim(file_get_contents(base_path('version')));
21
22         return view('settings.maintenance', ['version' => $version]);
23     }
24
25     /**
26      * Action to clean-up images in the system.
27      */
28     public function cleanupImages(Request $request, ImageService $imageService)
29     {
30         $this->checkPermission('settings-manage');
31
32         $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
33         $dryRun = !($request->has('confirm'));
34
35         $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
36         $deleteCount = count($imagesToDelete);
37         if ($deleteCount === 0) {
38             $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
39             return redirect('/settings/maintenance')->withInput();
40         }
41
42         if ($dryRun) {
43             session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
44         } else {
45             $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
46         }
47
48         return redirect('/settings/maintenance#image-cleanup')->withInput();
49     }
50
51     /**
52      * Action to send a test e-mail to the current user.
53      */
54     public function sendTestEmail()
55     {
56         $this->checkPermission('settings-manage');
57
58         try {
59             user()->notify(new TestEmail());
60             $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
61         } catch (\Exception $exception) {
62             $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
63             $this->showErrorNotification($errorMessage);
64         }
65
66         return redirect('/settings/maintenance#image-cleanup')->withInput();
67     }
68 }