refactor(init): standardize method naming conventions and improve command structure in Init.php

This commit is contained in:
Andras Bacsai
2025-07-07 09:50:15 +02:00
parent 7817c9cad7
commit 3b7f4bcbbd

View File

@@ -36,24 +36,20 @@ class Init extends Command
$this->servers = Server::all(); $this->servers = Server::all();
if (! isCloud()) { if (! isCloud()) {
$this->send_alive_signal(); $this->sendAliveSignal();
get_public_ips(); get_public_ips();
} }
// Backward compatibility // Backward compatibility
$this->replace_slash_in_environment_name(); $this->replaceSlashInEnvironmentName();
$this->restore_coolify_db_backup(); $this->restoreCoolifyDbBackup();
$this->update_user_emails(); $this->updateUserEmails();
// //
$this->update_traefik_labels(); $this->updateTraefikLabels();
if (! isCloud() || $this->option('force-cloud')) { if (! isCloud() || $this->option('force-cloud')) {
$this->cleanup_unused_network_from_coolify_proxy(); $this->cleanupUnusedNetworkFromCoolifyProxy();
}
if (isCloud()) {
$this->cleanup_unnecessary_dynamic_proxy_configuration();
} else {
$this->cleanup_in_progress_application_deployments();
} }
$this->call('cleanup:redis'); $this->call('cleanup:redis');
$this->call('cleanup:stucked-resources'); $this->call('cleanup:stucked-resources');
@@ -66,33 +62,35 @@ class Init extends Command
if (isCloud()) { if (isCloud()) {
try { try {
$this->cleanupUnnecessaryDynamicProxyConfiguration();
$this->pullTemplatesFromCDN(); $this->pullTemplatesFromCDN();
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n"; echo "Could not pull templates from CDN: {$e->getMessage()}\n";
} }
return;
} }
if (! isCloud()) { try {
try { $this->cleanupInProgressApplicationDeployments();
$this->pullTemplatesFromCDN(); $this->pullTemplatesFromCDN();
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n"; echo "Could not pull templates from CDN: {$e->getMessage()}\n";
} }
try { try {
$localhost = $this->servers->where('id', 0)->first(); $localhost = $this->servers->where('id', 0)->first();
$localhost->setupDynamicProxyConfiguration(); $localhost->setupDynamicProxyConfiguration();
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n"; echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
} }
$settings = instanceSettings(); $settings = instanceSettings();
if (! is_null(config('constants.coolify.autoupdate', null))) { if (! is_null(config('constants.coolify.autoupdate', null))) {
if (config('constants.coolify.autoupdate') == true) { if (config('constants.coolify.autoupdate') == true) {
echo "Enabling auto-update\n"; echo "Enabling auto-update\n";
$settings->update(['is_auto_update_enabled' => true]); $settings->update(['is_auto_update_enabled' => true]);
} else { } else {
echo "Disabling auto-update\n"; echo "Disabling auto-update\n";
$settings->update(['is_auto_update_enabled' => false]); $settings->update(['is_auto_update_enabled' => false]);
}
} }
} }
} }
@@ -117,7 +115,7 @@ class Init extends Command
Artisan::call('optimize'); Artisan::call('optimize');
} }
private function update_user_emails() private function updateUserEmails()
{ {
try { try {
User::whereRaw('email ~ \'[A-Z]\'')->get()->each(function (User $user) { 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 { try {
Server::where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']); 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) { foreach ($this->servers as $server) {
try { 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) { foreach ($this->servers as $server) {
if (! $server->isFunctional()) { 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'), '<=')) { if (version_compare('4.0.0-beta.179', config('constants.coolify.version'), '<=')) {
try { try {
@@ -223,7 +221,7 @@ class Init extends Command
} }
} }
private function send_alive_signal() private function sendAliveSignal()
{ {
$id = config('app.id'); $id = config('app.id');
$version = config('constants.coolify.version'); $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 // Cleanup any failed deployments
try { 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'), '<=')) { if (version_compare('4.0.0-beta.298', config('constants.coolify.version'), '<=')) {
$environments = Environment::all(); $environments = Environment::all();