Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore metadata if migration to 28 is not done #41442

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function get($file) {
} elseif (!$data) {
return $data;
} else {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public function getFolderContentsById($fileId) {
$result->closeCursor();

return array_map(function (array $data) use ($metadataQuery) {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
$data['metadata'] = $metadataQuery?->extractMetadata($data)->asArray() ?? [];
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ public function whereParentInParameter(string $parameter) {
return $this;
}

public function selectMetadata(): IMetadataQuery {
/**
* join metadata to current query builder and returns an helper
*
* @return IMetadataQuery|null NULL if no metadata have never been generated
*/
public function selectMetadata(): ?IMetadataQuery {
$metadataQuery = $this->filesMetadataManager->getMetadataQuery($this, $this->alias, 'fileid');
$metadataQuery->retrieveMetadata();
$metadataQuery?->retrieveMetadata();
return $metadataQuery;
}
}
13 changes: 12 additions & 1 deletion lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ protected function getQueryBuilder() {
);
}

/**
* @param CacheQueryBuilder $query
* @param ISearchQuery $searchQuery
* @param array $caches
* @param IMetadataQuery|null $metadataQuery
*/
protected function applySearchConstraints(
CacheQueryBuilder $query,
ISearchQuery $searchQuery,
Expand Down Expand Up @@ -189,7 +195,12 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
$files = $result->fetchAll();

$rawEntries = array_map(function (array $data) use ($metadataQuery) {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
// migrate to null safe ...
if ($metadataQuery === null) {
$data['metadata'] = [];
} else {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
}
return Cache::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);

Expand Down
8 changes: 6 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,19 @@ public function deleteMetadata(int $fileId): void {
* @param string $fileIdField alias of the field that contains file ids
*
* @inheritDoc
* @return IMetadataQuery
* @return IMetadataQuery|null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The info is already in method signature. We can remove this line.

* @see IMetadataQuery
* @since 28.0.0
*/
public function getMetadataQuery(
IQueryBuilder $qb,
string $fileTableAlias,
string $fileIdField
): IMetadataQuery {
): ?IMetadataQuery {
// we don't want to join metadata table if never filled
if ($this->config->getAppValue('core', self::CONFIG_KEY, '') === '') {
return null;
}
return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/public/FilesMetadata/IFilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public function deleteMetadata(int $fileId): void;
* @param string $fileTableAlias alias of the table that contains data about files
* @param string $fileIdField alias of the field that contains file ids
*
* @return IMetadataQuery
* @return IMetadataQuery|null NULL if table are not set yet or never used
* @see IMetadataQuery
* @since 28.0.0
*/
public function getMetadataQuery(
IQueryBuilder $qb,
string $fileTableAlias,
string $fileIdField
): IMetadataQuery;
): ?IMetadataQuery;

/**
* returns all type of metadata currently available.
Expand Down
Loading