2023-08-10 21:00:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\Database;
|
|
|
|
|
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
|
|
|
use App\Notifications\Channels\DiscordChannel;
|
|
|
|
use App\Notifications\Channels\EmailChannel;
|
|
|
|
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;
|
|
|
|
|
2023-09-01 15:52:18 +02:00
|
|
|
public string $name;
|
|
|
|
public string $frequency;
|
2023-08-10 21:00:02 +02:00
|
|
|
|
|
|
|
public function __construct(ScheduledDatabaseBackup $backup, public $database)
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
$channels = [];
|
2023-08-31 15:00:59 +02:00
|
|
|
$isEmailEnabled = isEmailEnabled($notifiable);
|
2023-08-10 21:00:02 +02:00
|
|
|
$isDiscordEnabled = data_get($notifiable, 'discord_enabled');
|
|
|
|
$isSubscribedToEmailEvent = data_get($notifiable, 'smtp_notifications_database_backups');
|
|
|
|
$isSubscribedToDiscordEvent = data_get($notifiable, 'discord_notifications_database_backups');
|
|
|
|
|
|
|
|
if ($isEmailEnabled && $isSubscribedToEmailEvent) {
|
|
|
|
$channels[] = EmailChannel::class;
|
|
|
|
}
|
|
|
|
if ($isDiscordEnabled && $isSubscribedToDiscordEvent) {
|
|
|
|
$channels[] = DiscordChannel::class;
|
|
|
|
}
|
|
|
|
return $channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toMail(): MailMessage
|
|
|
|
{
|
|
|
|
$mail = new MailMessage();
|
2023-09-01 15:52:18 +02:00
|
|
|
$mail->subject("✅ Backup successfully done for {$this->database->name}");
|
|
|
|
$mail->view('emails.backup-success', [
|
|
|
|
'name' => $this->name,
|
|
|
|
'frequency' => $this->frequency,
|
|
|
|
]);
|
2023-08-10 21:00:02 +02:00
|
|
|
return $mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
2023-09-01 15:52:18 +02:00
|
|
|
return "✅ Database backup for {$this->name} with frequency of {$this->frequency} was successful.";
|
2023-08-10 21:00:02 +02:00
|
|
|
}
|
|
|
|
}
|