|
52 | 52 | use OCP\FilesMetadata\Model\IFilesMetadata; |
53 | 53 | use OCP\FilesMetadata\Model\IMetadataValueWrapper; |
54 | 54 | use OCP\IConfig; |
| 55 | +use OCP\IDBConnection; |
55 | 56 | use Psr\Log\LoggerInterface; |
56 | 57 |
|
57 | 58 | /** |
|
60 | 61 | */ |
61 | 62 | class FilesMetadataManager implements IFilesMetadataManager { |
62 | 63 | public const CONFIG_KEY = 'files_metadata'; |
| 64 | + public const MIGRATION_DONE = 'files_metadata_installed'; |
63 | 65 | private const JSON_MAXSIZE = 100000; |
64 | 66 |
|
65 | 67 | private ?IFilesMetadata $all = null; |
@@ -241,10 +243,10 @@ public function getMetadataQuery( |
241 | 243 | string $fileTableAlias, |
242 | 244 | string $fileIdField |
243 | 245 | ): ?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()) { |
246 | 247 | return null; |
247 | 248 | } |
| 249 | + |
248 | 250 | return new MetadataQuery($qb, $this->getKnownMetadata(), $fileTableAlias, $fileIdField); |
249 | 251 | } |
250 | 252 |
|
@@ -320,4 +322,26 @@ public static function loadListeners(IEventDispatcher $eventDispatcher): void { |
320 | 322 | $eventDispatcher->addServiceListener(NodeWrittenEvent::class, MetadataUpdate::class); |
321 | 323 | $eventDispatcher->addServiceListener(CacheEntryRemovedEvent::class, MetadataDelete::class); |
322 | 324 | } |
| 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 | + } |
323 | 347 | } |
0 commit comments