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;
|
2024-08-07 09:42:55 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2025-12-12 16:26:08 +00:00
|
|
|
use App\Services\ChangelogService;
|
2023-04-28 13:08:48 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
2023-06-15 08:48:13 +00:00
|
|
|
class Upgrade extends Component
|
2023-04-28 13:08:48 +00:00
|
|
|
{
|
2024-05-17 07:52:19 +00:00
|
|
|
public bool $updateInProgress = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-15 09:39:15 +00:00
|
|
|
public bool $isUpgradeAvailable = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-16 10:35:40 +00:00
|
|
|
public string $latestVersion = '';
|
2023-06-15 09:39:15 +00:00
|
|
|
|
2025-12-12 16:26:08 +00:00
|
|
|
public string $currentVersion = '';
|
|
|
|
|
|
|
|
|
|
public array $changelogEntries = [];
|
|
|
|
|
|
2024-08-07 09:42:55 +00:00
|
|
|
protected $listeners = ['updateAvailable' => 'checkUpdate'];
|
|
|
|
|
|
2025-12-12 16:26:08 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
|
|
|
|
$this->currentVersion = config('constants.coolify.version');
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 09:39:15 +00:00
|
|
|
public function checkUpdate()
|
|
|
|
|
{
|
2024-08-07 09:42:55 +00:00
|
|
|
try {
|
2024-09-05 08:15:22 +00:00
|
|
|
$this->latestVersion = get_latest_version_of_coolify();
|
2025-12-12 16:26:08 +00:00
|
|
|
$this->currentVersion = config('constants.coolify.version');
|
2024-09-05 08:15:22 +00:00
|
|
|
$this->isUpgradeAvailable = data_get(InstanceSettings::get(), 'new_version_available', false);
|
2024-11-10 20:26:52 +00:00
|
|
|
if (isDev()) {
|
|
|
|
|
$this->isUpgradeAvailable = true;
|
|
|
|
|
}
|
2025-12-12 16:26:08 +00:00
|
|
|
$this->loadChangelog();
|
2024-08-07 09:42:55 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
2024-05-17 08:12:17 +00:00
|
|
|
}
|
2023-06-15 09:39:15 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-12-12 16:26:08 +00:00
|
|
|
public function loadChangelog()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$service = app(ChangelogService::class);
|
|
|
|
|
$currentVersion = str_replace('v', '', $this->currentVersion);
|
|
|
|
|
|
|
|
|
|
$this->changelogEntries = $service->getEntries(1)
|
|
|
|
|
->filter(function ($entry) use ($currentVersion) {
|
|
|
|
|
$entryVersion = str_replace('v', '', $entry->tag_name);
|
|
|
|
|
|
|
|
|
|
return version_compare($entryVersion, $currentVersion, '>');
|
|
|
|
|
})
|
|
|
|
|
->take(3)
|
|
|
|
|
->map(fn ($entry) => [
|
|
|
|
|
'tag_name' => $entry->tag_name,
|
|
|
|
|
'title' => $entry->title,
|
|
|
|
|
'content_html' => $entry->content_html,
|
|
|
|
|
])
|
|
|
|
|
->values()
|
|
|
|
|
->toArray();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
$this->changelogEntries = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 13:08:48 +00:00
|
|
|
public function upgrade()
|
|
|
|
|
{
|
2023-05-25 20:33:47 +00:00
|
|
|
try {
|
2024-05-17 07:52:19 +00:00
|
|
|
if ($this->updateInProgress) {
|
2023-06-16 19:16:30 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2024-05-17 07:52:19 +00:00
|
|
|
$this->updateInProgress = true;
|
2024-05-30 17:38:33 +00:00
|
|
|
UpdateCoolify::run(manual_update: true);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-25 20:33:47 +00:00
|
|
|
}
|
2023-04-28 13:08:48 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|