|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arcanesoft\Backups\Http\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Arcanesoft\Backups\Policies\StatusesPolicy; |
|
8
|
|
|
use Arcanesoft\Backups\Services\BackupService; |
|
9
|
|
|
use Arcanesoft\Foundation\Support\Traits\HasNotifications; |
|
10
|
|
|
use Illuminate\Support\Facades\Log; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class StatusesController |
|
14
|
|
|
* |
|
15
|
|
|
* @author ARCANEDEV <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class StatusesController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/* ----------------------------------------------------------------- |
|
20
|
|
|
| Traits |
|
21
|
|
|
| ----------------------------------------------------------------- |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use HasNotifications; |
|
25
|
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
|
27
|
|
|
| Properties |
|
28
|
|
|
| ----------------------------------------------------------------- |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** @var \Arcanesoft\Backups\Services\BackupService */ |
|
32
|
|
|
protected $backupService; |
|
33
|
|
|
|
|
34
|
|
|
/* ----------------------------------------------------------------- |
|
35
|
|
|
| Constructor |
|
36
|
|
|
| ----------------------------------------------------------------- |
|
37
|
|
|
*/ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* StatusesController constructor. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(BackupService $backupService) |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct(); |
|
45
|
|
|
|
|
46
|
|
|
$this->setCurrentSidebarItem('foundation::backups'); |
|
47
|
|
|
$this->addBreadcrumbRoute(__('Backups'), 'admin::backups.statuses.index'); |
|
48
|
|
|
|
|
49
|
|
|
$this->backupService = $backupService; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/* ----------------------------------------------------------------- |
|
53
|
|
|
| Main Methods |
|
54
|
|
|
| ----------------------------------------------------------------- |
|
55
|
|
|
*/ |
|
56
|
|
|
|
|
57
|
|
|
public function index() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->authorize(StatusesPolicy::ability('index')); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$statuses = $this->backupService->statuses(); |
|
62
|
|
|
|
|
63
|
|
|
$this->setTitle($title = __('List of Monitor Statuses')); |
|
|
|
|
|
|
64
|
|
|
$this->addBreadcrumb($title); |
|
65
|
|
|
|
|
66
|
|
|
return $this->view('statuses.index', compact('statuses')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function show($index) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->authorize(StatusesPolicy::ability('show')); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$status = $this->backupService->getStatus($index); |
|
74
|
|
|
|
|
75
|
|
|
abort_if(is_null($status), 404); |
|
76
|
|
|
|
|
77
|
|
|
$this->setTitle($title = __('Monitor Status')); |
|
|
|
|
|
|
78
|
|
|
$this->addBreadcrumb($title); |
|
79
|
|
|
|
|
80
|
|
|
return $this->view('statuses.show', compact('status')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function backup() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->authorize(StatusesPolicy::ability('create')); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
if ($this->backupService->runBackups()) { |
|
88
|
|
|
return static::jsonResponseSuccess([ |
|
89
|
|
|
'message' => $this->transNotification('created'), |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return static::jsonResponseError([ |
|
94
|
|
|
'message' => 'There is an error while running the backups.' |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function clear() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->authorize(StatusesPolicy::ability('clean')); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
if ($this->backupService->clearBackups()) { |
|
103
|
|
|
return static::jsonResponseSuccess([ |
|
104
|
|
|
'message' => $this->transNotification('cleared'), |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return static::jsonResponseError(['message' => 'There is an error while running the backups.']); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/* ----------------------------------------------------------------- |
|
112
|
|
|
| Other Methods |
|
113
|
|
|
| ----------------------------------------------------------------- |
|
114
|
|
|
*/ |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Notify with translation. |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $action |
|
120
|
|
|
* @param array $replace |
|
121
|
|
|
* @param array $context |
|
122
|
|
|
* |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
|
126
|
|
|
{ |
|
127
|
|
|
$title = trans("backups::statuses.messages.{$action}.title"); |
|
128
|
|
|
$message = trans("backups::statuses.messages.{$action}.message", $replace); |
|
129
|
|
|
|
|
130
|
|
|
Log::info($message, $context); |
|
131
|
|
|
|
|
132
|
|
|
$this->notifySuccess($title, $message); |
|
133
|
|
|
|
|
134
|
|
|
return $message; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.