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

53 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Livewire\Project\Database;
use Livewire\Component;
class ScheduledBackups extends Component
{
public $database;
public $parameters;
2023-11-07 11:11:47 +00:00
public $type;
public $selectedBackup;
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();
$this->emit('success', 'Scheduled backup deleted successfully.');
$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);
}
}
}