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

55 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Livewire\Project\Database;
use Livewire\Component;
class BackupEdit extends Component
{
public $backup;
2023-08-10 14:28:29 +00:00
public array $parameters;
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',
];
2023-08-10 14:28:29 +00:00
public function mount()
{
$this->parameters = get_route_parameters();
}
2023-08-10 14:25:59 +00:00
public function delete()
{
2023-08-10 14:28:29 +00:00
// TODO: Delete backup from server and add a confirmation modal
2023-08-10 14:25:59 +00:00
$this->backup->delete();
2023-08-10 14:28:29 +00:00
redirect()->route('project.database.backups.all', $this->parameters);
2023-08-10 14:25:59 +00:00
}
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');
}
}