1
0

IFilesMetadataManager.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\FilesMetadata;
  8. use OCP\DB\QueryBuilder\IQueryBuilder;
  9. use OCP\Files\Node;
  10. use OCP\FilesMetadata\Exceptions\FilesMetadataException;
  11. use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
  12. use OCP\FilesMetadata\Model\IFilesMetadata;
  13. use OCP\FilesMetadata\Model\IMetadataValueWrapper;
  14. /**
  15. * Manager for FilesMetadata; manage files' metadata.
  16. *
  17. * @since 28.0.0
  18. */
  19. interface IFilesMetadataManager {
  20. /** @since 28.0.0 */
  21. public const PROCESS_LIVE = 1;
  22. /** @since 28.0.0 */
  23. public const PROCESS_BACKGROUND = 2;
  24. /** @since 28.0.0 */
  25. public const PROCESS_NAMED = 4;
  26. /**
  27. * initiate the process of refreshing the metadata in relation to a node
  28. * usually, this process:
  29. * - get current metadata from database, if available, or create a new one
  30. * - dispatch a MetadataLiveEvent,
  31. * - save new metadata in database, if metadata have been changed during the event
  32. * - refresh metadata indexes if needed,
  33. * - prep a new cronjob if an app request it during the event,
  34. *
  35. * @param Node $node related node
  36. * @param int $process type of process
  37. * @param string $namedEvent limit process to a named event
  38. *
  39. * @return IFilesMetadata
  40. * @see self::PROCESS_BACKGROUND
  41. * @see self::PROCESS_LIVE
  42. * @see self::PROCESS_NAMED
  43. * @since 28.0.0
  44. */
  45. public function refreshMetadata(
  46. Node $node,
  47. int $process = self::PROCESS_LIVE,
  48. string $namedEvent = '',
  49. ): IFilesMetadata;
  50. /**
  51. * returns metadata of a file id
  52. *
  53. * @param int $fileId file id
  54. * @param boolean $generate Generate if metadata does not exist
  55. *
  56. * @return IFilesMetadata
  57. * @throws FilesMetadataNotFoundException if not found
  58. * @since 28.0.0
  59. */
  60. public function getMetadata(int $fileId, bool $generate = false): IFilesMetadata;
  61. /**
  62. * returns metadata of multiple file ids
  63. *
  64. * @param int[] $fileIds file ids
  65. *
  66. * @return array File ID is the array key, files without metadata are not returned in the array
  67. * @psalm-return array<int, IFilesMetadata>
  68. * @since 28.0.0
  69. */
  70. public function getMetadataForFiles(array $fileIds): array;
  71. /**
  72. * save metadata to database and refresh indexes.
  73. * metadata are saved if new data are available.
  74. * on update, a check on syncToken is done to avoid conflict (race condition)
  75. *
  76. * @param IFilesMetadata $filesMetadata
  77. *
  78. * @throws FilesMetadataException if metadata seems malformed
  79. * @since 28.0.0
  80. */
  81. public function saveMetadata(IFilesMetadata $filesMetadata): void;
  82. /**
  83. * delete metadata and its indexes
  84. *
  85. * @param int $fileId file id
  86. *
  87. * @return void
  88. * @since 28.0.0
  89. */
  90. public function deleteMetadata(int $fileId): void;
  91. /**
  92. * generate and return a MetadataQuery to help building sql queries
  93. *
  94. * @param IQueryBuilder $qb
  95. * @param string $fileTableAlias alias of the table that contains data about files
  96. * @param string $fileIdField alias of the field that contains file ids
  97. *
  98. * @return IMetadataQuery
  99. * @see IMetadataQuery
  100. * @since 28.0.0
  101. */
  102. public function getMetadataQuery(
  103. IQueryBuilder $qb,
  104. string $fileTableAlias,
  105. string $fileIdField,
  106. ): IMetadataQuery;
  107. /**
  108. * returns all type of metadata currently available.
  109. * The list is stored in a IFilesMetadata with null values but correct type.
  110. *
  111. * Note: this method loads lazy appconfig values.
  112. *
  113. * @return IFilesMetadata
  114. * @since 28.0.0
  115. */
  116. public function getKnownMetadata(): IFilesMetadata;
  117. /**
  118. * Initiate a metadata key with its type.
  119. *
  120. * The call is mandatory before using the metadata property in a webdav request.
  121. * The call should be part of a migration/repair step and not be called on app's boot
  122. * process as it is using lazy-appconfig value
  123. *
  124. * Note: this method loads lazy appconfig values.
  125. *
  126. * @param string $key metadata key
  127. * @param string $type metadata type
  128. * @param bool $indexed TRUE if metadata can be search
  129. * @param int $editPermission remote edit permission via Webdav PROPPATCH
  130. *
  131. * @see IMetadataValueWrapper::TYPE_INT
  132. * @see IMetadataValueWrapper::TYPE_FLOAT
  133. * @see IMetadataValueWrapper::TYPE_BOOL
  134. * @see IMetadataValueWrapper::TYPE_ARRAY
  135. * @see IMetadataValueWrapper::TYPE_STRING_LIST
  136. * @see IMetadataValueWrapper::TYPE_INT_LIST
  137. * @see IMetadataValueWrapper::TYPE_STRING
  138. * @see IMetadataValueWrapper::EDIT_FORBIDDEN
  139. * @see IMetadataValueWrapper::EDIT_REQ_OWNERSHIP
  140. * @see IMetadataValueWrapper::EDIT_REQ_WRITE_PERMISSION
  141. * @see IMetadataValueWrapper::EDIT_REQ_READ_PERMISSION
  142. * @since 28.0.0
  143. * @since 29.0.0 uses lazy config value - do not use this method out of repair steps
  144. */
  145. public function initMetadata(string $key, string $type, bool $indexed, int $editPermission): void;
  146. }