2023-08-09 15:57:27 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Database;
|
2023-08-09 15:57:27 +00:00
|
|
|
|
2024-05-24 15:20:20 +00:00
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
2023-08-09 15:57:27 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class ScheduledBackups extends Component
|
|
|
|
{
|
|
|
|
public $database;
|
2023-08-10 13:52:54 +00:00
|
|
|
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;
|
2023-11-07 13:09:24 +00:00
|
|
|
public $s3s;
|
2023-08-09 15:57:27 +00:00
|
|
|
protected $listeners = ['refreshScheduledBackups'];
|
2023-11-07 11:11:47 +00:00
|
|
|
protected $queryString = ['selectedBackupId'];
|
2023-08-09 15:57:27 +00:00
|
|
|
|
2023-08-10 13:52:54 +00:00
|
|
|
public function mount(): void
|
|
|
|
{
|
2023-11-07 11:11:47 +00:00
|
|
|
if ($this->selectedBackupId) {
|
|
|
|
$this->setSelectedBackup($this->selectedBackupId);
|
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
$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';
|
|
|
|
}
|
2023-11-07 13:09:24 +00:00
|
|
|
$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;
|
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
}
|
|
|
|
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.');
|
2023-08-10 13:52:54 +00:00
|
|
|
$this->refreshScheduledBackups();
|
|
|
|
}
|
|
|
|
|
2023-11-07 11:11:47 +00:00
|
|
|
public function refreshScheduledBackups(?int $id = null): void
|
2023-08-09 15:57:27 +00:00
|
|
|
{
|
|
|
|
$this->database->refresh();
|
2023-11-07 11:11:47 +00:00
|
|
|
if ($id) {
|
|
|
|
$this->setSelectedBackup($id);
|
|
|
|
}
|
2023-08-09 15:57:27 +00:00
|
|
|
}
|
|
|
|
}
|