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
|
|
|
|
2026-06-29 08:30:07 +00:00
|
|
|
use App\Models\ServiceDatabase;
|
2026-07-16 12:30:58 +00:00
|
|
|
use Illuminate\Contracts\View\View;
|
2025-08-23 16:50:35 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2023-08-09 15:57:27 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class ScheduledBackups extends Component
|
|
|
|
|
{
|
2025-08-23 16:50:35 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2023-08-09 15:57:27 +00:00
|
|
|
public $database;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-10 13:52:54 +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
|
|
|
|
2025-04-30 14:44:44 +00:00
|
|
|
public string $custom_type = 'mysql';
|
|
|
|
|
|
2023-08-09 15:57:27 +00:00
|
|
|
protected $listeners = ['refreshScheduledBackups'];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-10 13:52:54 +00:00
|
|
|
public function mount(): void
|
|
|
|
|
{
|
|
|
|
|
$this->parameters = get_route_parameters();
|
2026-06-29 08:30:07 +00:00
|
|
|
if ($this->database->getMorphClass() === ServiceDatabase::class) {
|
2023-11-07 11:11:47 +00:00
|
|
|
$this->type = 'service-database';
|
|
|
|
|
} else {
|
|
|
|
|
$this->type = 'database';
|
|
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-04-30 14:44:44 +00:00
|
|
|
public function setCustomType()
|
|
|
|
|
{
|
2026-02-25 13:20:29 +00:00
|
|
|
try {
|
|
|
|
|
$this->authorize('update', $this->database);
|
|
|
|
|
|
|
|
|
|
$this->database->custom_type = $this->custom_type;
|
|
|
|
|
$this->database->save();
|
|
|
|
|
$this->dispatch('success', 'Database type set.');
|
|
|
|
|
$this->refreshScheduledBackups();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
handleError($e, $this);
|
|
|
|
|
}
|
2025-04-30 14:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-10 13:52:54 +00:00
|
|
|
public function delete($scheduled_backup_id): void
|
|
|
|
|
{
|
2026-02-25 13:20:29 +00:00
|
|
|
try {
|
|
|
|
|
$this->authorize('manageBackups', $this->database);
|
|
|
|
|
|
|
|
|
|
$backup = $this->database->scheduledBackups->find($scheduled_backup_id);
|
|
|
|
|
$backup->delete();
|
|
|
|
|
$this->dispatch('success', 'Scheduled backup deleted.');
|
|
|
|
|
$this->refreshScheduledBackups();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
handleError($e, $this);
|
|
|
|
|
}
|
2023-08-10 13:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
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();
|
2025-04-30 14:44:44 +00:00
|
|
|
$this->dispatch('refreshScheduledBackups');
|
2023-08-09 15:57:27 +00:00
|
|
|
}
|
2026-07-16 12:30:58 +00:00
|
|
|
|
|
|
|
|
public function render(): View
|
|
|
|
|
{
|
|
|
|
|
$this->database->loadMissing('scheduledBackups.s3');
|
|
|
|
|
|
|
|
|
|
return view('livewire.project.database.scheduled-backups');
|
|
|
|
|
}
|
2023-08-09 15:57:27 +00:00
|
|
|
}
|