fix: skip version check if current version is empty (#6137)

This commit is contained in:
Alexis Saettler
2022-05-11 09:15:51 +02:00
committed by GitHub
parent 06bdc28800
commit 4e1e4ee1e9
+21 -4
View File
@@ -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;
}
}