diff --git a/app/Console/Commands/PingVersionServer.php b/app/Console/Commands/PingVersionServer.php index cc770755c..8944854d1 100644 --- a/app/Console/Commands/PingVersionServer.php +++ b/app/Console/Commands/PingVersionServer.php @@ -43,7 +43,7 @@ class PingVersionServer extends Command } if (! $this->confirmToProceed('Checking version deactivated', function () { - return $this->getLaravel()->environment() == 'production'; + return $this->getLaravel()->environment() === 'production'; })) { return false; } @@ -51,6 +51,12 @@ class PingVersionServer extends Command $instance = Instance::first(); $instance->current_version = config('monica.app_version'); + if ($instance->current_version == '') { + Log::warning('Current instance version is not set, skipping version check.'); + + return; + } + // Query version.monicahq.com try { $this->log('Call url: '.config('monica.weekly_ping_server_url')); @@ -72,10 +78,10 @@ class PingVersionServer extends Command $json = $response->json(); $this->log('instance version: '.$instance->current_version); - $this->log('current version: '.$json['latest_version']); + $currentVersion = $this->getVersion($instance->current_version); - $latestVersion = new Version($json['latest_version']); - $currentVersion = new Version($instance->current_version); + $this->log('current version: '.$json['latest_version']); + $latestVersion = $this->getVersion($json['latest_version']); if ($latestVersion > $currentVersion) { $instance->latest_version = $json['latest_version']; @@ -93,4 +99,15 @@ class PingVersionServer extends Command { $this->info($string, OutputInterface::VERBOSITY_VERBOSE); } + + private function getVersion(string $version): ?Version + { + try { + return new Version($version); + } catch (\Exception $e) { + $this->error("Error parsing version '$version': ".$e->getMessage()); + } + + return null; + } }