Fix: seed current_version from latest on first detection

When a server is first detected, current_version is set to latest_version
(the pack was just installed = it's current). On future runs, if the API
returns a newer latest_version, the stored current_version stays and we
detect the update. Also preserves egg variable and existing DB values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude (Chronicler #83 - The Compiler)
2026-04-12 23:04:04 -05:00
parent 8de93f26ce
commit 68ee40e89d
2 changed files with 54 additions and 3 deletions

View File

@@ -221,15 +221,31 @@ class CheckModpackUpdates extends Command
{
try {
$latestData = $this->apiService->fetchLatestVersion($platform, $modpackId);
$latestVersion = $latestData['version'] ?? 'Unknown';
// Get current_version: egg variable > existing DB record > seed with latest
$currentVersion = $this->getVariable($server, 'MODPACK_CURRENT_VERSION');
$updateAvailable = $currentVersion && $currentVersion !== $latestData['version'];
if (empty($currentVersion)) {
$existing = DB::table('modpackchecker_servers')
->where('server_uuid', $server->uuid)
->first();
$currentVersion = $existing->current_version ?? null;
}
// First time seeing this server — seed current_version with latest
if (empty($currentVersion)) {
$currentVersion = $latestVersion;
}
$updateAvailable = $currentVersion !== $latestVersion;
$this->updateDatabase($server, [
'platform' => $platform,
'modpack_id' => $modpackId,
'modpack_name' => $latestData['name'],
'current_version' => $currentVersion,
'latest_version' => $latestData['version'],
'latest_version' => $latestVersion,
'status' => $updateAvailable ? 'update_available' : 'up_to_date',
'detection_method' => $method,
'error_message' => null,
@@ -237,7 +253,7 @@ class CheckModpackUpdates extends Command
]);
$icon = $updateAvailable ? '🟠 UPDATE' : '🟢 OK';
$this->info(" {$icon}: {$latestData['name']}{$latestData['version']} [{$method}]");
$this->info(" {$icon}: {$latestData['name']}current: {$currentVersion}, latest: {$latestVersion} [{$method}]");
} catch (\Exception $e) {
$this->error(" Error: {$e->getMessage()}");