From 3b7f4bcbbd21f11e39a3d985c01214d41caed81c Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 7 Jul 2025 09:50:15 +0200 Subject: [PATCH] refactor(init): standardize method naming conventions and improve command structure in Init.php --- app/Console/Commands/Init.php | 78 +++++++++++++++++------------------ 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index a954b10fd..1a7c0911f 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -36,24 +36,20 @@ class Init extends Command $this->servers = Server::all(); if (! isCloud()) { - $this->send_alive_signal(); + $this->sendAliveSignal(); get_public_ips(); } // Backward compatibility - $this->replace_slash_in_environment_name(); - $this->restore_coolify_db_backup(); - $this->update_user_emails(); + $this->replaceSlashInEnvironmentName(); + $this->restoreCoolifyDbBackup(); + $this->updateUserEmails(); // - $this->update_traefik_labels(); + $this->updateTraefikLabels(); if (! isCloud() || $this->option('force-cloud')) { - $this->cleanup_unused_network_from_coolify_proxy(); - } - if (isCloud()) { - $this->cleanup_unnecessary_dynamic_proxy_configuration(); - } else { - $this->cleanup_in_progress_application_deployments(); + $this->cleanupUnusedNetworkFromCoolifyProxy(); } + $this->call('cleanup:redis'); $this->call('cleanup:stucked-resources'); @@ -66,33 +62,35 @@ class Init extends Command if (isCloud()) { try { + $this->cleanupUnnecessaryDynamicProxyConfiguration(); $this->pullTemplatesFromCDN(); } catch (\Throwable $e) { echo "Could not pull templates from CDN: {$e->getMessage()}\n"; } + + return; } - if (! isCloud()) { - try { - $this->pullTemplatesFromCDN(); - } catch (\Throwable $e) { - echo "Could not pull templates from CDN: {$e->getMessage()}\n"; - } - try { - $localhost = $this->servers->where('id', 0)->first(); - $localhost->setupDynamicProxyConfiguration(); - } catch (\Throwable $e) { - echo "Could not setup dynamic configuration: {$e->getMessage()}\n"; - } - $settings = instanceSettings(); - if (! is_null(config('constants.coolify.autoupdate', null))) { - if (config('constants.coolify.autoupdate') == true) { - echo "Enabling auto-update\n"; - $settings->update(['is_auto_update_enabled' => true]); - } else { - echo "Disabling auto-update\n"; - $settings->update(['is_auto_update_enabled' => false]); - } + try { + $this->cleanupInProgressApplicationDeployments(); + $this->pullTemplatesFromCDN(); + } catch (\Throwable $e) { + echo "Could not pull templates from CDN: {$e->getMessage()}\n"; + } + try { + $localhost = $this->servers->where('id', 0)->first(); + $localhost->setupDynamicProxyConfiguration(); + } catch (\Throwable $e) { + echo "Could not setup dynamic configuration: {$e->getMessage()}\n"; + } + $settings = instanceSettings(); + if (! is_null(config('constants.coolify.autoupdate', null))) { + if (config('constants.coolify.autoupdate') == true) { + echo "Enabling auto-update\n"; + $settings->update(['is_auto_update_enabled' => true]); + } else { + echo "Disabling auto-update\n"; + $settings->update(['is_auto_update_enabled' => false]); } } } @@ -117,7 +115,7 @@ class Init extends Command Artisan::call('optimize'); } - private function update_user_emails() + private function updateUserEmails() { try { User::whereRaw('email ~ \'[A-Z]\'')->get()->each(function (User $user) { @@ -128,7 +126,7 @@ class Init extends Command } } - private function update_traefik_labels() + private function updateTraefikLabels() { try { Server::where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']); @@ -137,7 +135,7 @@ class Init extends Command } } - private function cleanup_unnecessary_dynamic_proxy_configuration() + private function cleanupUnnecessaryDynamicProxyConfiguration() { foreach ($this->servers as $server) { try { @@ -158,7 +156,7 @@ class Init extends Command } } - private function cleanup_unused_network_from_coolify_proxy() + private function cleanupUnusedNetworkFromCoolifyProxy() { foreach ($this->servers as $server) { if (! $server->isFunctional()) { @@ -197,7 +195,7 @@ class Init extends Command } } - private function restore_coolify_db_backup() + private function restoreCoolifyDbBackup() { if (version_compare('4.0.0-beta.179', config('constants.coolify.version'), '<=')) { try { @@ -223,7 +221,7 @@ class Init extends Command } } - private function send_alive_signal() + private function sendAliveSignal() { $id = config('app.id'); $version = config('constants.coolify.version'); @@ -241,7 +239,7 @@ class Init extends Command } } - private function cleanup_in_progress_application_deployments() + private function cleanupInProgressApplicationDeployments() { // Cleanup any failed deployments try { @@ -258,7 +256,7 @@ class Init extends Command } } - private function replace_slash_in_environment_name() + private function replaceSlashInEnvironmentName() { if (version_compare('4.0.0-beta.298', config('constants.coolify.version'), '<=')) { $environments = Environment::all();