Refactor + package updates + improve local backups
This commit is contained in:
@@ -26,6 +26,29 @@ class DatabaseController extends Controller
|
||||
return view('project.database.configuration', ['database' => $database]);
|
||||
}
|
||||
|
||||
public function backup_logs()
|
||||
{
|
||||
$backup_uuid = request()->route('backup_uuid');
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
|
||||
if (!$environment) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$database = $environment->databases->where('uuid', request()->route('database_uuid'))->first();
|
||||
if (!$database) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$backup = $database->scheduledBackups->where('uuid', $backup_uuid)->first();
|
||||
if (!$backup) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$backup_executions = collect($backup->executions)->sortByDesc('created_at');
|
||||
return view('project.database.backups.logs', ['database' => $database, 'backup' => $backup, 'backup_executions' => $backup_executions]);
|
||||
}
|
||||
|
||||
public function backups()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
@@ -40,6 +63,6 @@ class DatabaseController extends Controller
|
||||
if (!$database) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
return view('project.database.backups', ['database' => $database]);
|
||||
return view('project.database.backups.all', ['database' => $database]);
|
||||
}
|
||||
}
|
||||
|
||||
41
app/Http/Livewire/Project/Database/BackupEdit.php
Normal file
41
app/Http/Livewire/Project/Database/BackupEdit.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class BackupEdit extends Component
|
||||
{
|
||||
public $backup;
|
||||
|
||||
protected $rules = [
|
||||
'backup.enabled' => 'required|boolean',
|
||||
'backup.frequency' => 'required|string',
|
||||
'backup.number_of_backups_locally' => 'required|integer|min:1',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'backup.enabled' => 'Enabled',
|
||||
'backup.frequency' => 'Frequency',
|
||||
'backup.number_of_backups_locally' => 'Number of Backups Locally',
|
||||
];
|
||||
|
||||
public function instantSave()
|
||||
{
|
||||
$this->backup->save();
|
||||
$this->backup->refresh();
|
||||
$this->emit('success', 'Backup updated successfully');
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$isValid = validate_cron_expression($this->backup->frequency);
|
||||
if (!$isValid) {
|
||||
$this->emit('error', 'Invalid Cron / Human expression');
|
||||
return;
|
||||
}
|
||||
$this->validate();
|
||||
$this->backup->save();
|
||||
$this->backup->refresh();
|
||||
$this->emit('success', 'Backup updated successfully');
|
||||
}
|
||||
}
|
||||
24
app/Http/Livewire/Project/Database/BackupExecution.php
Normal file
24
app/Http/Livewire/Project/Database/BackupExecution.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use App\Models\ScheduledDatabaseBackupExecution;
|
||||
use Livewire\Component;
|
||||
|
||||
class BackupExecution extends Component
|
||||
{
|
||||
public ScheduledDatabaseBackupExecution $execution;
|
||||
|
||||
public function download()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
delete_backup_locally($this->execution->filename, $this->execution->scheduledDatabaseBackup->database->destination->server);
|
||||
$this->execution->delete();
|
||||
$this->emit('success', 'Backup execution deleted successfully.');
|
||||
$this->emit('refreshBackupExecutions');
|
||||
}
|
||||
}
|
||||
17
app/Http/Livewire/Project/Database/BackupExecutions.php
Normal file
17
app/Http/Livewire/Project/Database/BackupExecutions.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class BackupExecutions extends Component
|
||||
{
|
||||
public $backup;
|
||||
public $executions;
|
||||
protected $listeners = ['refreshBackupExecutions'];
|
||||
|
||||
public function refreshBackupExecutions(): void
|
||||
{
|
||||
$this->executions = collect($this->backup->executions)->sortByDesc('created_at');
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,20 @@ namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use App\Models\ScheduledDatabaseBackup;
|
||||
use Livewire\Component;
|
||||
use Poliander\Cron\CronExpression;
|
||||
|
||||
class CreateScheduledBackup extends Component
|
||||
{
|
||||
public $database;
|
||||
public $frequency;
|
||||
public bool $enabled = true;
|
||||
public bool $keep_locally = true;
|
||||
public bool $save_s3 = true;
|
||||
|
||||
protected $rules = [
|
||||
'frequency' => 'required|string',
|
||||
'keep_locally' => 'required|boolean',
|
||||
'save_s3' => 'required|boolean',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'frequency' => 'Backup Frequency',
|
||||
'keep_locally' => 'Keep Locally',
|
||||
'save_s3' => 'Save to S3',
|
||||
];
|
||||
|
||||
@@ -29,13 +25,7 @@ class CreateScheduledBackup extends Component
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
|
||||
$expression = new CronExpression($this->frequency);
|
||||
$isValid = $expression->isValid();
|
||||
|
||||
if (isset(VALID_CRON_STRINGS[$this->frequency])) {
|
||||
$isValid = true;
|
||||
}
|
||||
$isValid = validate_cron_expression($this->frequency);
|
||||
if (!$isValid) {
|
||||
$this->emit('error', 'Invalid Cron / Human expression');
|
||||
return;
|
||||
@@ -43,7 +33,6 @@ class CreateScheduledBackup extends Component
|
||||
ScheduledDatabaseBackup::create([
|
||||
'enabled' => true,
|
||||
'frequency' => $this->frequency,
|
||||
'keep_locally' => $this->keep_locally,
|
||||
'save_s3' => $this->save_s3,
|
||||
'database_id' => $this->database->id,
|
||||
'database_type' => $this->database->getMorphClass(),
|
||||
@@ -54,7 +43,6 @@ class CreateScheduledBackup extends Component
|
||||
general_error_handler($e, $this);
|
||||
} finally {
|
||||
$this->frequency = '';
|
||||
$this->keep_locally = true;
|
||||
$this->save_s3 = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,22 @@ use Livewire\Component;
|
||||
class ScheduledBackups extends Component
|
||||
{
|
||||
public $database;
|
||||
public $parameters;
|
||||
protected $listeners = ['refreshScheduledBackups'];
|
||||
|
||||
public function refreshScheduledBackups()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->parameters = get_route_parameters();
|
||||
}
|
||||
|
||||
public function delete($scheduled_backup_id): void
|
||||
{
|
||||
$this->database->scheduledBackups->find($scheduled_backup_id)->delete();
|
||||
$this->emit('success', 'Scheduled backup deleted successfully.');
|
||||
$this->refreshScheduledBackups();
|
||||
}
|
||||
|
||||
public function refreshScheduledBackups(): void
|
||||
{
|
||||
ray('refreshScheduledBackups');
|
||||
$this->database->refresh();
|
||||
|
||||
Reference in New Issue
Block a user