2023-08-10 21:00:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\Database;
|
|
|
|
|
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
2023-10-10 14:17:16 +02:00
|
|
|
use App\Notifications\Channels\DiscordChannel;
|
|
|
|
use App\Notifications\Channels\TelegramChannel;
|
2023-08-10 21:00:02 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2023-10-10 14:17:16 +02:00
|
|
|
use Illuminate\Notifications\Channels\MailChannel;
|
2023-08-10 21:00:02 +02:00
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class BackupFailed extends Notification implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
2023-09-18 15:19:27 +02:00
|
|
|
public $tries = 1;
|
2023-09-01 15:52:18 +02:00
|
|
|
public string $name;
|
|
|
|
public string $frequency;
|
2023-08-10 21:00:02 +02:00
|
|
|
|
2023-08-11 10:42:57 +02:00
|
|
|
public function __construct(ScheduledDatabaseBackup $backup, public $database, public $output)
|
2023-08-10 21:00:02 +02:00
|
|
|
{
|
2023-09-01 15:52:18 +02:00
|
|
|
$this->name = $database->name;
|
|
|
|
$this->frequency = $backup->frequency;
|
2023-08-10 21:00:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function via(object $notifiable): array
|
|
|
|
{
|
2023-10-10 14:17:16 +02:00
|
|
|
return [DiscordChannel::class, TelegramChannel::class, MailChannel::class];
|
2023-08-10 21:00:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toMail(): MailMessage
|
|
|
|
{
|
|
|
|
$mail = new MailMessage();
|
2023-10-10 13:10:43 +02:00
|
|
|
$mail->subject("Coolify: [ACTION REQUIRED] Backup FAILED for {$this->database->name}");
|
2023-09-01 15:52:18 +02:00
|
|
|
$mail->view('emails.backup-failed', [
|
|
|
|
'name' => $this->name,
|
|
|
|
'frequency' => $this->frequency,
|
|
|
|
'output' => $this->output,
|
|
|
|
]);
|
2023-08-10 21:00:02 +02:00
|
|
|
return $mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
2023-10-10 13:10:43 +02:00
|
|
|
return "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}";
|
2023-08-10 21:00:02 +02:00
|
|
|
}
|
2023-09-06 14:31:38 +02:00
|
|
|
public function toTelegram(): array
|
|
|
|
{
|
2023-10-10 13:10:43 +02:00
|
|
|
$message = "Coolify: Database backup for {$this->name} with frequency of {$this->frequency} was FAILED.\n\nReason: {$this->output}";
|
2023-09-06 14:31:38 +02:00
|
|
|
return [
|
|
|
|
"message" => $message,
|
|
|
|
];
|
|
|
|
}
|
2023-08-10 21:00:02 +02:00
|
|
|
}
|