5151use OCP \FilesMetadata \IMetadataQuery ;
5252use OCP \FilesMetadata \Model \IFilesMetadata ;
5353use OCP \FilesMetadata \Model \IMetadataValueWrapper ;
54- use OCP \IConfig ;
55- use OCP \IDBConnection ;
54+ use OCP \IAppConfig ;
5655use Psr \Log \LoggerInterface ;
5756
5857/**
@@ -69,7 +68,7 @@ class FilesMetadataManager implements IFilesMetadataManager {
6968 public function __construct (
7069 private IEventDispatcher $ eventDispatcher ,
7170 private IJobList $ jobList ,
72- private IConfig $ config ,
71+ private IAppConfig $ appConfig ,
7372 private LoggerInterface $ logger ,
7473 private MetadataRequestService $ metadataRequestService ,
7574 private IndexRequestService $ indexRequestService ,
@@ -206,7 +205,7 @@ public function saveMetadata(IFilesMetadata $filesMetadata): void {
206205 // update metadata types list
207206 $ current = $ this ->getKnownMetadata ();
208207 $ current ->import ($ filesMetadata ->jsonSerialize (true ));
209- $ this ->config -> setAppValue ('core ' , self ::CONFIG_KEY , json_encode ( $ current) );
208+ $ this ->appConfig -> setValueArray ('core ' , self ::CONFIG_KEY , $ current-> jsonSerialize (), lazy: true );
210209 }
211210
212211 /**
@@ -235,20 +234,16 @@ public function deleteMetadata(int $fileId): void {
235234 * @param string $fileIdField alias of the field that contains file ids
236235 *
237236 * @inheritDoc
238- * @return IMetadataQuery|null
237+ * @return IMetadataQuery
239238 * @see IMetadataQuery
240239 * @since 28.0.0
241240 */
242241 public function getMetadataQuery (
243242 IQueryBuilder $ qb ,
244243 string $ fileTableAlias ,
245244 string $ fileIdField
246- ): ?IMetadataQuery {
247- if (!$ this ->metadataInitiated ()) {
248- return null ;
249- }
250-
251- return new MetadataQuery ($ qb , $ this ->getKnownMetadata (), $ fileTableAlias , $ fileIdField );
245+ ): IMetadataQuery {
246+ return new MetadataQuery ($ qb , $ this , $ fileTableAlias , $ fileIdField );
252247 }
253248
254249 /**
@@ -263,8 +258,7 @@ public function getKnownMetadata(): IFilesMetadata {
263258 $ this ->all = new FilesMetadata ();
264259
265260 try {
266- $ data = json_decode ($ this ->config ->getAppValue ('core ' , self ::CONFIG_KEY , '[] ' ), true , 127 , JSON_THROW_ON_ERROR );
267- $ this ->all ->import ($ data );
261+ $ this ->all ->import ($ this ->appConfig ->getValueArray ('core ' , self ::CONFIG_KEY , lazy: true ));
268262 } catch (JsonException ) {
269263 $ this ->logger ->warning ('issue while reading stored list of metadata. Advised to run ./occ files:scan --all --generate-metadata ' );
270264 }
@@ -310,7 +304,7 @@ public function initMetadata(
310304 }
311305
312306 $ current ->import ([$ key => ['type ' => $ type , 'indexed ' => $ indexed , 'editPermission ' => $ editPermission ]]);
313- $ this ->config -> setAppValue ('core ' , self ::CONFIG_KEY , json_encode ( $ current) );
307+ $ this ->appConfig -> setValueArray ('core ' , self ::CONFIG_KEY , $ current-> jsonSerialize (), lazy: true );
314308 $ this ->all = $ current ;
315309 }
316310
@@ -323,26 +317,4 @@ public static function loadListeners(IEventDispatcher $eventDispatcher): void {
323317 $ eventDispatcher ->addServiceListener (NodeWrittenEvent::class, MetadataUpdate::class);
324318 $ eventDispatcher ->addServiceListener (CacheEntryRemovedEvent::class, MetadataDelete::class);
325319 }
326-
327- /**
328- * Will confirm that tables were created and store an app value to cache the result.
329- * Can be removed in 29 as this is to avoid strange situation when Nextcloud files were
330- * replaced but the upgrade was not triggered yet.
331- *
332- * @return bool
333- */
334- private function metadataInitiated (): bool {
335- if ($ this ->config ->getAppValue ('core ' , self ::MIGRATION_DONE , '0 ' ) === '1 ' ) {
336- return true ;
337- }
338-
339- $ dbConnection = \OCP \Server::get (IDBConnection::class);
340- if ($ dbConnection ->tableExists (MetadataRequestService::TABLE_METADATA )) {
341- $ this ->config ->setAppValue ('core ' , self ::MIGRATION_DONE , '1 ' );
342-
343- return true ;
344- }
345-
346- return false ;
347- }
348320}
0 commit comments