Files
coolify/app/Livewire/Upgrade.php
T
Andras Bacsai 16a8c7999d feat(audit): log account, resource, and instance settings changes
Add audit events for account actions, server and application settings,
services, destinations, storage, backup schedules, and scheduled tasks.
Track changed fields and skip unchanged saves without logging file content.

Add regression coverage for audit events and changed-field detection.
2026-10-04 17:32:50 +02:00

126 lines
3.5 KiB
PHP

<?php
namespace App\Livewire;
use App\Actions\Server\UpdateCoolify;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Services\CoolifyUpgradeStatus;
use Livewire\Component;
class Upgrade extends Component
{
public bool $updateInProgress = false;
public bool $isUpgradeAvailable = false;
public string $latestVersion = '';
public string $currentVersion = '';
public bool $devMode = false;
public bool $fullButton = false;
protected $listeners = ['updateAvailable' => 'checkUpdate'];
public function mount()
{
$this->refreshUpgradeState();
}
public function checkUpdate()
{
try {
$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 {
if (! isInstanceAdmin()) {
abort(403);
}
if ($this->updateInProgress) {
return;
}
$this->updateInProgress = true;
dispatch(function () {
try {
UpdateCoolify::run(manual_update: true);
} catch (\Throwable $e) {
report($e);
}
})->afterResponse();
auditLog('ui.instance.upgrade_started', [
'team_id' => null,
'resource' => 'instance',
'from_version' => config('constants.coolify.version'),
'to_version' => get_latest_version_of_coolify(),
]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function getUpgradeStatus(): array
{
// Only root team members can view upgrade status
if (auth()->user()?->currentTeam()?->id !== 0) {
return ['status' => 'none'];
}
$server = Server::find(0);
if (! $server) {
return ['status' => 'none'];
}
$statusFile = '/data/coolify/source/.upgrade-status';
try {
$content = instant_remote_process(
["cat {$statusFile} 2>/dev/null || echo ''"],
$server,
false
);
$content = trim($content ?? '');
} catch (\Throwable $e) {
return ['status' => 'none'];
}
return CoolifyUpgradeStatus::fromFile(
content: $content,
runningVersion: $this->currentVersion !== '' ? $this->currentVersion : (string) config('constants.coolify.version'),
targetVersion: $this->latestVersion !== '' ? $this->latestVersion : get_latest_version_of_coolify(),
);
}
}