diff --git a/lib/Service/ExcludedFolderService.php b/lib/Service/ExcludedFolderService.php index a9bd5c4..0e21d91 100644 --- a/lib/Service/ExcludedFolderService.php +++ b/lib/Service/ExcludedFolderService.php @@ -34,8 +34,9 @@ public function __construct( private function validateUserContext(): void { if (empty($this->userId)) { - $this->logger->debug('No user context available'); - throw new \RuntimeException('User context required for this operation'); + $this->logger->debug('No user context available, skipping excluded folder check'); + // Instead of throwing an exception, we'll just skip the check + return; } $this->logger->debug('User context validated: {userId}', ['userId' => $this->userId]); } @@ -141,58 +142,50 @@ public function delete(int $id): void { } } - public function isPathExcluded(string $path): bool { - $this->validateUserContext(); - - $this->logger->debug('Checking if path is in excluded folder', [ - 'path' => $path, - 'userId' => $this->userId - ]); - - // Normalize path for comparison - remove /admin/files/ prefix + private function isPathInExcludedFolder(string $path, string $excludedPath): bool { + // Normalize paths for comparison - remove /admin/files/ prefix $normalizedPath = preg_replace('#^/[^/]+/files/#', '/', $path); $normalizedPath = '/' . trim($normalizedPath, '/'); - - $this->logger->debug('Normalized path for exclusion check', [ - 'originalPath' => $path, - 'normalizedPath' => $normalizedPath, - 'strippedPrefix' => preg_match('#^/[^/]+/files/#', $path) ? 'true' : 'false' - ]); + $excludedPath = '/' . trim($excludedPath, '/'); - // Get all excluded folders - $excludedFolders = $this->findAll(); - $this->logger->debug('Found excluded folders', [ - 'count' => count($excludedFolders), - 'paths' => array_map(fn($f) => $f->getFolderPath(), $excludedFolders) + $this->logger->debug('Comparing paths for exclusion', [ + 'filePath' => $normalizedPath, + 'excludedPath' => $excludedPath, + 'isSubPath' => str_starts_with($normalizedPath, $excludedPath), + 'exactMatch' => $normalizedPath === $excludedPath ]); - foreach ($excludedFolders as $folder) { - $excludedPath = '/' . trim($folder->getFolderPath(), '/'); - $this->logger->debug('Comparing paths for exclusion', [ - 'filePath' => $normalizedPath, - 'excludedPath' => $excludedPath, - 'isSubPath' => str_starts_with($normalizedPath, $excludedPath), - 'exactMatch' => $normalizedPath === $excludedPath + // Check if the path is either exactly the excluded path or starts with it followed by a slash + return $normalizedPath === $excludedPath || str_starts_with($normalizedPath, $excludedPath . '/'); + } + + public function isPathExcluded(string $path): bool { + if (empty($this->userId)) { + $this->logger->debug('No user context available for path exclusion check, assuming not excluded', [ + 'path' => $path ]); + return false; + } - // Check if the path is either exactly the excluded path or starts with it followed by a slash - if ($normalizedPath === $excludedPath || str_starts_with($normalizedPath, $excludedPath . '/')) { - $this->logger->debug('Path is in excluded folder', [ - 'path' => $path, - 'normalizedPath' => $normalizedPath, - 'excludedFolder' => $excludedPath, - 'matchType' => $normalizedPath === $excludedPath ? 'exact' : 'subpath' - ]); - return true; + try { + $excludedFolders = $this->findAll(); + foreach ($excludedFolders as $excludedFolder) { + if ($this->isPathInExcludedFolder($path, $excludedFolder->getFolderPath())) { + $this->logger->debug('Path is in excluded folder', [ + 'path' => $path, + 'excludedFolder' => $excludedFolder->getFolderPath() + ]); + return true; + } } + } catch (\Exception $e) { + $this->logger->warning('Error checking excluded folders, assuming not excluded', [ + 'path' => $path, + 'error' => $e->getMessage() + ]); + return false; } - $this->logger->debug('Path is not in any excluded folder', [ - 'path' => $path, - 'normalizedPath' => $normalizedPath, - 'checkedFolders' => count($excludedFolders) - ]); - return false; }