|
34 | 34 | namespace OCA\DAV\Connector\Sabre; |
35 | 35 |
|
36 | 36 | use OC\AppFramework\Http\Request; |
| 37 | +use OC\FilesMetadata\Model\MetadataValueWrapper; |
37 | 38 | use OCP\Constants; |
38 | 39 | use OCP\Files\ForbiddenException; |
39 | 40 | use OCP\Files\StorageNotAvailableException; |
| 41 | +use OCP\FilesMetadata\IFilesMetadataManager; |
40 | 42 | use OCP\IConfig; |
41 | 43 | use OCP\IPreview; |
42 | 44 | use OCP\IRequest; |
@@ -516,6 +518,57 @@ public function handleUpdateProperties($path, PropPatch $propPatch) { |
516 | 518 | $node->setCreationTime((int) $time); |
517 | 519 | return true; |
518 | 520 | }); |
| 521 | + |
| 522 | + |
| 523 | + /** @var IFilesMetadataManager */ |
| 524 | + $filesMetadataManager = \OCP\Server::get(IFilesMetadataManager::class); |
| 525 | + $metadata = $filesMetadataManager->getMetadata((int)$node->getFileId()); |
| 526 | + |
| 527 | + foreach ($metadata->getKeys() as $metadataKey) { |
| 528 | + $propPatch->handle(self::FILE_METADATA_PREFIX.$metadataKey, function (mixed $value) use ($metadata, $metadataKey, $filesMetadataManager) { |
| 529 | + switch ($metadata->getType($metadataKey)) { |
| 530 | + case MetadataValueWrapper::TYPE_STRING: |
| 531 | + $metadata->set($metadataKey, $value); |
| 532 | + break; |
| 533 | + case MetadataValueWrapper::TYPE_INT: |
| 534 | + $metadata->setInt($metadataKey, $value); |
| 535 | + break; |
| 536 | + case MetadataValueWrapper::TYPE_FLOAT: |
| 537 | + $metadata->setFloat($metadataKey, $value); |
| 538 | + break; |
| 539 | + case MetadataValueWrapper::TYPE_BOOL: |
| 540 | + $metadata->setBool($metadataKey, $value); |
| 541 | + break; |
| 542 | + case MetadataValueWrapper::TYPE_ARRAY: |
| 543 | + $metadata->setArray($metadataKey, $value); |
| 544 | + break; |
| 545 | + case MetadataValueWrapper::TYPE_STRING_LIST: |
| 546 | + $metadata->setStringList($metadataKey, $value); |
| 547 | + break; |
| 548 | + case MetadataValueWrapper::TYPE_INT_LIST: |
| 549 | + $metadata->setIntList($metadataKey, $value); |
| 550 | + break; |
| 551 | + } |
| 552 | + |
| 553 | + $filesMetadataManager->saveMetadata($metadata); |
| 554 | + return true; |
| 555 | + }); |
| 556 | + } |
| 557 | + |
| 558 | + foreach ($propPatch->getRemainingMutations() as $mutation) { |
| 559 | + if (!str_starts_with($mutation, self::FILE_METADATA_PREFIX)) { |
| 560 | + continue; |
| 561 | + } |
| 562 | + |
| 563 | + $propPatch->handle($mutation, function (string $value) use ($metadata, $mutation, $filesMetadataManager) { |
| 564 | + $metadataKey = substr($mutation, strlen(self::FILE_METADATA_PREFIX)); |
| 565 | + $metadata->set($metadataKey, $value); |
| 566 | + $filesMetadataManager->saveMetadata($metadata); |
| 567 | + return true; |
| 568 | + }); |
| 569 | + } |
| 570 | + |
| 571 | + |
519 | 572 | /** |
520 | 573 | * Disable modification of the displayname property for files and |
521 | 574 | * folders via PROPPATCH. See PROPFIND for more information. |
|
0 commit comments