Skip to content

Commit

Permalink
ignore metadata if migration to 28 is not done
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 13, 2023
1 parent 3e0f5ea commit 911e039
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
7 changes: 7 additions & 0 deletions core/Migrations/Version28000Date20231004103301.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
return null;
}

/**
* We need to tell FilesMetadataManager that the migration is done
* and successful, so it can start joining the metadata table
*/
$config = \OCP\Server::get(\OCP\IConfig::class);
$config->setAppValue('core', \OC\FilesMetadata\FilesMetadataManager::CONFIG_KEY, '[]');

return $schema;
}
}
2 changes: 1 addition & 1 deletion 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
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public function whereParentInParameter(string $parameter) {
return $this;
}

public function selectMetadata(): IMetadataQuery {
public function selectMetadata(): ?IMetadataQuery {
$metadataQuery = $this->filesMetadataManager->getMetadataQuery($this, $this->alias, 'fileid');
$metadataQuery->retrieveMetadata();
$metadataQuery?->retrieveMetadata();
return $metadataQuery;
}
}
11 changes: 9 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,22 @@ public function deleteMetadata(int $fileId): void {
* @param string $fileIdField alias of the field that contains file ids
*
* @inheritDoc
* @return IMetadataQuery
* @return IMetadataQuery|null
* @see IMetadataQuery
* @since 28.0.0
*/
public function getMetadataQuery(
IQueryBuilder $qb,
string $fileTableAlias,
string $fileIdField
): IMetadataQuery {
): ?IMetadataQuery {
/**
* during the upgrade to 28, and before the migration is trigered, we
* need to not join metadata table as it does not exist yet.
*/
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 @@ -106,15 +106,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
* @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

0 comments on commit 911e039

Please sign in to comment.