lasthourcloud/app/Livewire/Project/Database/ScheduledBackups.php

54 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Database;
2024-05-24 15:20:20 +00:00
use App\Models\ScheduledDatabaseBackup;
use Livewire\Component;
class ScheduledBackups extends Component
{
public $database;
public $parameters;
2023-11-07 11:11:47 +00:00
public $type;
2024-05-24 15:20:20 +00:00
public ?ScheduledDatabaseBackup $selectedBackup;
2023-11-07 11:11:47 +00:00
public $selectedBackupId;
public $s3s;
protected $listeners = ['refreshScheduledBackups'];
2023-11-07 11:11:47 +00:00
protected $queryString = ['selectedBackupId'];
public function mount(): void
{
2023-11-07 11:11:47 +00:00
if ($this->selectedBackupId) {
$this->setSelectedBackup($this->selectedBackupId);
}
$this->parameters = get_route_parameters();
2023-11-07 11:11:47 +00:00
if ($this->database->getMorphClass() === 'App\Models\ServiceDatabase') {
$this->type = 'service-database';
} else {
$this->type = 'database';
}
$this->s3s = currentTeam()->s3s;
2023-11-07 11:11:47 +00:00
}
public function setSelectedBackup($backupId) {
$this->selectedBackupId = $backupId;
$this->selectedBackup = $this->database->scheduledBackups->find($this->selectedBackupId);
if (is_null($this->selectedBackup)) {
$this->selectedBackupId = null;
}
}
public function delete($scheduled_backup_id): void
{
$this->database->scheduledBackups->find($scheduled_backup_id)->delete();
2024-02-22 13:53:42 +00:00
$this->dispatch('success', 'Scheduled backup deleted.');
$this->refreshScheduledBackups();
}
2023-11-07 11:11:47 +00:00
public function refreshScheduledBackups(?int $id = null): void
{
$this->database->refresh();
2023-11-07 11:11:47 +00:00
if ($id) {
$this->setSelectedBackup($id);
}
}
}