1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\Notifications\Notifications; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
6
|
|
|
use Illuminate\Notifications\Messages\SlackAttachment; |
7
|
|
|
use Illuminate\Notifications\Messages\SlackMessage; |
8
|
|
|
use Spatie\UptimeMonitor\Events\SiteRestored as SiteRestoredEvent; |
9
|
|
|
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
10
|
|
|
use Spatie\UptimeMonitor\Notifications\BaseNotification; |
11
|
|
|
|
12
|
|
View Code Duplication |
class SiteRestored extends BaseNotification |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** @var \Spatie\UptimeMonitor\Events\SiteDown */ |
15
|
|
|
protected $event; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get the mail representation of the notification. |
19
|
|
|
* |
20
|
|
|
* @param mixed $notifiable |
21
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
22
|
|
|
*/ |
23
|
|
|
public function toMail($notifiable) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$mailMessage = (new MailMessage) |
26
|
|
|
->success() |
27
|
|
|
->subject("Site {$this->event->site->url} has been restored.") |
28
|
|
|
->line('Site has been restored'); |
29
|
|
|
|
30
|
|
|
return $mailMessage; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function toSlack($notifiable) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return (new SlackMessage) |
36
|
|
|
->success() |
37
|
|
|
->content("Site {$this->event->site->url} has been restored") |
38
|
|
|
->attachment(function (SlackAttachment $attachment) { |
39
|
|
|
$attachment->fields($this->getSiteProperties()); |
40
|
|
|
}); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getSiteProperties($extraProperties = []): array |
44
|
|
|
{ |
45
|
|
|
$extraProperties = [ |
46
|
|
|
'online since' => $this->event->site->formattedLastUpdatedStatusChangeDate, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
return parent::getSiteProperties($extraProperties); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isStillRelevant(): bool |
53
|
|
|
{ |
54
|
|
|
return $this->event->site->uptime_status == UptimeStatus::UP; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setEvent(SiteRestoredEvent $event) |
58
|
|
|
{ |
59
|
|
|
$this->event = $event; |
|
|
|
|
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.