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

+files_metadata_installed #42019

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
28 changes: 26 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use OCP\FilesMetadata\Model\IFilesMetadata;
use OCP\FilesMetadata\Model\IMetadataValueWrapper;
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -60,6 +61,7 @@
*/
class FilesMetadataManager implements IFilesMetadataManager {
public const CONFIG_KEY = 'files_metadata';
public const MIGRATION_DONE = 'files_metadata_installed';
private const JSON_MAXSIZE = 100000;

private ?IFilesMetadata $all = null;
Expand Down Expand Up @@ -241,10 +243,10 @@ public function getMetadataQuery(
string $fileTableAlias,
string $fileIdField
): ?IMetadataQuery {
// we don't want to join metadata table if never filled
if ($this->config->getAppValue('core', self::CONFIG_KEY, '') === '') {
if (!$this->metadataInitiated()) {
return null;
}

return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField);
}

Expand Down Expand Up @@ -320,4 +322,26 @@ public static function loadListeners(IEventDispatcher $eventDispatcher): void {
$eventDispatcher->addServiceListener(NodeWrittenEvent::class, MetadataUpdate::class);
$eventDispatcher->addServiceListener(CacheEntryRemovedEvent::class, MetadataDelete::class);
}

/**
* Will confirm that tables were created and store an app value to cache the result.
* Can be removed in 29 as this is to avoid strange situation when Nextcloud files were
* replaced but the upgrade was not triggered yet.
*
* @return bool
*/
private function metadataInitiated(): bool {
if ($this->config->getAppValue('core', self::MIGRATION_DONE, '0') === '1') {
return true;
}

$dbConnection = \OCP\Server::get(IDBConnection::class);
if ($dbConnection->tableExists(MetadataRequestService::TABLE_METADATA)) {
$this->config->setAppValue('core', self::MIGRATION_DONE, '1');

return true;
}

return false;
}
}
Loading