2023-09-22 09:23:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Service;
|
|
|
|
|
2023-11-09 13:59:38 +00:00
|
|
|
use App\Actions\Database\StartDatabaseProxy;
|
|
|
|
use App\Actions\Database\StopDatabaseProxy;
|
2023-09-22 09:23:49 +00:00
|
|
|
use App\Models\ServiceDatabase;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Database extends Component
|
|
|
|
{
|
|
|
|
public ServiceDatabase $database;
|
2023-11-09 13:59:38 +00:00
|
|
|
public ?string $db_url_public = null;
|
2023-09-26 12:45:52 +00:00
|
|
|
public $fileStorages;
|
2023-11-09 13:59:38 +00:00
|
|
|
|
2023-09-26 12:45:52 +00:00
|
|
|
protected $listeners = ["refreshFileStorages"];
|
2023-09-22 09:23:49 +00:00
|
|
|
protected $rules = [
|
|
|
|
'database.human_name' => 'nullable',
|
2023-09-22 12:47:25 +00:00
|
|
|
'database.description' => 'nullable',
|
2023-09-26 12:45:52 +00:00
|
|
|
'database.image' => 'required',
|
|
|
|
'database.exclude_from_status' => 'required|boolean',
|
2023-11-09 13:59:38 +00:00
|
|
|
'database.public_port' => 'nullable|integer',
|
|
|
|
'database.is_public' => 'required|boolean',
|
2023-09-22 09:23:49 +00:00
|
|
|
];
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.database');
|
|
|
|
}
|
2023-09-26 12:45:52 +00:00
|
|
|
public function mount() {
|
2023-11-09 13:59:38 +00:00
|
|
|
if ($this->database->is_public) {
|
|
|
|
$this->db_url_public = $this->database->getServiceDatabaseUrl();
|
|
|
|
}
|
2023-09-26 12:45:52 +00:00
|
|
|
$this->refreshFileStorages();
|
|
|
|
}
|
2023-09-25 13:48:43 +00:00
|
|
|
public function instantSave() {
|
2023-11-09 13:59:38 +00:00
|
|
|
if ($this->database->is_public && !$this->database->public_port) {
|
|
|
|
$this->emit('error', 'Public port is required.');
|
|
|
|
$this->database->is_public = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($this->database->is_public) {
|
|
|
|
if (!str($this->database->status)->startsWith('running')) {
|
|
|
|
$this->emit('error', 'Database must be started to be publicly accessible.');
|
|
|
|
$this->database->is_public = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StartDatabaseProxy::run($this->database);
|
|
|
|
$this->db_url_public = $this->database->getServiceDatabaseUrl();
|
|
|
|
$this->emit('success', 'Database is now publicly accessible.');
|
|
|
|
} else {
|
|
|
|
StopDatabaseProxy::run($this->database);
|
|
|
|
$this->db_url_public = null;
|
|
|
|
$this->emit('success', 'Database is no longer publicly accessible.');
|
|
|
|
}
|
2023-09-25 13:48:43 +00:00
|
|
|
$this->submit();
|
|
|
|
}
|
2023-09-26 12:45:52 +00:00
|
|
|
public function refreshFileStorages()
|
|
|
|
{
|
|
|
|
$this->fileStorages = $this->database->fileStorages()->get();
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->validate();
|
|
|
|
$this->database->save();
|
2023-09-27 10:45:53 +00:00
|
|
|
updateCompose($this->database);
|
2023-09-25 13:48:43 +00:00
|
|
|
$this->emit('success', 'Database saved successfully.');
|
2023-09-22 09:23:49 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
ray($e);
|
|
|
|
} finally {
|
|
|
|
$this->emit('generateDockerCompose');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|