coolify/app/Notifications/Database/BackupSuccess.php

62 lines
1.6 KiB
PHP
Raw Normal View History

2023-08-10 21:00:02 +02: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 BackupSuccess extends Notification implements ShouldQueue
{
use Queueable;
2024-04-29 09:38:45 +02:00
public $backoff = 10;
2024-06-10 22:43:34 +02:00
2024-04-29 09:38:45 +02:00
public $tries = 3;
2024-06-10 22:43:34 +02:00
2023-09-01 15:52:18 +02:00
public string $name;
2024-06-10 22:43:34 +02:00
2023-09-01 15:52:18 +02:00
public string $frequency;
2023-08-10 21:00:02 +02:00
2024-04-29 09:38:45 +02:00
public function __construct(ScheduledDatabaseBackup $backup, public $database, public $database_name)
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-09-06 14:31:38 +02:00
return setNotificationChannels($notifiable, 'database_backups');
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: Backup successfully done for {$this->database->name}");
2023-09-01 15:52:18 +02:00
$mail->view('emails.backup-success', [
'name' => $this->name,
'database_name' => $this->database_name,
2023-09-01 15:52:18 +02:00
'frequency' => $this->frequency,
]);
2024-06-10 22:43:34 +02:00
2023-08-10 21:00:02 +02:00
return $mail;
}
public function toDiscord(): string
{
return "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful.";
2023-08-10 21:00:02 +02:00
}
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
public function toTelegram(): array
{
$message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful.";
2024-04-29 09:38:45 +02:00
ray($message);
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
return [
2024-06-10 22:43:34 +02:00
'message' => $message,
2023-09-06 14:31:38 +02:00
];
}
2023-08-10 21:00:02 +02:00
}