@@ 11-61 (lines=51) @@ | ||
8 | use Spatie\Backup\Events\BackupHasFailed as BackupHasFailedEvent; |
|
9 | use Spatie\Backup\Notifications\BaseNotification; |
|
10 | ||
11 | class BackupHasFailed extends BaseNotification |
|
12 | { |
|
13 | /** @var \Spatie\Backup\Events\BackupHasFailed */ |
|
14 | protected $event; |
|
15 | ||
16 | public function toMail(): MailMessage |
|
17 | { |
|
18 | $mailMessage = (new MailMessage) |
|
19 | ->error() |
|
20 | ->from(config('backup.notifications.mail.from.address', config('mail.from.address')), config('backup.notifications.mail.from.name', config('mail.from.name'))) |
|
21 | ->subject(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()])) |
|
22 | ->line(trans('backup::notifications.backup_failed_body', ['application_name' => $this->applicationName()])) |
|
23 | ->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()])) |
|
24 | ->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()])); |
|
25 | ||
26 | $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) { |
|
27 | $mailMessage->line("{$name}: $value"); |
|
28 | }); |
|
29 | ||
30 | return $mailMessage; |
|
31 | } |
|
32 | ||
33 | public function toSlack(): SlackMessage |
|
34 | { |
|
35 | return (new SlackMessage) |
|
36 | ->error() |
|
37 | ->from(config('backup.notifications.slack.username'), config('backup.notifications.slack.icon')) |
|
38 | ->to(config('backup.notifications.slack.channel')) |
|
39 | ->content(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()])) |
|
40 | ->attachment(function (SlackAttachment $attachment) { |
|
41 | $attachment |
|
42 | ->title(trans('backup::notifications.exception_message_title')) |
|
43 | ->content($this->event->exception->getMessage()); |
|
44 | }) |
|
45 | ->attachment(function (SlackAttachment $attachment) { |
|
46 | $attachment |
|
47 | ->title(trans('backup::notifications.exception_trace_title')) |
|
48 | ->content($this->event->exception->getTraceAsString()); |
|
49 | }) |
|
50 | ->attachment(function (SlackAttachment $attachment) { |
|
51 | $attachment->fields($this->backupDestinationProperties()->toArray()); |
|
52 | }); |
|
53 | } |
|
54 | ||
55 | public function setEvent(BackupHasFailedEvent $event) |
|
56 | { |
|
57 | $this->event = $event; |
|
58 | ||
59 | return $this; |
|
60 | } |
|
61 | } |
|
62 |
@@ 11-61 (lines=51) @@ | ||
8 | use Spatie\Backup\Events\CleanupHasFailed as CleanupHasFailedEvent; |
|
9 | use Spatie\Backup\Notifications\BaseNotification; |
|
10 | ||
11 | class CleanupHasFailed extends BaseNotification |
|
12 | { |
|
13 | /** @var \Spatie\Backup\Events\CleanupHasFailed */ |
|
14 | protected $event; |
|
15 | ||
16 | public function toMail(): MailMessage |
|
17 | { |
|
18 | $mailMessage = (new MailMessage) |
|
19 | ->error() |
|
20 | ->from(config('backup.notifications.mail.from.address', config('mail.from.address')), config('backup.notifications.mail.from.name', config('mail.from.name'))) |
|
21 | ->subject(trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()])) |
|
22 | ->line(trans('backup::notifications.cleanup_failed_body', ['application_name' => $this->applicationName()])) |
|
23 | ->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()])) |
|
24 | ->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()])); |
|
25 | ||
26 | $this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) { |
|
27 | $mailMessage->line("{$name}: $value"); |
|
28 | }); |
|
29 | ||
30 | return $mailMessage; |
|
31 | } |
|
32 | ||
33 | public function toSlack(): SlackMessage |
|
34 | { |
|
35 | return (new SlackMessage) |
|
36 | ->error() |
|
37 | ->from(config('backup.notifications.slack.username'), config('backup.notifications.slack.icon')) |
|
38 | ->to(config('backup.notifications.slack.channel')) |
|
39 | ->content(trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()])) |
|
40 | ->attachment(function (SlackAttachment $attachment) { |
|
41 | $attachment |
|
42 | ->title(trans('backup::notifications.exception_message_title')) |
|
43 | ->content($this->event->exception->getMessage()); |
|
44 | }) |
|
45 | ->attachment(function (SlackAttachment $attachment) { |
|
46 | $attachment |
|
47 | ->title(trans('backup::notifications.exception_message_trace')) |
|
48 | ->content($this->event->exception->getTraceAsString()); |
|
49 | }) |
|
50 | ->attachment(function (SlackAttachment $attachment) { |
|
51 | $attachment->fields($this->backupDestinationProperties()->toArray()); |
|
52 | }); |
|
53 | } |
|
54 | ||
55 | public function setEvent(CleanupHasFailedEvent $event) |
|
56 | { |
|
57 | $this->event = $event; |
|
58 | ||
59 | return $this; |
|
60 | } |
|
61 | } |
|
62 |