2023-08-09 15:57:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Database;
|
|
|
|
|
|
|
|
use App\Models\ScheduledDatabaseBackup;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class CreateScheduledBackup extends Component
|
|
|
|
{
|
|
|
|
public $database;
|
|
|
|
public $frequency;
|
|
|
|
public bool $enabled = true;
|
|
|
|
public bool $save_s3 = true;
|
2023-08-11 14:13:53 +00:00
|
|
|
public $s3_storage_id;
|
|
|
|
public $s3s;
|
2023-08-09 15:57:27 +00:00
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'frequency' => 'required|string',
|
|
|
|
'save_s3' => 'required|boolean',
|
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
|
|
|
'frequency' => 'Backup Frequency',
|
|
|
|
'save_s3' => 'Save to S3',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function submit(): void
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->validate();
|
2023-08-10 13:52:54 +00:00
|
|
|
$isValid = validate_cron_expression($this->frequency);
|
2023-08-09 15:57:27 +00:00
|
|
|
if (!$isValid) {
|
2023-08-11 14:13:53 +00:00
|
|
|
$this->emit('error', 'Invalid Cron / Human expression.');
|
2023-08-09 15:57:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ScheduledDatabaseBackup::create([
|
|
|
|
'enabled' => true,
|
|
|
|
'frequency' => $this->frequency,
|
|
|
|
'save_s3' => $this->save_s3,
|
2023-08-11 14:13:53 +00:00
|
|
|
's3_storage_id' => $this->s3_storage_id,
|
2023-08-09 15:57:27 +00:00
|
|
|
'database_id' => $this->database->id,
|
|
|
|
'database_type' => $this->database->getMorphClass(),
|
2023-08-22 15:44:49 +00:00
|
|
|
'team_id' => currentTeam()->id,
|
2023-08-09 15:57:27 +00:00
|
|
|
]);
|
|
|
|
$this->emit('refreshScheduledBackups');
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
general_error_handler($e, $this);
|
|
|
|
} finally {
|
|
|
|
$this->frequency = '';
|
|
|
|
$this->save_s3 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|