2026-05-31 19:50:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Database;
|
|
|
|
|
|
2026-06-01 06:55:03 +00:00
|
|
|
use Illuminate\Contracts\View\View;
|
2026-05-31 19:50:10 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
|
use Livewire\Attributes\Validate;
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Health extends Component
|
|
|
|
|
{
|
|
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
|
|
|
|
public $database;
|
|
|
|
|
|
|
|
|
|
#[Validate(['boolean'])]
|
|
|
|
|
public bool $healthCheckEnabled = true;
|
|
|
|
|
|
|
|
|
|
#[Validate(['integer', 'min:1'])]
|
|
|
|
|
public int $healthCheckInterval = 15;
|
|
|
|
|
|
|
|
|
|
#[Validate(['integer', 'min:1'])]
|
|
|
|
|
public int $healthCheckTimeout = 5;
|
|
|
|
|
|
|
|
|
|
#[Validate(['integer', 'min:1'])]
|
|
|
|
|
public int $healthCheckRetries = 5;
|
|
|
|
|
|
|
|
|
|
#[Validate(['integer', 'min:0'])]
|
|
|
|
|
public int $healthCheckStartPeriod = 5;
|
|
|
|
|
|
2026-06-01 06:55:03 +00:00
|
|
|
public function mount(): void
|
2026-05-31 19:50:10 +00:00
|
|
|
{
|
|
|
|
|
$this->authorize('view', $this->database);
|
|
|
|
|
$this->syncData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function syncData(bool $toModel = false): void
|
|
|
|
|
{
|
|
|
|
|
if ($toModel) {
|
|
|
|
|
$this->validate();
|
|
|
|
|
$this->database->health_check_enabled = $this->healthCheckEnabled;
|
|
|
|
|
$this->database->health_check_interval = $this->healthCheckInterval;
|
|
|
|
|
$this->database->health_check_timeout = $this->healthCheckTimeout;
|
|
|
|
|
$this->database->health_check_retries = $this->healthCheckRetries;
|
|
|
|
|
$this->database->health_check_start_period = $this->healthCheckStartPeriod;
|
|
|
|
|
$this->database->save();
|
|
|
|
|
} else {
|
|
|
|
|
$this->healthCheckEnabled = $this->database->health_check_enabled;
|
|
|
|
|
$this->healthCheckInterval = $this->database->health_check_interval;
|
|
|
|
|
$this->healthCheckTimeout = $this->database->health_check_timeout;
|
|
|
|
|
$this->healthCheckRetries = $this->database->health_check_retries;
|
|
|
|
|
$this->healthCheckStartPeriod = $this->database->health_check_start_period;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 06:55:03 +00:00
|
|
|
public function instantSave(): void
|
2026-05-31 19:50:10 +00:00
|
|
|
{
|
|
|
|
|
$this->submit();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 06:55:03 +00:00
|
|
|
public function submit(): void
|
2026-05-31 19:50:10 +00:00
|
|
|
{
|
2026-06-01 06:55:03 +00:00
|
|
|
$updateSuccessful = false;
|
|
|
|
|
|
2026-05-31 19:50:10 +00:00
|
|
|
try {
|
|
|
|
|
$this->authorize('update', $this->database);
|
|
|
|
|
$this->syncData(true);
|
2026-06-01 06:55:03 +00:00
|
|
|
$updateSuccessful = true;
|
2026-05-31 19:50:10 +00:00
|
|
|
$this->dispatch('success', 'Health check updated. Restart the database to apply the changes.');
|
|
|
|
|
} catch (\Throwable $e) {
|
2026-06-01 06:55:03 +00:00
|
|
|
handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $updateSuccessful) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->markConfigurationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toggleHealthcheck(): void
|
|
|
|
|
{
|
|
|
|
|
$updateSuccessful = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->authorize('update', $this->database);
|
|
|
|
|
$this->healthCheckEnabled = ! $this->healthCheckEnabled;
|
|
|
|
|
$this->syncData(true);
|
|
|
|
|
$updateSuccessful = true;
|
|
|
|
|
$this->dispatch('success', 'Health check '.($this->healthCheckEnabled ? 'enabled' : 'disabled').'. Restart the database to apply the changes.');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $updateSuccessful) {
|
|
|
|
|
return;
|
2026-05-31 19:50:10 +00:00
|
|
|
}
|
2026-06-01 06:55:03 +00:00
|
|
|
|
|
|
|
|
$this->markConfigurationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function markConfigurationChanged(): void
|
|
|
|
|
{
|
|
|
|
|
if (is_null($this->database->config_hash)) {
|
|
|
|
|
$this->database->isConfigurationChanged(true);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->dispatch('configurationChanged');
|
2026-05-31 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-01 06:55:03 +00:00
|
|
|
public function render(): View
|
2026-05-31 19:50:10 +00:00
|
|
|
{
|
|
|
|
|
return view('livewire.project.database.health');
|
|
|
|
|
}
|
|
|
|
|
}
|