1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Backup\Notifications; |
4
|
|
|
|
5
|
|
|
use Spatie\Backup\Events\BackupHasFailed; |
6
|
|
|
use Spatie\Backup\Events\BackupWasSuccessful; |
7
|
|
|
use Spatie\Backup\Events\CleanupHasFailed; |
8
|
|
|
use Spatie\Backup\Events\CleanupWasSuccessful; |
9
|
|
|
use Spatie\Backup\Events\HealthyBackupWasFound; |
10
|
|
|
use Spatie\Backup\Events\UnhealthyBackupWasFound; |
11
|
|
|
|
12
|
|
|
class EventHandler |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \Spatie\Backup\Notifications\Notifier |
16
|
|
|
*/ |
17
|
|
|
protected $notifier; |
18
|
|
|
|
19
|
|
|
public function __construct() |
20
|
|
|
{ |
21
|
|
|
$notifierClass = config('laravel-backup.notifications.handler'); |
22
|
|
|
|
23
|
|
|
$this->notifier = app($notifierClass); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function whenBackupWasSuccessful() |
27
|
|
|
{ |
28
|
|
|
$this->notifier->backupWasSuccessful(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param \Spatie\Backup\Events\BackupHasFailed $event |
33
|
|
|
*/ |
34
|
|
|
public function whenBackupHasFailed(BackupHasFailed $event) |
35
|
|
|
{ |
36
|
|
|
$this->notifier->backupHasFailed($event->thrown, $event->backupDestination); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param \Spatie\Backup\Events\CleanupWasSuccessful $event |
41
|
|
|
*/ |
42
|
|
|
public function whenCleanupWasSuccessful(CleanupWasSuccessFul $event) |
43
|
|
|
{ |
44
|
|
|
$this->notifier->cleanupWasSuccessFul($event->backupDestination); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Spatie\Backup\Events\CleanupHasFailed $event |
49
|
|
|
*/ |
50
|
|
|
public function whenCleanupHasFailed(CleanupHasFailed $event) |
51
|
|
|
{ |
52
|
|
|
$this->notifier->cleanupHasFailed($event->thrown); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \Spatie\Backup\Events\HealthyBackupWasFound $event |
57
|
|
|
*/ |
58
|
|
|
public function whenHealthyBackupWasFound(HealthyBackupWasFound $event) |
59
|
|
|
{ |
60
|
|
|
$this->notifier->healthyBackupWasFound($event->backupDestinationStatus); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \Spatie\Backup\Events\UnhealthyBackupWasFound $event |
65
|
|
|
*/ |
66
|
|
|
public function whenUnhealthyBackupWasFound(UnhealthyBackupWasFound $event) |
67
|
|
|
{ |
68
|
|
|
$this->notifier->unHealthyBackupWasFound($event->backupDestinationStatus); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Register the listeners for the subscriber. |
73
|
|
|
* |
74
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function subscribe($events) |
79
|
|
|
{ |
80
|
|
|
$events->listen( |
81
|
|
|
BackupWasSuccessful::class, |
82
|
|
|
static::class.'@whenBackupWasSuccessful' |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$events->listen( |
86
|
|
|
BackupHasFailed::class, |
87
|
|
|
static::class.'@whenBackupHasFailed' |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$events->listen( |
91
|
|
|
CleanupWasSuccessful::class, |
92
|
|
|
static::class.'@whenCleanupWasSuccessful' |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$events->listen( |
96
|
|
|
CleanupHasFailed::class, |
97
|
|
|
static::class.'@whenCleanupHasFailed' |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$events->listen( |
101
|
|
|
BackupHasFailed::class, |
102
|
|
|
static::class.'@whenBackupHasFailed' |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$events->listen( |
106
|
|
|
HealthyBackupWasFound::class, |
107
|
|
|
static::class.'@whenHealthyBackupWasFound' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$events->listen( |
111
|
|
|
UnHealthyBackupWasFound::class, |
112
|
|
|
static::class.'@whenUnhealthyBackupWasFound' |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|