1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Backup\Notifications\Notifications; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
6
|
|
|
use Illuminate\Notifications\Messages\SlackAttachment; |
7
|
|
|
use Illuminate\Notifications\Messages\SlackMessage; |
8
|
|
|
use Spatie\Backup\Events\BackupWasSuccessful as BackupWasSuccessfulEvent; |
9
|
|
|
use Spatie\Backup\Notifications\BaseNotification; |
10
|
|
|
|
11
|
|
View Code Duplication |
class BackupWasSuccessful extends BaseNotification |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** @var \Spatie\Backup\Events\BackupWasSuccessful */ |
14
|
|
|
protected $event; |
15
|
|
|
|
16
|
|
|
public function toMail(): MailMessage |
17
|
|
|
{ |
18
|
|
|
$mailMessage = (new MailMessage) |
19
|
|
|
->from(config('backup.notifications.mail.from.address', config('mail.from.address')), config('backup.notifications.mail.from.name', config('mail.from.name'))) |
20
|
|
|
->subject(trans('backup::notifications.backup_successful_subject', ['application_name' => $this->applicationName()])) |
21
|
|
|
->line(trans('backup::notifications.backup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()])); |
22
|
|
|
|
23
|
|
|
$this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) { |
24
|
|
|
$mailMessage->line("{$name}: $value"); |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
return $mailMessage; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function toSlack(): SlackMessage |
31
|
|
|
{ |
32
|
|
|
return (new SlackMessage) |
33
|
|
|
->success() |
34
|
|
|
->from(config('backup.notifications.slack.username'), config('backup.notifications.slack.icon')) |
35
|
|
|
->to(config('backup.notifications.slack.channel')) |
36
|
|
|
->content(trans('backup::notifications.backup_successful_subject_title')) |
37
|
|
|
->attachment(function (SlackAttachment $attachment) { |
38
|
|
|
$attachment->fields($this->backupDestinationProperties()->toArray()); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function setEvent(BackupWasSuccessfulEvent $event) |
43
|
|
|
{ |
44
|
|
|
$this->event = $event; |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
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.