An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(upgrade): clear stale upgrade flag when version is already current
Andras Bacsaidbd2b68a08f2
diff --git a/app/Livewire/Upgrade.php b/app/Livewire/Upgrade.phpindex 25cedc71b0..1b8701d94a 100644--- a/app/Livewire/Upgrade.php+++ b/app/Livewire/Upgrade.php@@ -23,25 +23,42 @@ class Upgrade extends Componentpublic function mount(){- $this->currentVersion = config('constants.coolify.version');- $this->latestVersion = get_latest_version_of_coolify();- $this->devMode = isDev();+ $this->refreshUpgradeState();}public function checkUpdate(){try {- $this->latestVersion = get_latest_version_of_coolify();- $this->currentVersion = config('constants.coolify.version');- $this->isUpgradeAvailable = data_get(InstanceSettings::get(), 'new_version_available', false);- if (isDev()) {- $this->isUpgradeAvailable = true;- }+ $this->refreshUpgradeState();} catch (\Throwable $e) {return handleError($e, $this);}}+ protected function refreshUpgradeState(): void+ {+ $this->currentVersion = config('constants.coolify.version');+ $this->latestVersion = get_latest_version_of_coolify();+ $this->devMode = isDev();++ if ($this->devMode) {+ $this->isUpgradeAvailable = true;++ return;+ }++ $settings = InstanceSettings::find(0);+ $hasNewerVersion = version_compare($this->latestVersion, $this->currentVersion, '>');+ $newVersionAvailable = (bool) data_get($settings, 'new_version_available', false);++ if ($settings && $newVersionAvailable && ! $hasNewerVersion) {+ $settings->update(['new_version_available' => false]);+ $newVersionAvailable = false;+ }++ $this->isUpgradeAvailable = $hasNewerVersion && $newVersionAvailable;+ }+public function upgrade(){try {diff --git a/tests/Feature/UpgradeComponentTest.php b/tests/Feature/UpgradeComponentTest.phpindex 612e989ae3..896e0fa3bb 100644--- a/tests/Feature/UpgradeComponentTest.php+++ b/tests/Feature/UpgradeComponentTest.php@@ -1,11 +1,19 @@<?phpuse App\Livewire\Upgrade;+use App\Models\InstanceSettings;+use Illuminate\Foundation\Testing\RefreshDatabase;use Illuminate\Support\Facades\Cache;use Livewire\Livewire;+uses(RefreshDatabase::class);+it('initializes latest version during mount from cached versions data', function () {config(['constants.coolify.version' => '4.0.0-beta.998']);+ InstanceSettings::create([+ 'id' => 0,+ 'new_version_available' => true,+ ]);Cache::shouldReceive('remember')->once()@@ -21,12 +29,17 @@ it('initializes latest version during mount from cached versions data', functionLivewire::test(Upgrade::class)->assertSet('currentVersion', '4.0.0-beta.998')->assertSet('latestVersion', '4.0.0-beta.999')- ->set('isUpgradeAvailable', true)+ ->assertSet('isUpgradeAvailable', true)->assertSee('4.0.0-beta.998')->assertSee('4.0.0-beta.999');});it('falls back to 0.0.0 during mount when cached versions data is unavailable', function () {+ InstanceSettings::create([+ 'id' => 0,+ 'new_version_available' => false,+ ]);+Cache::shouldReceive('remember')->once()->with('coolify:versions:all', 3600, Mockery::type(\Closure::class))@@ -35,3 +48,53 @@ it('falls back to 0.0.0 during mount when cached versions data is unavailable',Livewire::test(Upgrade::class)->assertSet('latestVersion', '0.0.0');});++it('clears stale upgrade availability when current version already matches latest version', function () {+ config(['constants.coolify.version' => '4.0.0-beta.999']);+ InstanceSettings::create([+ 'id' => 0,+ 'new_version_available' => true,+ ]);++ Cache::shouldReceive('remember')+ ->once()+ ->with('coolify:versions:all', 3600, Mockery::type(\Closure::class))+ ->andReturn([+ 'coolify' => [+ 'v4' => [+ 'version' => '4.0.0-beta.999',+ ],+ ],+ ]);++ Livewire::test(Upgrade::class)+ ->assertSet('latestVersion', '4.0.0-beta.999')+ ->assertSet('isUpgradeAvailable', false);++ expect(InstanceSettings::findOrFail(0)->new_version_available)->toBeFalse();+});++it('clears stale upgrade availability when current version is newer than cached latest version', function () {+ config(['constants.coolify.version' => '4.0.0-beta.1000']);+ InstanceSettings::create([+ 'id' => 0,+ 'new_version_available' => true,+ ]);++ Cache::shouldReceive('remember')+ ->once()+ ->with('coolify:versions:all', 3600, Mockery::type(\Closure::class))+ ->andReturn([+ 'coolify' => [+ 'v4' => [+ 'version' => '4.0.0-beta.999',+ ],+ ],+ ]);++ Livewire::test(Upgrade::class)+ ->assertSet('latestVersion', '4.0.0-beta.999')+ ->assertSet('isUpgradeAvailable', false);++ expect(InstanceSettings::findOrFail(0)->new_version_available)->toBeFalse();+});