lasthourcloud/app/Livewire/Upgrade.php

47 lines
1.3 KiB
PHP
Raw Normal View History

2023-04-28 13:08:48 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire;
2023-04-28 13:08:48 +00:00
2023-06-15 09:23:48 +00:00
use App\Actions\Server\UpdateCoolify;
2023-06-23 11:22:29 +00:00
use App\Models\InstanceSettings;
2023-04-28 13:08:48 +00:00
use Livewire\Component;
2023-10-09 12:20:55 +00:00
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
2023-04-28 13:08:48 +00:00
2023-06-15 08:48:13 +00:00
class Upgrade extends Component
2023-04-28 13:08:48 +00:00
{
2023-10-09 12:20:55 +00:00
use WithRateLimiting;
2023-06-15 08:48:13 +00:00
public bool $showProgress = false;
2023-06-15 09:39:15 +00:00
public bool $isUpgradeAvailable = false;
2023-06-16 10:35:40 +00:00
public string $latestVersion = '';
2023-06-15 09:39:15 +00:00
public function checkUpdate()
{
2023-06-16 10:35:40 +00:00
$this->latestVersion = get_latest_version_of_coolify();
2023-06-15 09:39:15 +00:00
$currentVersion = config('version');
2023-06-16 10:35:40 +00:00
version_compare($currentVersion, $this->latestVersion, '<') ? $this->isUpgradeAvailable = true : $this->isUpgradeAvailable = false;
if (isDev()) {
2023-06-15 09:39:15 +00:00
$this->isUpgradeAvailable = true;
}
2023-06-23 11:22:29 +00:00
$settings = InstanceSettings::get();
if ($settings->next_channel) {
$this->isUpgradeAvailable = true;
2023-06-23 11:26:58 +00:00
$this->latestVersion = 'next';
2023-06-23 11:22:29 +00:00
}
2023-06-15 09:39:15 +00:00
}
2023-04-28 13:08:48 +00:00
public function upgrade()
{
2023-05-25 20:33:47 +00:00
try {
2023-06-16 19:16:30 +00:00
if ($this->showProgress) {
return;
}
2024-04-08 07:36:24 +00:00
$this->rateLimit(1, 30);
2023-06-15 08:48:13 +00:00
$this->showProgress = true;
2024-03-27 10:35:57 +00:00
UpdateCoolify::run(force: true, async: true);
$this->dispatch('success', "Updating Coolify to {$this->latestVersion} version...");
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-25 20:33:47 +00:00
}
2023-04-28 13:08:48 +00:00
}
}