Skip to content

Commit 4e1e4ee

Browse files
authored
fix: skip version check if current version is empty (#6137)
1 parent 06bdc28 commit 4e1e4ee

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

app/Console/Commands/PingVersionServer.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ public function handle()
4343
}
4444

4545
if (! $this->confirmToProceed('Checking version deactivated', function () {
46-
return $this->getLaravel()->environment() == 'production';
46+
return $this->getLaravel()->environment() === 'production';
4747
})) {
4848
return false;
4949
}
5050

5151
$instance = Instance::first();
5252
$instance->current_version = config('monica.app_version');
5353

54+
if ($instance->current_version == '') {
55+
Log::warning('Current instance version is not set, skipping version check.');
56+
57+
return;
58+
}
59+
5460
// Query version.monicahq.com
5561
try {
5662
$this->log('Call url: '.config('monica.weekly_ping_server_url'));
@@ -72,10 +78,10 @@ public function handle()
7278
$json = $response->json();
7379

7480
$this->log('instance version: '.$instance->current_version);
75-
$this->log('current version: '.$json['latest_version']);
81+
$currentVersion = $this->getVersion($instance->current_version);
7682

77-
$latestVersion = new Version($json['latest_version']);
78-
$currentVersion = new Version($instance->current_version);
83+
$this->log('current version: '.$json['latest_version']);
84+
$latestVersion = $this->getVersion($json['latest_version']);
7985

8086
if ($latestVersion > $currentVersion) {
8187
$instance->latest_version = $json['latest_version'];
@@ -93,4 +99,15 @@ public function log($string)
9399
{
94100
$this->info($string, OutputInterface::VERBOSITY_VERBOSE);
95101
}
102+
103+
private function getVersion(string $version): ?Version
104+
{
105+
try {
106+
return new Version($version);
107+
} catch (\Exception $e) {
108+
$this->error("Error parsing version '$version': ".$e->getMessage());
109+
}
110+
111+
return null;
112+
}
96113
}

0 commit comments

Comments
 (0)