refactor(livewire): make data-sync helpers private (#11578)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-09-01 18:44:18 +02:00
committed by GitHub
co-authored by Claude Fable 5
parent 2018e7f329
commit 7c3b05e2d2
42 changed files with 525 additions and 80 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ class Show extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+5 -2
View File
@@ -85,11 +85,10 @@ class Discord extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->settings);
$this->settings->discord_enabled = $this->discordEnabled;
$this->settings->discord_webhook_url = $this->discordWebhookUrl;
@@ -174,6 +173,7 @@ class Discord extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->settings);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -184,6 +184,7 @@ class Discord extends Component
{
try {
$this->resetErrorBag();
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
@@ -193,6 +194,8 @@ class Discord extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
refreshSession();
$this->dispatch('success', 'Settings saved.');
+3 -2
View File
@@ -132,12 +132,11 @@ class Email extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->validate(['smtpEhloDomain' => ['nullable', 'string', new ValidHostname]]);
$this->authorize('update', $this->settings);
$this->settings->smtp_enabled = $this->smtpEnabled;
$this->settings->smtp_from_address = $this->smtpFromAddress;
$this->settings->smtp_from_name = $this->smtpFromName;
@@ -224,6 +223,8 @@ class Email extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->dispatch('success', 'Email notifications settings updated.');
}
+5 -2
View File
@@ -89,11 +89,10 @@ class Pushover extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->settings);
$this->settings->pushover_enabled = $this->pushoverEnabled;
$this->settings->pushover_user_key = $this->pushoverUserKey;
$this->settings->pushover_api_token = $this->pushoverApiToken;
@@ -167,6 +166,7 @@ class Pushover extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->settings);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -179,6 +179,7 @@ class Pushover extends Component
{
try {
$this->resetErrorBag();
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
@@ -188,6 +189,8 @@ class Pushover extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
refreshSession();
$this->dispatch('success', 'Settings saved.');
+5 -2
View File
@@ -87,11 +87,10 @@ class Slack extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->settings);
$this->settings->slack_enabled = $this->slackEnabled;
$this->settings->slack_webhook_url = $this->slackWebhookUrl;
@@ -158,6 +157,7 @@ class Slack extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->settings);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -170,6 +170,7 @@ class Slack extends Component
{
try {
$this->resetErrorBag();
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
@@ -179,6 +180,8 @@ class Slack extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
refreshSession();
$this->dispatch('success', 'Settings saved.');
+5 -2
View File
@@ -134,11 +134,10 @@ class Telegram extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->settings);
$this->settings->telegram_enabled = $this->telegramEnabled;
$this->settings->telegram_token = $this->telegramToken;
$this->settings->telegram_chat_id = $this->telegramChatId;
@@ -223,6 +222,7 @@ class Telegram extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->settings);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -235,6 +235,7 @@ class Telegram extends Component
{
try {
$this->resetErrorBag();
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
@@ -264,6 +265,8 @@ class Telegram extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
refreshSession();
$this->dispatch('success', 'Settings saved.');
+5 -2
View File
@@ -82,11 +82,10 @@ class Webhook extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->settings);
$this->settings->webhook_enabled = $this->webhookEnabled;
$this->settings->webhook_url = $this->webhookUrl;
@@ -152,6 +151,7 @@ class Webhook extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->settings);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -162,6 +162,7 @@ class Webhook extends Component
{
try {
$this->resetErrorBag();
$this->authorize('update', $this->settings);
$this->syncData(true);
$this->saveModel();
} catch (\Throwable $e) {
@@ -171,6 +172,8 @@ class Webhook extends Component
public function saveModel()
{
$this->authorize('update', $this->settings);
$this->syncData(true);
refreshSession();
@@ -99,7 +99,7 @@ class Advanced extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -330,7 +330,7 @@ class General extends Component
$this->syncData();
}
public function syncData(bool $toModel = false): void
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -65,7 +65,7 @@ class Source extends Component
$this->gitCommitSha = trim($this->gitCommitSha);
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -31,7 +31,7 @@ class Swarm extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -128,7 +128,7 @@ class BackupEdit extends Component
$this->status = $database->status;
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->backup->enabled = $this->backupEnabled;
@@ -121,7 +121,7 @@ class General extends Component
);
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -199,6 +199,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -115,7 +115,7 @@ class General extends Component
);
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -191,6 +191,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
+1 -1
View File
@@ -34,7 +34,7 @@ class Health extends Component
$this->syncData();
}
public function syncData(bool $toModel = false): void
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -118,7 +118,7 @@ class General extends Component
);
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -196,6 +196,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -136,7 +136,7 @@ class General extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -244,6 +244,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -128,7 +128,7 @@ class General extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -237,6 +237,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -136,7 +136,7 @@ class General extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -244,6 +244,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -149,7 +149,7 @@ class General extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -240,6 +240,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
@@ -127,7 +127,7 @@ class General extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -235,6 +235,7 @@ class General extends Component
}
$this->dispatch('databaseUpdated');
} catch (\Throwable $e) {
$this->authorize('update', $this->database);
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
+1 -1
View File
@@ -77,7 +77,7 @@ class Edit extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -48,7 +48,7 @@ class EnvironmentEdit extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -46,7 +46,7 @@ class EditDomain extends Component
$this->syncData();
}
public function syncData(bool $toModel = false): void
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+1 -1
View File
@@ -120,7 +120,7 @@ class FileStorage extends Component
: route('project.application.backup.show', [...$parameters, 'backup_uuid' => $backup->uuid]);
}
public function syncData(bool $toModel = false): void
private function syncData(bool $toModel = false): void
{
if ($toModel) {
if ($this->fileStorage->is_too_large) {
@@ -162,7 +162,7 @@ class Show extends Component
$this->valuesLoaded = true;
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->key = ValidationPatterns::normalizeEnvironmentVariableKey($this->key);
+1 -1
View File
@@ -86,7 +86,7 @@ class HealthChecks extends Component
}
}
public function syncData(bool $toModel = false): void
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
@@ -102,7 +102,7 @@ class Add extends Component
}
}
public function saveScheduledTask()
private function saveScheduledTask(): mixed
{
try {
$task = new ScheduledTask;
@@ -87,7 +87,7 @@ class Show extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
+3 -2
View File
@@ -42,10 +42,9 @@ class Advanced extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->authorize('update', $this->server);
$this->validate();
$this->server->settings->concurrent_builds = $this->concurrentBuilds;
$this->server->settings->dynamic_timeout = $this->dynamicTimeout;
@@ -67,6 +66,7 @@ class Advanced extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
@@ -81,6 +81,7 @@ class Advanced extends Component
$this->serverDiskUsageCheckFrequency = $this->server->settings->getOriginal('server_disk_usage_check_frequency');
throw new \Exception('Invalid Cron / Human expression for Disk Usage Check Frequency.');
}
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
+3 -2
View File
@@ -97,10 +97,9 @@ class DockerCleanup extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->authorize('update', $this->server);
$this->validate();
$this->server->settings->force_docker_cleanup = $this->forceDockerCleanup;
$this->server->settings->docker_cleanup_frequency = $this->dockerCleanupFrequency;
@@ -122,6 +121,7 @@ class DockerCleanup extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
@@ -147,6 +147,7 @@ class DockerCleanup extends Component
$this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency');
throw new \Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.');
}
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
+4 -4
View File
@@ -52,7 +52,7 @@ class LogDrains extends Component
}
}
public function syncDataNewRelic(bool $toModel = false)
private function syncDataNewRelic(bool $toModel = false): void
{
if ($toModel) {
$this->server->settings->is_logdrain_newrelic_enabled = $this->isLogDrainNewRelicEnabled;
@@ -65,7 +65,7 @@ class LogDrains extends Component
}
}
public function syncDataAxiom(bool $toModel = false)
private function syncDataAxiom(bool $toModel = false): void
{
if ($toModel) {
$this->server->settings->is_logdrain_axiom_enabled = $this->isLogDrainAxiomEnabled;
@@ -78,7 +78,7 @@ class LogDrains extends Component
}
}
public function syncDataCustom(bool $toModel = false)
private function syncDataCustom(bool $toModel = false): void
{
if ($toModel) {
$this->server->settings->is_logdrain_custom_enabled = $this->isLogDrainCustomEnabled;
@@ -91,7 +91,7 @@ class LogDrains extends Component
}
}
public function syncData(bool $toModel = false, ?string $type = null)
private function syncData(bool $toModel = false, ?string $type = null): void
{
if ($toModel) {
$this->customValidation();
@@ -62,10 +62,9 @@ class TerminalAccess extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->authorize('update', $this->server);
$this->validate();
// No other fields to sync for terminal access
} else {
+3 -2
View File
@@ -54,10 +54,9 @@ class Sentinel extends Component
$this->syncData();
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->authorize('update', $this->server);
$this->validate();
$this->server->settings->is_metrics_enabled = $this->isMetricsEnabled;
$this->server->settings->sentinel_token = $this->sentinelToken;
@@ -145,6 +144,7 @@ class Sentinel extends Component
public function submit()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Sentinel settings updated. Restarting Sentinel.');
} catch (\Throwable $e) {
@@ -155,6 +155,7 @@ class Sentinel extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->restartSentinel();
} catch (\Throwable $e) {
+4 -3
View File
@@ -230,12 +230,10 @@ class Show extends Component
->toArray();
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();
$this->authorize('update', $this->server);
$foundServer = Server::where('ip', $this->ip)
->where('id', '!=', $this->server->id)
->first();
@@ -363,6 +361,7 @@ class Show extends Component
public function checkLocalhostConnection()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
['uptime' => $uptime, 'error' => $error] = $this->server->validateConnection();
if ($uptime) {
@@ -479,6 +478,7 @@ class Show extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -694,6 +694,7 @@ class Show extends Component
public function submit()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Server settings updated.');
} catch (\Throwable $e) {
+2 -2
View File
@@ -29,10 +29,9 @@ class Swarm extends Component
}
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->authorize('update', $this->server);
$this->server->settings->is_swarm_manager = $this->isSwarmManager;
$this->server->settings->is_swarm_worker = $this->isSwarmWorker;
$this->server->settings->save();
@@ -45,6 +44,7 @@ class Swarm extends Component
public function instantSave()
{
try {
$this->authorize('update', $this->server);
$this->syncData(true);
$this->dispatch('success', 'Swarm settings updated.');
} catch (\Throwable $e) {
+1 -1
View File
@@ -74,7 +74,7 @@ class SettingsEmail extends Component
$this->testEmailAddress = auth()->user()->email;
}
public function syncData(bool $toModel = false)
private function syncData(bool $toModel = false): void
{
if ($toModel) {
$this->validate();