Skip to content

Commit

Permalink
Support setting metadata in PROPPATCH requests
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Oct 19, 2023
1 parent 8579aa3 commit ca2e7e3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
namespace OCA\DAV\Connector\Sabre;

use OC\AppFramework\Http\Request;
use OC\FilesMetadata\Model\MetadataValueWrapper;
use OCP\Constants;
use OCP\Files\ForbiddenException;
use OCP\Files\StorageNotAvailableException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\IPreview;
use OCP\IRequest;
Expand Down Expand Up @@ -516,6 +518,48 @@ public function handleUpdateProperties($path, PropPatch $propPatch) {
$node->setCreationTime((int) $time);
return true;
});

foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
$propPatch->handle(self::FILE_METADATA_PREFIX.$metadataKey, function (mixed $value) use ($metadataValue) {
switch ($metadataValue->getType()) {
case MetadataValueWrapper::TYPE_STRING:
$metadataValue->setValueString($value);
break;
case MetadataValueWrapper::TYPE_INT:
$metadataValue->setValueInt($value);
break;
case MetadataValueWrapper::TYPE_FLOAT:
$metadataValue->setValueFloat($value);
break;
case MetadataValueWrapper::TYPE_BOOL:
$metadataValue->setValueBool($value);
break;
case MetadataValueWrapper::TYPE_ARRAY:
$metadataValue->setValueArray($value);
break;
case MetadataValueWrapper::TYPE_STRING_LIST:
$metadataValue->setValueStringList($value);
break;
case MetadataValueWrapper::TYPE_INT_LIST:
$metadataValue->setValueIntList($value);
break;
}

$filesMetadataManager = \OCP\Server::get(IFilesMetadataManager::class);
// TODO: $filesMetadataManager->saveMetadata();
return true;
});
}

foreach ($propPatch->getRemainingMutations() as $mutation) {
if (!str_starts_with($mutation, self::FILE_METADATA_PREFIX)) {
continue;
}

$metadataKey = substr($mutation, strlen(self::FILE_METADATA_PREFIX));
// TODO: $node->getFileInfo()->getMetadata()->createNewMetadata()
}

/**
* Disable modification of the displayname property for files and
* folders via PROPPATCH. See PROPFIND for more information.
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
namespace OCP\Files;

use OC\FilesMetadata\Model\MetadataValueWrapper;
use OCP\Files\Storage\IStorage;

/**
Expand Down Expand Up @@ -312,7 +313,7 @@ public function getParentId(): int;
/**
* Get the metadata, if available
*
* @return array
* @return MetadataValueWrapper[]
* @since 28.0.0
*/
public function getMetadata(): array;
Expand Down

0 comments on commit ca2e7e3

Please sign in to comment.