refactor(vikon): use Redis cache for version instead of file
This commit is contained in:
@@ -345,14 +345,11 @@ class UpdateCoreAction
|
||||
$latestVersion = $body['version'] ?? null;
|
||||
|
||||
if ($latestVersion) {
|
||||
$versionFile = config('vikon.current_version_file');
|
||||
if ($versionFile) {
|
||||
file_put_contents($versionFile, $latestVersion);
|
||||
Log::info('Vikon: version updated', ['version' => $latestVersion]);
|
||||
}
|
||||
cache()->put('vikon:current_version', $latestVersion, 3600);
|
||||
Log::info('Vikon: version updated', ['version' => $latestVersion]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Vikon: failed to update version file', ['error' => $e->getMessage()]);
|
||||
Log::warning('Vikon: failed to update version', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,14 +70,9 @@ class VikonServiceProvider extends ServiceProvider
|
||||
));
|
||||
|
||||
$this->app->singleton(CheckVersionAction::class, function ($app) {
|
||||
$versionFile = config('vikon.current_version_file');
|
||||
$version = '1.0.0';
|
||||
if ($versionFile && file_exists($versionFile)) {
|
||||
$version = trim(file_get_contents($versionFile)) ?: '1.0.0';
|
||||
}
|
||||
return new CheckVersionAction(
|
||||
http: $app->make(HttpTask::class),
|
||||
currentVersion: $version,
|
||||
currentVersion: $app->make('vikon.version'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -98,5 +93,11 @@ class VikonServiceProvider extends ServiceProvider
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadRoutesFrom(app_path('Containers/VikonIntegration/UI/WEB/Routes/web.php'));
|
||||
|
||||
$this->app->bind('vikon.version', function () {
|
||||
return cache()->remember('vikon:current_version', 3600, function () {
|
||||
return config('vikon.current_version', '5.90.8.1');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class VikonController extends Controller
|
||||
|
||||
return inertia()->render('Dashboard/VikonUpdates/Index', [
|
||||
'is_authenticated' => $isAuth,
|
||||
'current_version' => $this->getCurrentVersion(),
|
||||
'current_version' => app('vikon.version'),
|
||||
'modules' => config('vikon.modules'),
|
||||
'parts' => $parts,
|
||||
'vikon_api_domain' => config('vikon.api_domain'),
|
||||
@@ -220,16 +220,4 @@ class VikonController extends Controller
|
||||
|
||||
return response()->json(['url' => $url]);
|
||||
}
|
||||
|
||||
private function getCurrentVersion(): string
|
||||
{
|
||||
$versionFile = config('vikon.current_version_file');
|
||||
if ($versionFile && file_exists($versionFile)) {
|
||||
$version = trim(file_get_contents($versionFile));
|
||||
if ($version !== '') {
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
return '1.0.0';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user