mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
fix: Remove static vars in trashbin, versions and storages
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
8b5bc09cbe
commit
9d7c277668
4 changed files with 27 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use OCP\FilesMetadata\IMetadataQuery;
|
|||
*/
|
||||
class SearchBuilder {
|
||||
/** @var array<string, string> */
|
||||
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<string, string> */
|
||||
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<string, string> */
|
||||
protected static $fieldTypes = [
|
||||
private const FIELD_TYPES = [
|
||||
'mimetype' => 'string',
|
||||
'mtime' => 'integer',
|
||||
'name' => 'string',
|
||||
|
|
@ -69,14 +69,14 @@ class SearchBuilder {
|
|||
];
|
||||
|
||||
/** @var array<string, int|string> */
|
||||
protected static $paramTypeMap = [
|
||||
private const PARAM_TYPE_MAP = [
|
||||
'string' => IQueryBuilder::PARAM_STR,
|
||||
'integer' => IQueryBuilder::PARAM_INT,
|
||||
'boolean' => IQueryBuilder::PARAM_BOOL,
|
||||
];
|
||||
|
||||
/** @var array<string, int> */
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue