From 720aa4d0aeae897b77cf7d4b72a08dc41ca78804 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Sun, 5 Jul 2026 23:13:51 +0500 Subject: [PATCH] feat(logging): migrate VikonIntegration to vikon channel --- .../Actions/CheckAccessAction.php | 2 +- .../Actions/CheckVersionAction.php | 2 +- .../Actions/SyncFilesAction.php | 10 +++---- .../Actions/UpdateCoreAction.php | 28 +++++++++---------- .../Actions/UpdatePartAction.php | 8 +++--- .../VikonIntegration/Tasks/FilesystemTask.php | 2 +- .../Tasks/PollPartStatusTask.php | 2 +- .../Tasks/ValidateTokenTask.php | 2 +- .../UI/WEB/Controllers/VikonController.php | 10 +++---- app/Http/Middleware/VikonTokenRefresh.php | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/Containers/VikonIntegration/Actions/CheckAccessAction.php b/app/Containers/VikonIntegration/Actions/CheckAccessAction.php index f3eb8e3..9233116 100644 --- a/app/Containers/VikonIntegration/Actions/CheckAccessAction.php +++ b/app/Containers/VikonIntegration/Actions/CheckAccessAction.php @@ -88,7 +88,7 @@ class CheckAccessAction 'parts' => $partsByModule, ]; } catch (\Throwable $e) { - Log::error('Vikon access check failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->error('Vikon access check failed', ['error' => $e->getMessage()]); return [ 'has_access' => false, 'error' => 'Не удалось проверить права: ' . $e->getMessage(), diff --git a/app/Containers/VikonIntegration/Actions/CheckVersionAction.php b/app/Containers/VikonIntegration/Actions/CheckVersionAction.php index ee8c9c4..1c4970b 100644 --- a/app/Containers/VikonIntegration/Actions/CheckVersionAction.php +++ b/app/Containers/VikonIntegration/Actions/CheckVersionAction.php @@ -24,7 +24,7 @@ class CheckVersionAction 'has_update' => $latest && version_compare($latest, $this->currentVersion, '>'), ]; } catch (\Throwable $e) { - Log::warning('Version check failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->warning('Version check failed', ['error' => $e->getMessage()]); return [ 'current_version' => $this->currentVersion, 'latest_version' => null, diff --git a/app/Containers/VikonIntegration/Actions/SyncFilesAction.php b/app/Containers/VikonIntegration/Actions/SyncFilesAction.php index 9ad3c4a..5ca52dc 100644 --- a/app/Containers/VikonIntegration/Actions/SyncFilesAction.php +++ b/app/Containers/VikonIntegration/Actions/SyncFilesAction.php @@ -20,10 +20,10 @@ class SyncFilesAction File::makeDirectory($modulePath, 0755, true, true); File::makeDirectory($filesDir, 0755, true, true); - Log::info('Vikon FM: starting sync', ['module' => $moduleId]); + Log::channel('vikon')->info('Vikon FM: starting sync', ['module' => $moduleId]); $dirIds = $this->getUsedDirNames($moduleId, $accessToken); - Log::info('Vikon FM: dir identifiers', ['count' => count($dirIds)]); + Log::channel('vikon')->info('Vikon FM: dir identifiers', ['count' => count($dirIds)]); $synced = 0; @@ -36,7 +36,7 @@ class SyncFilesAction $newSynced = $this->syncNewFiles($moduleId, $accessToken, $filesDir); $total = $synced + $newSynced; - Log::info('Vikon FM: sync complete', ['downloaded' => $synced, 'new' => $newSynced]); + Log::channel('vikon')->info('Vikon FM: sync complete', ['downloaded' => $synced, 'new' => $newSynced]); return "Синхронизировано: {$total} файлов"; } @@ -94,7 +94,7 @@ class SyncFilesAction file_put_contents($filesDir . '/' . $name, $content); $synced++; } catch (\Throwable $e) { - Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); } } return $synced; @@ -138,7 +138,7 @@ class SyncFilesAction file_put_contents($targetDir . '/' . $name, $content); $synced++; } catch (\Throwable $e) { - Log::warning('Vikon FM: sub download failed', ['identity' => $identity, 'error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon FM: sub download failed', ['identity' => $identity, 'error' => $e->getMessage()]); } } return $synced; diff --git a/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php b/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php index d8c7351..7467071 100644 --- a/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php +++ b/app/Containers/VikonIntegration/Actions/UpdateCoreAction.php @@ -24,7 +24,7 @@ class UpdateCoreAction $modulePath = $this->basePath . '/' . $config['path']; $tempPath = $this->storagePath . '/temp/' . $config['path']; - Log::info('Vikon: starting full update', ['module' => $moduleId]); + Log::channel('vikon')->info('Vikon: starting full update', ['module' => $moduleId]); $this->downloadCore($moduleId, $modulePath, $tempPath, $accessToken); $this->syncFromFM($moduleId, $modulePath, $accessToken); @@ -35,7 +35,7 @@ class UpdateCoreAction // Update version file from API $this->updateVersionFile($accessToken); - Log::info('Vikon: full update complete', ['module' => $config['name']]); + Log::channel('vikon')->info('Vikon: full update complete', ['module' => $config['name']]); return 'Модуль "' . $config['name'] . '" полностью обновлён.'; } @@ -56,13 +56,13 @@ class UpdateCoreAction $zipFile ); - Log::info('Vikon: ZIP downloaded', ['size' => filesize($zipFile), 'module' => $moduleId]); + Log::channel('vikon')->info('Vikon: ZIP downloaded', ['size' => filesize($zipFile), 'module' => $moduleId]); $this->extractZip($zipFile, $tempPath); // Log what was extracted $extracted = array_map(fn($f) => basename($f), File::allFiles($tempPath)); - Log::info('Vikon: extracted files', ['count' => count($extracted), 'sample' => array_slice($extracted, 0, 10)]); + Log::channel('vikon')->info('Vikon: extracted files', ['count' => count($extracted), 'sample' => array_slice($extracted, 0, 10)]); $blocked = $this->fs->validateFileTypes($tempPath); if (!empty($blocked)) { @@ -74,7 +74,7 @@ class UpdateCoreAction File::makeDirectory($modulePath, 0755, true, true); $this->copyFiles($syncSource, $modulePath); - Log::info('Vikon: core downloaded', ['module' => $moduleId]); + Log::channel('vikon')->info('Vikon: core downloaded', ['module' => $moduleId]); } private function syncFromFM(int $moduleId, string $modulePath, string $accessToken): void @@ -84,7 +84,7 @@ class UpdateCoreAction File::makeDirectory($filesDir, 0755, true, true); $dirIds = $this->getUsedDirNames($moduleId, $accessToken); - Log::info('Vikon FM: dir identifiers', ['count' => count($dirIds), 'dirs' => $dirIds]); + Log::channel('vikon')->info('Vikon FM: dir identifiers', ['count' => count($dirIds), 'dirs' => $dirIds]); $synced = 0; @@ -96,7 +96,7 @@ class UpdateCoreAction $newSynced = $this->syncNewFiles($moduleId, $accessToken, $filesDir); - Log::info('Vikon FM: sync done', ['synced' => $synced, 'new' => $newSynced]); + Log::channel('vikon')->info('Vikon FM: sync done', ['synced' => $synced, 'new' => $newSynced]); } private function syncRootDir(int $moduleId, string $filesDir, string $accessToken): int @@ -141,11 +141,11 @@ class UpdateCoreAction file_put_contents($filesDir . '/' . $name, $content); $synced++; } catch (\Throwable $e) { - Log::warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon FM: root download failed', ['identity' => $identity, 'error' => $e->getMessage()]); } } - Log::info('Vikon FM: root dir stats', [ + Log::channel('vikon')->info('Vikon FM: root dir stats', [ 'server' => $serverCount, 'local' => $localCount, 'to_download' => $toDownload, @@ -193,7 +193,7 @@ class UpdateCoreAction file_put_contents($targetDir . '/' . $name, $content); $synced++; } catch (\Throwable $e) { - Log::warning('Vikon FM: sub download failed', ['identity' => $identity, 'error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon FM: sub download failed', ['identity' => $identity, 'error' => $e->getMessage()]); } } return $synced; @@ -236,7 +236,7 @@ class UpdateCoreAction $synced++; } catch (\Throwable $e) { - Log::warning('Vikon FM: new file failed', ['identity' => $identity, 'error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon FM: new file failed', ['identity' => $identity, 'error' => $e->getMessage()]); } } return $synced; @@ -333,7 +333,7 @@ class UpdateCoreAction } if ($removed > 0) { - Log::info('Vikon: cleaned up post-sync', ['removed' => $removed]); + Log::channel('vikon')->info('Vikon: cleaned up post-sync', ['removed' => $removed]); } } @@ -346,10 +346,10 @@ class UpdateCoreAction if ($latestVersion) { cache()->put('vikon:current_version', $latestVersion, 3600); - Log::info('Vikon: version updated', ['version' => $latestVersion]); + Log::channel('vikon')->info('Vikon: version updated', ['version' => $latestVersion]); } } catch (\Throwable $e) { - Log::warning('Vikon: failed to update version', ['error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon: failed to update version', ['error' => $e->getMessage()]); } } } diff --git a/app/Containers/VikonIntegration/Actions/UpdatePartAction.php b/app/Containers/VikonIntegration/Actions/UpdatePartAction.php index 8a95b32..3719f08 100644 --- a/app/Containers/VikonIntegration/Actions/UpdatePartAction.php +++ b/app/Containers/VikonIntegration/Actions/UpdatePartAction.php @@ -24,7 +24,7 @@ class UpdatePartAction { $config = $this->modulesConfig[$moduleId] ?? throw new \RuntimeException("Неизвестный модуль: {$moduleId}"); - Log::info('Vikon: starting part update', ['module' => $moduleId, 'part' => $part]); + Log::channel('vikon')->info('Vikon: starting part update', ['module' => $moduleId, 'part' => $part]); // Step 1: Request generation $genResponse = $this->http->postWithToken( @@ -40,7 +40,7 @@ class UpdatePartAction $operationIdentity = $genBody['operation_identity']; - Log::info('Vikon: part generation requested', ['operation' => $operationIdentity]); + Log::channel('vikon')->info('Vikon: part generation requested', ['operation' => $operationIdentity]); // Step 2: Poll status $pollResult = $this->pollStatus->run($operationIdentity, $accessToken); @@ -98,7 +98,7 @@ class UpdatePartAction $this->cleanupPostSync($modulePath); } - Log::info('Vikon: part update complete', ['module' => $moduleId, 'part' => $part, 'synced' => $syncedCount]); + Log::channel('vikon')->info('Vikon: part update complete', ['module' => $moduleId, 'part' => $part, 'synced' => $syncedCount]); return [ 'success' => true, @@ -222,7 +222,7 @@ class UpdatePartAction } if ($removed > 0) { - Log::info('Vikon: cleaned up post-sync', ['removed' => $removed, 'path' => $modulePath]); + Log::channel('vikon')->info('Vikon: cleaned up post-sync', ['removed' => $removed, 'path' => $modulePath]); } } } diff --git a/app/Containers/VikonIntegration/Tasks/FilesystemTask.php b/app/Containers/VikonIntegration/Tasks/FilesystemTask.php index 4584212..b4a8cea 100644 --- a/app/Containers/VikonIntegration/Tasks/FilesystemTask.php +++ b/app/Containers/VikonIntegration/Tasks/FilesystemTask.php @@ -24,7 +24,7 @@ class FilesystemTask public function safeRemove(string $path, string $base, bool $recursive = false): bool { if (!$this->isPathSafe($path, $base)) { - Log::warning('Path traversal blocked', ['path' => $path, 'base' => $base]); + Log::channel('vikon')->warning('Path traversal blocked', ['path' => $path, 'base' => $base]); return false; } if (!file_exists($path)) return true; diff --git a/app/Containers/VikonIntegration/Tasks/PollPartStatusTask.php b/app/Containers/VikonIntegration/Tasks/PollPartStatusTask.php index 5b09f4c..d837dd0 100644 --- a/app/Containers/VikonIntegration/Tasks/PollPartStatusTask.php +++ b/app/Containers/VikonIntegration/Tasks/PollPartStatusTask.php @@ -23,7 +23,7 @@ class PollPartStatusTask $body = $response->json(); $status = $body['status'] ?? -2; - Log::info('Vikon poll part status', [ + Log::channel('vikon')->info('Vikon poll part status', [ 'operation' => $operationIdentity, 'status' => $status, 'attempt' => $attempt + 1, diff --git a/app/Containers/VikonIntegration/Tasks/ValidateTokenTask.php b/app/Containers/VikonIntegration/Tasks/ValidateTokenTask.php index e37b24b..cd4f52a 100644 --- a/app/Containers/VikonIntegration/Tasks/ValidateTokenTask.php +++ b/app/Containers/VikonIntegration/Tasks/ValidateTokenTask.php @@ -32,7 +32,7 @@ class ValidateTokenTask return $valid; } catch (\Throwable $e) { - Log::warning('Vikon token validation failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon token validation failed', ['error' => $e->getMessage()]); return false; } } diff --git a/app/Containers/VikonIntegration/UI/WEB/Controllers/VikonController.php b/app/Containers/VikonIntegration/UI/WEB/Controllers/VikonController.php index 892600a..f29e83c 100644 --- a/app/Containers/VikonIntegration/UI/WEB/Controllers/VikonController.php +++ b/app/Containers/VikonIntegration/UI/WEB/Controllers/VikonController.php @@ -59,7 +59,7 @@ class VikonController extends Controller $expectedState = Session::pull('oauth_state'); if ($state && $expectedState && $state !== $expectedState) { - Log::warning('Vikon OAuth CSRF mismatch'); + Log::channel('vikon')->warning('Vikon OAuth CSRF mismatch'); } $code = $request->query('code'); @@ -70,7 +70,7 @@ class VikonController extends Controller Session::put('vikon_access_token', $tokens['access_token']); Session::put('vikon_refresh_token', $tokens['refresh_token']); } catch (\Throwable $e) { - Log::error('OAuth callback failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->error('OAuth callback failed', ['error' => $e->getMessage()]); } } @@ -159,7 +159,7 @@ class VikonController extends Controller $message = $this->updateCore->run($request->validated('module_id'), $token); return response()->json(['success' => true, 'message' => $message]); } catch (\Throwable $e) { - Log::error('Vikon update failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->error('Vikon update failed', ['error' => $e->getMessage()]); return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } } @@ -175,7 +175,7 @@ class VikonController extends Controller $message = $this->syncFiles->run($request->validated('module_id'), $token); return response()->json(['success' => true, 'message' => $message]); } catch (\Throwable $e) { - Log::error('Vikon sync failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->error('Vikon sync failed', ['error' => $e->getMessage()]); return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } } @@ -195,7 +195,7 @@ class VikonController extends Controller ); return response()->json($result); } catch (\Throwable $e) { - Log::error('Vikon part update failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->error('Vikon part update failed', ['error' => $e->getMessage()]); return response()->json(['success' => false, 'message' => $e->getMessage()], 500); } } diff --git a/app/Http/Middleware/VikonTokenRefresh.php b/app/Http/Middleware/VikonTokenRefresh.php index a22668f..6dc2eac 100644 --- a/app/Http/Middleware/VikonTokenRefresh.php +++ b/app/Http/Middleware/VikonTokenRefresh.php @@ -25,7 +25,7 @@ class VikonTokenRefresh Session::put('vikon_access_token', $tokens['access_token']); Session::put('vikon_refresh_token', $tokens['refresh_token']); } catch (\Throwable $e) { - Log::warning('Vikon auto-refresh failed', ['error' => $e->getMessage()]); + Log::channel('vikon')->warning('Vikon auto-refresh failed', ['error' => $e->getMessage()]); Session::forget(['vikon_access_token', 'vikon_refresh_token']); } }