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

64 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;
2024-06-10 20:43:34 +00:00
public $parameters;
2024-06-10 20:43:34 +00:00
2023-11-07 11:11:47 +00:00
public $type;
2024-06-10 20:43:34 +00:00
2024-05-24 15:20:20 +00:00
public ?ScheduledDatabaseBackup $selectedBackup;
2024-06-10 20:43:34 +00:00
2023-11-07 11:11:47 +00:00
public $selectedBackupId;
2024-06-10 20:43:34 +00:00
public $s3s;
2024-06-10 20:43:34 +00:00
protected $listeners = ['refreshScheduledBackups'];
2024-06-10 20:43:34 +00:00
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
}
2024-06-10 20:43:34 +00:00
public function setSelectedBackup($backupId)
{
2023-11-07 11:11:47 +00:00
$this->selectedBackupId = $backupId;
$this->selectedBackup = $this->database->scheduledBackups->find($this->selectedBackupId);
if (is_null($this->selectedBackup)) {
$this->selectedBackupId = null;
}
}
2024-06-10 20:43:34 +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.');
$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);
}
}
}