IFilesMetadataManager.php 5.4 KB

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