1
0

IFilesMetadata.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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\Model;
  25. use JsonSerializable;
  26. use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
  27. use OCP\FilesMetadata\Exceptions\FilesMetadataTypeException;
  28. /**
  29. * Model that represent metadata linked to a specific file.
  30. *
  31. * Example of json stored in the database
  32. * {
  33. * "mymeta": {
  34. * "value": "this is a test",
  35. * "type": "string",
  36. * "etag": "abcd1234",
  37. * "indexed": false,
  38. * "editPermission": 1
  39. * },
  40. * "myapp-anothermeta": {
  41. * "value": 42,
  42. * "type": "int",
  43. * "etag": "0987zyxw",
  44. * "indexed": true,
  45. * "editPermission": 0
  46. * }
  47. * }
  48. *
  49. * @see IMetadataValueWrapper
  50. * @since 28.0.0
  51. */
  52. interface IFilesMetadata extends JsonSerializable {
  53. /**
  54. * returns the file id linked to this metadata
  55. *
  56. * @return int related file id
  57. * @since 28.0.0
  58. */
  59. public function getFileId(): int;
  60. /**
  61. * returns last time metadata were updated in the database
  62. *
  63. * @return int timestamp
  64. * @since 28.0.0
  65. */
  66. public function lastUpdateTimestamp(): int;
  67. /**
  68. * returns the token known at the time the metadata were extracted from database
  69. *
  70. * @return string token
  71. * @since 28.0.0
  72. */
  73. public function getSyncToken(): string;
  74. /**
  75. * returns all current metadata keys
  76. *
  77. * @return string[] list of keys
  78. * @since 28.0.0
  79. */
  80. public function getKeys(): array;
  81. /**
  82. * returns true if search metadata key exists
  83. *
  84. * @param string $needle metadata key to search
  85. *
  86. * @return bool TRUE if key exist
  87. * @since 28.0.0
  88. */
  89. public function hasKey(string $needle): bool;
  90. /**
  91. * return the list of metadata keys set as indexed
  92. *
  93. * @return string[] list of indexes
  94. * @since 28.0.0
  95. */
  96. public function getIndexes(): array;
  97. /**
  98. * returns true if key exists and is set as indexed
  99. *
  100. * @param string $key metadata key
  101. *
  102. * @return bool
  103. * @since 28.0.0
  104. */
  105. public function isIndex(string $key): bool;
  106. /**
  107. * returns file etag stored during the last update of the metadata key
  108. *
  109. * @param string $key metadata key
  110. * @return string
  111. * @since 29.0.0
  112. */
  113. public function getEtag(string $key): string;
  114. /**
  115. * set file etag
  116. *
  117. * @param string $key metadata key
  118. * @since 29.0.0
  119. */
  120. public function setEtag(string $key, string $etag): void;
  121. /**
  122. * set remote edit permission
  123. * (Webdav PROPPATCH)
  124. *
  125. * @param string $key metadata key
  126. * @param int $permission remote edit permission
  127. *
  128. * @since 28.0.0
  129. */
  130. public function setEditPermission(string $key, int $permission): void;
  131. /**
  132. * returns remote edit permission
  133. * (Webdav PROPPATCH)
  134. *
  135. * @param string $key metadata key
  136. *
  137. * @return int
  138. * @since 28.0.0
  139. */
  140. public function getEditPermission(string $key): int;
  141. /**
  142. * returns string value for a metadata key
  143. *
  144. * @param string $key metadata key
  145. *
  146. * @return string metadata value
  147. * @throws FilesMetadataNotFoundException
  148. * @throws FilesMetadataTypeException
  149. * @since 28.0.0
  150. */
  151. public function getString(string $key): string;
  152. /**
  153. * returns int value for a metadata key
  154. *
  155. * @param string $key metadata key
  156. *
  157. * @return int metadata value
  158. * @throws FilesMetadataNotFoundException
  159. * @throws FilesMetadataTypeException
  160. * @since 28.0.0
  161. */
  162. public function getInt(string $key): int;
  163. /**
  164. * returns float value for a metadata key
  165. *
  166. * @param string $key metadata key
  167. *
  168. * @return float metadata value
  169. * @throws FilesMetadataNotFoundException
  170. * @throws FilesMetadataTypeException
  171. * @since 28.0.0
  172. */
  173. public function getFloat(string $key): float;
  174. /**
  175. * returns bool value for a metadata key
  176. *
  177. * @param string $key metadata key
  178. *
  179. * @return bool metadata value
  180. * @throws FilesMetadataNotFoundException
  181. * @throws FilesMetadataTypeException
  182. * @since 28.0.0
  183. */
  184. public function getBool(string $key): bool;
  185. /**
  186. * returns array for a metadata key
  187. *
  188. * @param string $key metadata key
  189. *
  190. * @return array metadata value
  191. * @throws FilesMetadataNotFoundException
  192. * @throws FilesMetadataTypeException
  193. * @since 28.0.0
  194. */
  195. public function getArray(string $key): array;
  196. /**
  197. * returns string[] value for a metadata key
  198. *
  199. * @param string $key metadata key
  200. *
  201. * @return string[] metadata value
  202. * @throws FilesMetadataNotFoundException
  203. * @throws FilesMetadataTypeException
  204. * @since 28.0.0
  205. */
  206. public function getStringList(string $key): array;
  207. /**
  208. * returns int[] value for a metadata key
  209. *
  210. * @param string $key metadata key
  211. *
  212. * @return int[] metadata value
  213. * @throws FilesMetadataNotFoundException
  214. * @throws FilesMetadataTypeException
  215. * @since 28.0.0
  216. */
  217. public function getIntList(string $key): array;
  218. /**
  219. * returns the value type of the metadata (string, int, ...)
  220. *
  221. * @param string $key metadata key
  222. *
  223. * @return string value type
  224. * @throws FilesMetadataNotFoundException
  225. * @see IMetadataValueWrapper::TYPE_STRING
  226. * @see IMetadataValueWrapper::TYPE_INT
  227. * @see IMetadataValueWrapper::TYPE_FLOAT
  228. * @see IMetadataValueWrapper::TYPE_BOOL
  229. * @see IMetadataValueWrapper::TYPE_ARRAY
  230. * @see IMetadataValueWrapper::TYPE_STRING_LIST
  231. * @see IMetadataValueWrapper::TYPE_INT_LIST
  232. * @since 28.0.0
  233. */
  234. public function getType(string $key): string;
  235. /**
  236. * set a metadata key/value pair for string value
  237. *
  238. * @param string $key metadata key
  239. * @param string $value metadata value
  240. * @param bool $index set TRUE if value must be indexed
  241. *
  242. * @return self
  243. * @since 28.0.0
  244. */
  245. public function setString(string $key, string $value, bool $index = false): self;
  246. /**
  247. * set a metadata key/value pair for int value
  248. *
  249. * @param string $key metadata key
  250. * @param int $value metadata value
  251. * @param bool $index set TRUE if value must be indexed
  252. *
  253. * @return self
  254. * @since 28.0.0
  255. */
  256. public function setInt(string $key, int $value, bool $index = false): self;
  257. /**
  258. * set a metadata key/value pair for float value
  259. *
  260. * @param string $key metadata key
  261. * @param float $value metadata value
  262. *
  263. * @return self
  264. * @since 28.0.0
  265. */
  266. public function setFloat(string $key, float $value): self;
  267. /**
  268. * set a metadata key/value pair for bool value
  269. *
  270. * @param string $key metadata key
  271. * @param bool $value metadata value
  272. * @param bool $index set TRUE if value must be indexed
  273. *
  274. * @return self
  275. * @since 28.0.0
  276. */
  277. public function setBool(string $key, bool $value, bool $index = false): self;
  278. /**
  279. * set a metadata key/value pair for array
  280. *
  281. * @param string $key metadata key
  282. * @param array $value metadata value
  283. *
  284. * @return self
  285. * @since 28.0.0
  286. */
  287. public function setArray(string $key, array $value): self;
  288. /**
  289. * set a metadata key/value pair for list of string
  290. *
  291. * @param string $key metadata key
  292. * @param string[] $value metadata value
  293. * @param bool $index set TRUE if each values from the list must be indexed
  294. *
  295. * @return self
  296. * @since 28.0.0
  297. */
  298. public function setStringList(string $key, array $value, bool $index = false): self;
  299. /**
  300. * set a metadata key/value pair for list of int
  301. *
  302. * @param string $key metadata key
  303. * @param int[] $value metadata value
  304. * @param bool $index set TRUE if each values from the list must be indexed
  305. *
  306. * @return self
  307. * @since 28.0.0
  308. */
  309. public function setIntList(string $key, array $value, bool $index = false): self;
  310. /**
  311. * unset a metadata
  312. *
  313. * @param string $key metadata key
  314. *
  315. * @return self
  316. * @since 28.0.0
  317. */
  318. public function unset(string $key): self;
  319. /**
  320. * unset metadata with key starting with prefix
  321. *
  322. * @param string $keyPrefix metadata key prefix
  323. *
  324. * @return self
  325. * @since 28.0.0
  326. */
  327. public function removeStartsWith(string $keyPrefix): self;
  328. /**
  329. * returns true if object have been updated since last import
  330. *
  331. * @return bool TRUE if metadata have been modified
  332. * @since 28.0.0
  333. */
  334. public function updated(): bool;
  335. /**
  336. * returns metadata in a simple array with METADATA_KEY => METADATA_VALUE
  337. *
  338. * @return array metadata
  339. * @since 28.0.0
  340. */
  341. public function asArray(): array;
  342. /**
  343. * deserialize the object from a json
  344. *
  345. * @param array $data serialized version of the object
  346. *
  347. * @return self
  348. * @see jsonSerialize
  349. * @since 28.0.0
  350. */
  351. public function import(array $data): self;
  352. }