Skip to content

Commit

Permalink
fix: skip version check if current version is empty (#6137)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored May 11, 2022
1 parent 06bdc28 commit 4e1e4ee
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/Console/Commands/PingVersionServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ public function handle()
}

if (! $this->confirmToProceed('Checking version deactivated', function () {
return $this->getLaravel()->environment() == 'production';
return $this->getLaravel()->environment() === 'production';
})) {
return false;
}

$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'));
Expand All @@ -72,10 +78,10 @@ public function handle()
$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'];
Expand All @@ -93,4 +99,15 @@ public function log($string)
{
$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;
}
}

0 comments on commit 4e1e4ee

Please sign in to comment.