|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\Backup\Notifications; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notification; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Spatie\Backup\BackupDestination\BackupDestination; |
|
8
|
|
|
use Spatie\Backup\Helpers\Format; |
|
9
|
|
|
|
|
10
|
|
|
abstract class BaseNotification extends Notification |
|
11
|
|
|
{ |
|
12
|
|
|
public function via(): array |
|
13
|
|
|
{ |
|
14
|
|
|
$notificationChannels = config('backup.notifications.notifications.'.static::class); |
|
15
|
|
|
|
|
16
|
|
|
return array_filter($notificationChannels); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function applicationName(): string |
|
20
|
|
|
{ |
|
21
|
|
|
return config('app.name') ?? config('app.url') ?? 'Laravel application'; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function backupName(): string |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->backupDestination()->backupName(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function diskName(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->backupDestination()->diskName(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function backupDestinationProperties(): Collection |
|
35
|
|
|
{ |
|
36
|
|
|
$backupDestination = $this->backupDestination(); |
|
37
|
|
|
|
|
38
|
|
|
if (! $backupDestination) { |
|
39
|
|
|
return collect(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$backupDestination->fresh(); |
|
43
|
|
|
|
|
44
|
|
|
$newestBackup = $backupDestination->newestBackup(); |
|
45
|
|
|
$oldestBackup = $backupDestination->oldestBackup(); |
|
46
|
|
|
|
|
47
|
|
|
return collect([ |
|
48
|
|
|
'Application name' => $this->applicationName(), |
|
49
|
|
|
'Backup name' => $this->backupName(), |
|
50
|
|
|
'Disk' => $backupDestination->diskName(), |
|
51
|
|
|
'Newest backup size' => $newestBackup ? Format::humanReadableSize($newestBackup->size()) : 'No backups were made yet', |
|
52
|
|
|
'Number of backups' => (string) $backupDestination->backups()->count(), |
|
53
|
|
|
'Total storage used' => Format::humanReadableSize($backupDestination->backups()->size()), |
|
54
|
|
|
'Newest backup date' => $newestBackup ? $newestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet', |
|
55
|
|
|
'Oldest backup date' => $oldestBackup ? $oldestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet', |
|
56
|
|
|
])->filter(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function backupDestination(): ?BackupDestination |
|
60
|
|
|
{ |
|
61
|
|
|
if (isset($this->event->backupDestination)) { |
|
62
|
|
|
return $this->event->backupDestination; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (isset($this->event->backupDestinationStatus)) { |
|
66
|
|
|
return $this->event->backupDestinationStatus->backupDestination(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return null; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: