|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\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
|
|
|
/** |
|
13
|
|
|
* Get the notification's delivery channels. |
|
14
|
|
|
* |
|
15
|
|
|
* @param mixed $notifiable |
|
16
|
|
|
* @return array |
|
17
|
|
|
*/ |
|
18
|
|
|
public function via($notifiable) |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
return config('laravel-backup.notifications.notifications.'.static::class); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getApplicationName(): string |
|
24
|
|
|
{ |
|
25
|
|
|
return config('app.name'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getDiskName(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->getBackupDestination()->getDiskName(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function getBackupDestinationProperties(): Collection |
|
34
|
|
|
{ |
|
35
|
|
|
$backupDestination = $this->getBackupDestination(); |
|
36
|
|
|
|
|
37
|
|
|
if (! $backupDestination) { |
|
38
|
|
|
return collect(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$newestBackup = $backupDestination->getNewestBackup(); |
|
42
|
|
|
$oldestBackup = $backupDestination->getOldestBackup(); |
|
43
|
|
|
|
|
44
|
|
|
return collect([ |
|
45
|
|
|
'Application name' => $this->getApplicationName(), |
|
46
|
|
|
'Disk' => $backupDestination->getDiskName(), |
|
47
|
|
|
'Newest backup size' => $newestBackup ? Format::getHumanReadableSize($newestBackup->size()) : 'No backups were made yet', |
|
48
|
|
|
'Amount of backups' => $backupDestination->getBackups()->count(), |
|
49
|
|
|
'Total storage used' => Format::getHumanReadableSize($backupDestination->getBackups()->size()), |
|
50
|
|
|
'Newest backup date' => $newestBackup ? $newestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet', |
|
51
|
|
|
'Oldest backup date' => $oldestBackup ? $oldestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet', |
|
52
|
|
|
])->filter(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return \Spatie\Backup\BackupDestination\BackupDestination|null |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getBackupDestination() |
|
59
|
|
|
{ |
|
60
|
|
|
if (isset($this->event->backupDestination)) { |
|
61
|
|
|
return $this->event->backupDestination; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (isset($this->event->backupDestinationStatus)) { |
|
65
|
|
|
return $this->event->backupDestinationStatus->getBackupDestination(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.