2023-04-28 15:08:48 +02:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire;
|
2023-04-28 15:08:48 +02:00
|
|
|
|
2023-06-15 11:23:48 +02:00
|
|
|
use App\Actions\Server\UpdateCoolify;
|
2024-08-07 11:42:55 +02:00
|
|
|
use App\Models\InstanceSettings;
|
2024-08-07 12:16:06 +02:00
|
|
|
use Illuminate\Support\Facades\Http;
|
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;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2024-05-17 09:52:19 +02:00
|
|
|
public bool $updateInProgress = false;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-06-15 11:39:15 +02:00
|
|
|
public bool $isUpgradeAvailable = false;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-06-16 12:35:40 +02:00
|
|
|
public string $latestVersion = '';
|
2023-06-15 11:39:15 +02:00
|
|
|
|
2024-08-07 11:42:55 +02:00
|
|
|
protected $listeners = ['updateAvailable' => 'checkUpdate'];
|
|
|
|
|
2023-06-15 11:39:15 +02:00
|
|
|
public function checkUpdate()
|
|
|
|
{
|
2024-08-07 11:42:55 +02:00
|
|
|
try {
|
|
|
|
$settings = InstanceSettings::get();
|
2024-08-07 12:16:06 +02:00
|
|
|
$response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');
|
|
|
|
if ($response->successful()) {
|
|
|
|
$versions = $response->json();
|
|
|
|
$this->latestVersion = data_get($versions, 'coolify.v4.version');
|
|
|
|
}
|
2024-08-07 11:42:55 +02:00
|
|
|
$this->isUpgradeAvailable = $settings->new_version_available;
|
2024-08-07 12:10:31 +02:00
|
|
|
|
2024-08-07 11:42:55 +02:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
2024-05-17 10:12:17 +02:00
|
|
|
}
|
2024-08-07 11:42:55 +02:00
|
|
|
|
2023-06-15 11:39:15 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-04-28 15:08:48 +02:00
|
|
|
public function upgrade()
|
|
|
|
{
|
2023-05-25 22:33:47 +02:00
|
|
|
try {
|
2024-05-17 09:52:19 +02:00
|
|
|
if ($this->updateInProgress) {
|
2023-06-16 21:16:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-05-17 09:52:19 +02:00
|
|
|
$this->updateInProgress = true;
|
2024-05-30 19:38:33 +02:00
|
|
|
UpdateCoolify::run(manual_update: true);
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 15:34:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-05-25 22:33:47 +02:00
|
|
|
}
|
2023-04-28 15:08:48 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|