From b76064d94ae0a20743823aa74e7b0d077debe8e6 Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sat, 1 Nov 2025 19:39:28 +0100 Subject: [PATCH] fix: stabilise staging sync --- deployment/stacks/staging/docker-compose.yml | 10 +- ....php => CreatePerformanceMetricsTable.php} | 0 ...1Command.php => DetectNPlusOneCommand.php} | 2 +- .../Processing/LegacyClassExtractor.php | 141 ------------------ ...p => CreateComponentStateHistoryTable.php} | 0 ...able.php => CreateComponentStateTable.php} | 0 6 files changed, 7 insertions(+), 146 deletions(-) rename src/Framework/Database/Migration/Migrations/{2024_09_28_233500_CreatePerformanceMetricsTable.php => CreatePerformanceMetricsTable.php} (100%) rename src/Framework/Database/QueryOptimization/Commands/{DetectN+1Command.php => DetectNPlusOneCommand.php} (99%) delete mode 100644 src/Framework/Discovery/Processing/LegacyClassExtractor.php rename src/Infrastructure/Database/Migrations/{2024_12_20_120100_CreateComponentStateHistoryTable.php => CreateComponentStateHistoryTable.php} (100%) rename src/Infrastructure/Database/Migrations/{2024_12_20_120000_CreateComponentStateTable.php => CreateComponentStateTable.php} (100%) diff --git a/deployment/stacks/staging/docker-compose.yml b/deployment/stacks/staging/docker-compose.yml index 51aeabb7..95c872c4 100644 --- a/deployment/stacks/staging/docker-compose.yml +++ b/deployment/stacks/staging/docker-compose.yml @@ -57,7 +57,9 @@ services: [ -f /run/secrets/GIT_TOKEN ] && export GIT_TOKEN="$(cat /run/secrets/GIT_TOKEN)" || true # Fix Git ownership issue + # Ensure Git treats the mounted repository as safe regardless of owner git config --global --add safe.directory /var/www/html 2>/dev/null || true + git config --system --add safe.directory /var/www/html 2>/dev/null || true # Git Clone/Pull functionality if [ -n "$GIT_REPOSITORY_URL" ]; then @@ -84,7 +86,7 @@ services: fi TEMP_CLONE="${GIT_TARGET_DIR}.tmp" rm -rf "$TEMP_CLONE" 2>/dev/null || true - if git clone --branch "$GIT_BRANCH" --depth 1 "$GIT_URL_WITH_AUTH" "$TEMP_CLONE"; then + if git -c safe.directory=/var/www/html clone --branch "$GIT_BRANCH" --depth 1 "$GIT_URL_WITH_AUTH" "$TEMP_CLONE"; then find "$GIT_TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name "storage" -exec rm -rf {} \; 2>/dev/null || true find "$TEMP_CLONE" -mindepth 1 -maxdepth 1 ! -name "." ! -name ".." -exec mv {} "$GIT_TARGET_DIR/" \; 2>/dev/null || true rm -rf "$TEMP_CLONE" 2>/dev/null || true @@ -93,9 +95,9 @@ services: else echo "🔄 Pulling latest changes from $GIT_BRANCH..." cd "$GIT_TARGET_DIR" - git fetch origin "$GIT_BRANCH" || echo "⚠️ Git fetch failed" - git reset --hard "origin/$GIT_BRANCH" || echo "⚠️ Git reset failed" - git clean -fd || true + git -c safe.directory=/var/www/html fetch origin "$GIT_BRANCH" || echo "⚠️ Git fetch failed" + git -c safe.directory=/var/www/html reset --hard "origin/$GIT_BRANCH" || echo "⚠️ Git reset failed" + git -c safe.directory=/var/www/html clean -fd || true fi # Install dependencies diff --git a/src/Framework/Database/Migration/Migrations/2024_09_28_233500_CreatePerformanceMetricsTable.php b/src/Framework/Database/Migration/Migrations/CreatePerformanceMetricsTable.php similarity index 100% rename from src/Framework/Database/Migration/Migrations/2024_09_28_233500_CreatePerformanceMetricsTable.php rename to src/Framework/Database/Migration/Migrations/CreatePerformanceMetricsTable.php diff --git a/src/Framework/Database/QueryOptimization/Commands/DetectN+1Command.php b/src/Framework/Database/QueryOptimization/Commands/DetectNPlusOneCommand.php similarity index 99% rename from src/Framework/Database/QueryOptimization/Commands/DetectN+1Command.php rename to src/Framework/Database/QueryOptimization/Commands/DetectNPlusOneCommand.php index f40d9583..b1195a54 100644 --- a/src/Framework/Database/QueryOptimization/Commands/DetectN+1Command.php +++ b/src/Framework/Database/QueryOptimization/Commands/DetectNPlusOneCommand.php @@ -25,7 +25,7 @@ use App\Framework\Logging\ValueObjects\LogContext; name: 'detect:n-plus-one', description: 'Detect N+1 query problems and generate optimization recommendations' )] -final readonly class DetectN+1Command +final readonly class DetectNPlusOneCommand { public function __construct( private NPlusOneDetectionService $detectionService, diff --git a/src/Framework/Discovery/Processing/LegacyClassExtractor.php b/src/Framework/Discovery/Processing/LegacyClassExtractor.php deleted file mode 100644 index c0344280..00000000 --- a/src/Framework/Discovery/Processing/LegacyClassExtractor.php +++ /dev/null @@ -1,141 +0,0 @@ - '/^\s*namespace\s+([^;]+);/m', - 'class' => '/^\s*(?:final\s+)?(?:abstract\s+)?(?:readonly\s+)?class\s+([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/mi', - 'interface' => '/^\s*interface\s+([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/mi', - 'trait' => '/^\s*trait\s+([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/mi', - 'enum' => '/^\s*enum\s+([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/mi', - ]; - - public function __construct( - private FileSystemService $fileSystemService - ) { - } - - /** - * Extract class names from a file - * @return array - */ - public function extractFromFile(File $file): array - { - try { - // Read file content once - $content = $this->fileSystemService->readFile($file); - - // Extract namespace - $namespace = $this->extractNamespace($content); - - // Extract all class-like declarations - $classNames = []; - - foreach (['class', 'interface', 'trait', 'enum'] as $type) { - $names = $this->extractDeclarations($content, $type, $namespace); - foreach ($names as $name) { - $classNames[] = $name; - } - } - - return $this->deduplicateClassNames($classNames); - - } catch (Throwable) { - // Silently fail for files that can't be processed - return []; - } - } - - /** - * Extract namespace from content - */ - private function extractNamespace(string $content): string - { - if (preg_match(self::PATTERNS['namespace'], $content, $matches)) { - return trim($matches[1]); - } - - return ''; - } - - /** - * Extract declarations of a specific type - * @return array - */ - private function extractDeclarations(string $content, string $type, string $namespace): array - { - $pattern = self::PATTERNS[$type] ?? null; - if (! $pattern) { - return []; - } - - $classNames = []; - if (preg_match_all($pattern, $content, $matches)) { - foreach ($matches[1] as $name) { - $fullName = $namespace ? $namespace . '\\' . $name : $name; - $classNames[] = ClassName::create($fullName); - } - } - - return $classNames; - } - - /** - * Remove duplicate class names - * @param array $classNames - * @return array - */ - private function deduplicateClassNames(array $classNames): array - { - $seen = []; - $unique = []; - - foreach ($classNames as $className) { - $fqn = $className->getFullyQualified(); - if (! isset($seen[$fqn])) { - $seen[$fqn] = true; - $unique[] = $className; - } - } - - return $unique; - } - - /** - * Quick check if content likely contains PHP classes - */ - public function likelyContainsClasses(string $content): bool - { - // Quick checks to avoid regex on files that definitely don't have classes - if (strlen($content) < 10) { - return false; - } - - // Must have PHP opening tag - if (! str_contains($content, '