Skip to content

Commit 4346933

Browse files
committed
+files_metadata_installed
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 0f459ff commit 4346933

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

lib/private/FilesMetadata/FilesMetadataManager.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\FilesMetadata\Model\IFilesMetadata;
5353
use OCP\FilesMetadata\Model\IMetadataValueWrapper;
5454
use OCP\IConfig;
55+
use OCP\IDBConnection;
5556
use Psr\Log\LoggerInterface;
5657

5758
/**
@@ -60,6 +61,7 @@
6061
*/
6162
class FilesMetadataManager implements IFilesMetadataManager {
6263
public const CONFIG_KEY = 'files_metadata';
64+
public const MIGRATION_DONE = 'files_metadata_installed';
6365
private const JSON_MAXSIZE = 100000;
6466

6567
private ?IFilesMetadata $all = null;
@@ -241,10 +243,10 @@ public function getMetadataQuery(
241243
string $fileTableAlias,
242244
string $fileIdField
243245
): ?IMetadataQuery {
244-
// we don't want to join metadata table if never filled
245-
if ($this->config->getAppValue('core', self::CONFIG_KEY, '') === '') {
246+
if (!$this->metadataInitiated()) {
246247
return null;
247248
}
249+
248250
return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField);
249251
}
250252

@@ -320,4 +322,26 @@ public static function loadListeners(IEventDispatcher $eventDispatcher): void {
320322
$eventDispatcher->addServiceListener(NodeWrittenEvent::class, MetadataUpdate::class);
321323
$eventDispatcher->addServiceListener(CacheEntryRemovedEvent::class, MetadataDelete::class);
322324
}
325+
326+
/**
327+
* Will confirm that tables were created and store an app value to cache the result.
328+
* Can be removed in 29 as this is to avoid strange situation when Nextcloud files were
329+
* replaced but the upgrade was not triggered yet.
330+
*
331+
* @return bool
332+
*/
333+
private function metadataInitiated(): bool {
334+
if ($this->config->getAppValue('core', self::MIGRATION_DONE, '0') === '1') {
335+
return true;
336+
}
337+
338+
$dbConnection = \OCP\Server::get(IDBConnection::class);
339+
if ($dbConnection->tableExists(MetadataRequestService::TABLE_METADATA)) {
340+
$this->config->setAppValue('core', self::MIGRATION_DONE, '1');
341+
342+
return true;
343+
}
344+
345+
return false;
346+
}
323347
}

0 commit comments

Comments
 (0)