@@ 9-40 (lines=32) @@ | ||
6 | use Spatie\UptimeMonitor\MonitorRepository; |
|
7 | use Spatie\Url\Url; |
|
8 | ||
9 | class DisableMonitor extends BaseCommand |
|
10 | { |
|
11 | protected $signature = 'monitor:disable {url}'; |
|
12 | ||
13 | protected $description = 'Disable monitors'; |
|
14 | ||
15 | public function handle() |
|
16 | { |
|
17 | foreach (explode(',', $this->argument('url')) as $url) { |
|
18 | $this->disableMonitor(trim($url)); |
|
19 | } |
|
20 | } |
|
21 | ||
22 | protected function disableMonitor(string $url) |
|
23 | { |
|
24 | if (! $monitor = MonitorRepository::findByUrl($url)) { |
|
25 | $this->error("There is no monitor configured for url `{$url}`."); |
|
26 | ||
27 | return; |
|
28 | } |
|
29 | ||
30 | if (! $monitor->enabled) { |
|
31 | $this->warn("The monitor for url `{$url}` was already disabled."); |
|
32 | ||
33 | return; |
|
34 | } |
|
35 | ||
36 | $monitor->disable(); |
|
37 | ||
38 | $this->info("The monitor for url `{$url}` is now disabled"); |
|
39 | } |
|
40 | } |
|
41 |
@@ 9-39 (lines=31) @@ | ||
6 | use Spatie\UptimeMonitor\MonitorRepository; |
|
7 | use Spatie\Url\Url; |
|
8 | ||
9 | class EnableMonitor extends BaseCommand |
|
10 | { |
|
11 | protected $signature = 'monitor:enable {url}'; |
|
12 | ||
13 | protected $description = 'Enable a monitors'; |
|
14 | ||
15 | public function handle() |
|
16 | { |
|
17 | foreach (explode(',', $this->argument('url')) as $url) { |
|
18 | $this->enableMonitor(trim($url)); |
|
19 | } |
|
20 | } |
|
21 | ||
22 | protected function enableMonitor(string $url) |
|
23 | { |
|
24 | if (! $monitor = MonitorRepository::findByUrl($url)) { |
|
25 | $this->error("There is no monitor configured for url `{$url}`."); |
|
26 | ||
27 | return; |
|
28 | } |
|
29 | ||
30 | if ($monitor->enabled) { |
|
31 | $this->warn("The monitor for url `{$url}` was already enabled."); |
|
32 | ||
33 | return; |
|
34 | } |
|
35 | ||
36 | $monitor->enable(); |
|
37 | $this->info("The monitor for url `{$url}` is now enabled"); |
|
38 | } |
|
39 | } |
|
40 |