coolify/app/Http/Livewire/Upgrade.php

43 lines
1.3 KiB
PHP
Raw Normal View History

2023-04-28 15:08:48 +02:00
<?php
namespace App\Http\Livewire;
2023-06-15 11:23:48 +02:00
use App\Actions\Server\UpdateCoolify;
2023-06-23 13:22:29 +02:00
use App\Models\InstanceSettings;
2023-06-15 10:48:13 +02:00
use Masmerise\Toaster\Toaster;
2023-04-28 15:08:48 +02:00
use Livewire\Component;
2023-06-15 10:48:13 +02:00
class Upgrade extends Component
2023-04-28 15:08:48 +02:00
{
2023-06-15 10:48:13 +02:00
public bool $showProgress = false;
2023-06-15 11:39:15 +02:00
public bool $isUpgradeAvailable = false;
2023-06-16 12:35:40 +02:00
public string $latestVersion = '';
2023-06-15 11:39:15 +02:00
public function checkUpdate()
{
2023-06-16 12:35:40 +02:00
$this->latestVersion = get_latest_version_of_coolify();
2023-06-15 11:39:15 +02:00
$currentVersion = config('version');
2023-06-16 12:35:40 +02:00
version_compare($currentVersion, $this->latestVersion, '<') ? $this->isUpgradeAvailable = true : $this->isUpgradeAvailable = false;
2023-06-16 11:01:27 +02:00
if (isDev()) {
2023-06-15 11:39:15 +02:00
$this->isUpgradeAvailable = true;
}
2023-06-23 13:22:29 +02:00
$settings = InstanceSettings::get();
if ($settings->next_channel) {
$this->isUpgradeAvailable = true;
2023-06-23 13:26:58 +02:00
$this->latestVersion = 'next';
2023-06-23 13:22:29 +02:00
}
2023-06-15 11:39:15 +02:00
}
2023-04-28 15:08:48 +02:00
public function upgrade()
{
2023-05-25 22:33:47 +02:00
try {
2023-06-16 21:16:30 +02:00
if ($this->showProgress) {
return;
}
2023-06-15 10:48:13 +02:00
$this->showProgress = true;
2023-06-15 11:23:48 +02:00
resolve(UpdateCoolify::class)(true);
2023-06-16 15:06:37 +02:00
Toaster::success("Upgrading to {$this->latestVersion} version...");
2023-05-25 22:33:47 +02:00
} catch (\Exception $e) {
2023-06-09 15:55:21 +02:00
return general_error_handler(err: $e, that: $this);
2023-05-25 22:33:47 +02:00
}
2023-04-28 15:08:48 +02:00
}
2023-07-05 21:26:21 +02:00
}