diff options
Diffstat (limited to 'lib/private/FilesMetadata/MetadataQuery.php')
-rw-r--r-- | lib/private/FilesMetadata/MetadataQuery.php | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/lib/private/FilesMetadata/MetadataQuery.php b/lib/private/FilesMetadata/MetadataQuery.php index aa079c678d7..deae433e2fc 100644 --- a/lib/private/FilesMetadata/MetadataQuery.php +++ b/lib/private/FilesMetadata/MetadataQuery.php @@ -2,25 +2,8 @@ declare(strict_types=1); /** - * @copyright 2023 Maxence Lange <maxence@artificial-owl.com> - * - * @author Maxence Lange <maxence@artificial-owl.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\FilesMetadata; @@ -31,9 +14,11 @@ use OC\FilesMetadata\Service\MetadataRequestService; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException; use OCP\FilesMetadata\Exceptions\FilesMetadataTypeException; +use OCP\FilesMetadata\IFilesMetadataManager; use OCP\FilesMetadata\IMetadataQuery; use OCP\FilesMetadata\Model\IFilesMetadata; use OCP\FilesMetadata\Model\IMetadataValueWrapper; +use Psr\Log\LoggerInterface; /** * @inheritDoc @@ -43,12 +28,23 @@ class MetadataQuery implements IMetadataQuery { private array $knownJoinedIndex = []; public function __construct( private IQueryBuilder $queryBuilder, - private IFilesMetadata $knownMetadata, + private IFilesMetadata|IFilesMetadataManager $manager, private string $fileTableAlias = 'fc', private string $fileIdField = 'fileid', private string $alias = 'meta', - private string $aliasIndexPrefix = 'meta_index' + private string $aliasIndexPrefix = 'meta_index', ) { + if ($manager instanceof IFilesMetadata) { + /** + * Since 29, because knownMetadata is stored in lazy appconfig, it seems smarter + * to not call getKnownMetadata() at the load of this class as it is only needed + * in {@see getMetadataValueField}. + * + * FIXME: remove support for IFilesMetadata + */ + $logger = \OCP\Server::get(LoggerInterface::class); + $logger->debug('It is deprecated to use IFilesMetadata as second parameter when calling MetadataQuery::__construct()'); + } } /** @@ -158,7 +154,20 @@ class MetadataQuery implements IMetadataQuery { * @since 28.0.0 */ public function getMetadataValueField(string $metadataKey): string { - return match ($this->knownMetadata->getType($metadataKey)) { + if ($this->manager instanceof IFilesMetadataManager) { + /** + * Since 29, because knownMetadata is stored in lazy appconfig, it seems smarter + * to not call getKnownMetadata() at the load of this class as it is only needed + * in this method. + * + * FIXME: keep only this line and remove support for previous IFilesMetadata in constructor + */ + $knownMetadata = $this->manager->getKnownMetadata(); + } else { + $knownMetadata = $this->manager; + } + + return match ($knownMetadata->getType($metadataKey)) { IMetadataValueWrapper::TYPE_STRING => $this->joinedTableAlias($metadataKey) . '.meta_value_string', IMetadataValueWrapper::TYPE_INT, IMetadataValueWrapper::TYPE_BOOL => $this->joinedTableAlias($metadataKey) . '.meta_value_int', default => throw new FilesMetadataTypeException('metadata is not set as indexed'), |