lasthourcloud/app/Notifications/Database/BackupFailed.php

54 lines
1.5 KiB
PHP
Raw Normal View History

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