From 9d7c2776684b6dda8958c857af91bcfeec7b999f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 17 Mar 2026 16:34:44 +0100 Subject: [PATCH] fix: Remove static vars in trashbin, versions and storages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Service/BackendService.php | 9 +++---- .../lib/Command/RestoreAllFiles.php | 6 ++--- apps/files_versions/lib/Storage.php | 14 +++++------ lib/private/Files/Cache/SearchBuilder.php | 24 +++++++++---------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/apps/files_external/lib/Service/BackendService.php b/apps/files_external/lib/Service/BackendService.php index bb147f1d84b..1359379131e 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/apps/files_external/lib/Service/BackendService.php @@ -62,6 +62,7 @@ class BackendService { /** @var IConfigHandler[] */ private array $configHandlers = []; + private bool $eventSent = false; public function __construct( protected readonly IAppConfig $appConfig, @@ -79,14 +80,14 @@ class BackendService { $this->backendProviders[] = $provider; } - private function callForRegistrations() { - static $eventSent = false; - if (!$eventSent) { + private function callForRegistrations(): void { + $instance = Server::get(self::class); + if (!$instance->eventSent) { Server::get(IEventDispatcher::class)->dispatch( 'OCA\\Files_External::loadAdditionalBackends', new GenericEvent() ); - $eventSent = true; + $instance->eventSent = true; } } diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php index 7855e668890..adf2bcacd8a 100644 --- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php +++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php @@ -30,7 +30,7 @@ class RestoreAllFiles extends Base { private const SCOPE_USER = 1; private const SCOPE_GROUPFOLDERS = 2; - private static array $SCOPE_MAP = [ + private const SCOPE_MAP = [ 'user' => self::SCOPE_USER, 'groupfolders' => self::SCOPE_GROUPFOLDERS, 'all' => self::SCOPE_ALL @@ -221,8 +221,8 @@ class RestoreAllFiles extends Base { } protected function parseScope(string $scope): int { - if (isset(self::$SCOPE_MAP[$scope])) { - return self::$SCOPE_MAP[$scope]; + if (isset(self::SCOPE_MAP[$scope])) { + return self::SCOPE_MAP[$scope]; } throw new InvalidOptionException("Invalid scope '$scope'"); diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 3349ee4d191..303048d0085 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -60,7 +60,7 @@ class Storage { private static $sourcePathAndUser = []; - private static $max_versions_per_interval = [ + private const MAX_VERSIONS_PER_INTERVAL = [ //first 10sec, one version every 2sec 1 => ['intervalEndsAfter' => 10, 'step' => 2], //next minute, one version every 10sec @@ -763,11 +763,11 @@ class Storage { $toDelete = []; // versions we want to delete $interval = 1; - $step = Storage::$max_versions_per_interval[$interval]['step']; - if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) { + $step = Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['step']; + if (Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) { $nextInterval = -1; } else { - $nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter']; + $nextInterval = $time - Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; } $firstVersion = reset($versions); @@ -797,12 +797,12 @@ class Storage { $newInterval = false; // version checked so we can move to the next one } else { // time to move on to the next interval $interval++; - $step = Storage::$max_versions_per_interval[$interval]['step']; + $step = Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['step']; $nextVersion = $prevTimestamp - $step; - if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) { + if (Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) { $nextInterval = -1; } else { - $nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter']; + $nextInterval = $time - Storage::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter']; } $newInterval = true; // we changed the interval -> check same version with new interval } diff --git a/lib/private/Files/Cache/SearchBuilder.php b/lib/private/Files/Cache/SearchBuilder.php index 009a1d068e1..79fc7db1a4b 100644 --- a/lib/private/Files/Cache/SearchBuilder.php +++ b/lib/private/Files/Cache/SearchBuilder.php @@ -24,7 +24,7 @@ use OCP\FilesMetadata\IMetadataQuery; */ class SearchBuilder { /** @var array */ - protected static $searchOperatorMap = [ + private const SEARCH_OPERATOR_MAP = [ ISearchComparison::COMPARE_LIKE => 'iLike', ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE => 'like', ISearchComparison::COMPARE_EQUAL => 'eq', @@ -37,7 +37,7 @@ class SearchBuilder { ]; /** @var array */ - protected static $searchOperatorNegativeMap = [ + private const SEARCH_OPERATOR_NEGATIVE_MAP = [ ISearchComparison::COMPARE_LIKE => 'notLike', ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE => 'notLike', ISearchComparison::COMPARE_EQUAL => 'neq', @@ -50,7 +50,7 @@ class SearchBuilder { ]; /** @var array */ - protected static $fieldTypes = [ + private const FIELD_TYPES = [ 'mimetype' => 'string', 'mtime' => 'integer', 'name' => 'string', @@ -69,14 +69,14 @@ class SearchBuilder { ]; /** @var array */ - protected static $paramTypeMap = [ + private const PARAM_TYPE_MAP = [ 'string' => IQueryBuilder::PARAM_STR, 'integer' => IQueryBuilder::PARAM_INT, 'boolean' => IQueryBuilder::PARAM_BOOL, ]; /** @var array */ - protected static $paramArrayTypeMap = [ + private const PARAM_ARRAY_TYPE_MAP = [ 'string' => IQueryBuilder::PARAM_STR_ARRAY, 'integer' => IQueryBuilder::PARAM_INT_ARRAY, 'boolean' => IQueryBuilder::PARAM_INT_ARRAY, @@ -134,7 +134,7 @@ class SearchBuilder { case ISearchBinaryOperator::OPERATOR_NOT: $negativeOperator = $operator->getArguments()[0]; if ($negativeOperator instanceof ISearchComparison) { - return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap, $metadataQuery); + return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::SEARCH_OPERATOR_NEGATIVE_MAP, $metadataQuery); } else { throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); } @@ -147,7 +147,7 @@ class SearchBuilder { throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); } } elseif ($operator instanceof ISearchComparison) { - return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap, $metadataQuery); + return $this->searchComparisonToDBExpr($builder, $operator, self::SEARCH_OPERATOR_MAP, $metadataQuery); } else { throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); } @@ -193,7 +193,7 @@ class SearchBuilder { * @return list{string, ParamValue, string, string} */ private function getOperatorFieldAndValueInner(string $field, mixed $value, string $type, bool $pathEqHash): array { - $paramType = self::$fieldTypes[$field]; + $paramType = self::FIELD_TYPES[$field]; if ($type === ISearchComparison::COMPARE_IN) { $resultField = $field; $values = []; @@ -263,10 +263,10 @@ class SearchBuilder { 'upload_time' => ['eq', 'gt', 'lt', 'gte', 'lte'], ]; - if (!isset(self::$fieldTypes[$operator->getField()])) { + if (!isset(self::FIELD_TYPES[$operator->getField()])) { throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); } - $type = self::$fieldTypes[$operator->getField()]; + $type = self::FIELD_TYPES[$operator->getField()]; if ($operator->getType() === ISearchComparison::COMPARE_IN) { if (!is_array($operator->getValue())) { throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); @@ -316,9 +316,9 @@ class SearchBuilder { $value = $value->getTimestamp(); } if (is_array($value)) { - $type = self::$paramArrayTypeMap[$paramType]; + $type = self::PARAM_ARRAY_TYPE_MAP[$paramType]; } else { - $type = self::$paramTypeMap[$paramType]; + $type = self::PARAM_TYPE_MAP[$paramType]; } return $builder->createNamedParameter($value, $type); }