coolify/app/Notifications/Database/BackupSuccess.php

89 lines
2.6 KiB
PHP
Raw Normal View History

2023-08-10 19:00:02 +00:00
<?php
namespace App\Notifications\Database;
use App\Models\ScheduledDatabaseBackup;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
2024-12-11 14:54:11 +00:00
use App\Notifications\Dto\PushoverMessage;
2024-11-12 21:37:55 +00:00
use App\Notifications\Dto\SlackMessage;
2024-12-09 15:57:15 +00:00
use Illuminate\Notifications\Messages\MailMessage;
2024-06-10 20:43:34 +00:00
class BackupSuccess extends CustomEmailNotification
2023-08-10 19:00:02 +00:00
{
2023-09-01 13:52:18 +00:00
public string $name;
2024-06-10 20:43:34 +00:00
2023-09-01 13:52:18 +00:00
public string $frequency;
2023-08-10 19:00:02 +00:00
public function __construct(ScheduledDatabaseBackup $backup, public $database, public $database_name)
2023-08-10 19:00:02 +00:00
{
$this->onQueue('high');
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
{
2024-12-09 15:57:15 +00:00
return $notifiable->getEnabledChannels('backup_success');
2023-08-10 19:00:02 +00:00
}
public function toMail(): MailMessage
{
$mail = new MailMessage;
$mail->subject("Coolify: Backup successfully done for {$this->database->name}");
$mail->view('emails.backup-success', [
2023-09-01 13:52:18 +00:00
'name' => $this->name,
'database_name' => $this->database_name,
2023-09-01 13:52:18 +00:00
'frequency' => $this->frequency,
]);
2024-06-10 20:43:34 +00:00
return $mail;
2023-08-10 19:00:02 +00:00
}
public function toDiscord(): DiscordMessage
2023-08-10 19:00:02 +00:00
{
$message = new DiscordMessage(
2024-10-21 20:40:43 +00:00
title: ':white_check_mark: Database backup successful',
description: "Database backup for {$this->name} (db:{$this->database_name}) was successful.",
color: DiscordMessage::successColor(),
);
$message->addField('Frequency', $this->frequency, true);
return $message;
2023-08-10 19:00:02 +00:00
}
2024-06-10 20:43:34 +00:00
2023-09-06 12:31:38 +00:00
public function toTelegram(): array
{
$message = "Coolify: Database backup for {$this->name} (db:{$this->database_name}) with frequency of {$this->frequency} was successful.";
2024-06-10 20:43:34 +00:00
2023-09-06 12:31:38 +00:00
return [
2024-06-10 20:43:34 +00:00
'message' => $message,
2023-09-06 12:31:38 +00:00
];
}
2024-11-12 21:37:55 +00:00
2024-12-11 14:54:11 +00:00
public function toPushover(): PushoverMessage
{
return new PushoverMessage(
title: 'Database backup successful',
level: 'success',
message: "Database backup for {$this->name} (db:{$this->database_name}) was successful.<br/><br/><b>Frequency:</b> {$this->frequency}.",
);
}
2024-11-12 21:37:55 +00:00
public function toSlack(): SlackMessage
{
2024-12-09 15:57:15 +00:00
$title = 'Database backup successful';
2024-11-12 21:37:55 +00:00
$description = "Database backup for {$this->name} (db:{$this->database_name}) was successful.";
$description .= "\n\n**Frequency:** {$this->frequency}";
return new SlackMessage(
title: $title,
description: $description,
color: SlackMessage::successColor()
);
}
2023-08-10 19:00:02 +00:00
}