]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/MaintenanceController.php
Started work on the recycle bin interface
[bookstack] / app / Http / Controllers / MaintenanceController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Managers\TrashCan;
6 use BookStack\Notifications\TestEmail;
7 use BookStack\Uploads\ImageService;
8 use Illuminate\Http\Request;
9
10 class MaintenanceController extends Controller
11 {
12     /**
13      * Show the page for application maintenance.
14      */
15     public function index()
16     {
17         $this->checkPermission('settings-manage');
18         $this->setPageTitle(trans('settings.maint'));
19
20         // Get application version
21         $version = trim(file_get_contents(base_path('version')));
22
23         // Recycle bin details
24         $recycleStats = (new TrashCan())->getTrashedCounts();
25
26         return view('settings.maintenance', [
27             'version' => $version,
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
39         $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true');
40         $dryRun = !($request->has('confirm'));
41
42         $imagesToDelete = $imageService->deleteUnusedImages($checkRevisions, $dryRun);
43         $deleteCount = count($imagesToDelete);
44         if ($deleteCount === 0) {
45             $this->showWarningNotification(trans('settings.maint_image_cleanup_nothing_found'));
46             return redirect('/settings/maintenance')->withInput();
47         }
48
49         if ($dryRun) {
50             session()->flash('cleanup-images-warning', trans('settings.maint_image_cleanup_warning', ['count' => $deleteCount]));
51         } else {
52             $this->showSuccessNotification(trans('settings.maint_image_cleanup_success', ['count' => $deleteCount]));
53         }
54
55         return redirect('/settings/maintenance#image-cleanup')->withInput();
56     }
57
58     /**
59      * Action to send a test e-mail to the current user.
60      */
61     public function sendTestEmail()
62     {
63         $this->checkPermission('settings-manage');
64
65         try {
66             user()->notify(new TestEmail());
67             $this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
68         } catch (\Exception $exception) {
69             $errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
70             $this->showErrorNotification($errorMessage);
71         }
72
73         return redirect('/settings/maintenance#image-cleanup')->withInput();
74     }
75 }