feat: collection move
Some checks failed
JS Unit Tests / test (pull_request) Failing after 26s
Build Test / test (pull_request) Successful in 32s
PHP Unit Tests / test (pull_request) Successful in 53s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-06 12:03:05 -04:00
parent 9b6823c481
commit fbc8ac2d7e
5 changed files with 117 additions and 11 deletions

View File

@@ -152,7 +152,7 @@ class DefaultController extends ControllerAbstract {
'collection.update' => $this->collectionUpdate($tenantId, $userId, $data),
'collection.delete' => $this->collectionDelete($tenantId, $userId, $data),
'collection.delta' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'collection.move' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'collection.move' => $this->collectionMove($tenantId, $userId, $data),
// Entity operations
'entity.list' => $this->entityList($tenantId, $userId, $data),
@@ -581,11 +581,11 @@ class DefaultController extends ControllerAbstract {
if (!is_string($data['target'])) {
throw new InvalidArgumentException(self::ERR_INVALID_TARGET);
}
if (!isset($data['sources'])) {
throw new InvalidArgumentException(self::ERR_MISSING_SOURCES);
if (!isset($data['source'])) {
throw new InvalidArgumentException(self::ERR_MISSING_SOURCE);
}
if (!is_array($data['sources'])) {
throw new InvalidArgumentException(self::ERR_INVALID_SOURCES);
if (!is_string($data['source'])) {
throw new InvalidArgumentException(self::ERR_INVALID_SOURCE);
}
$target = ResourceIdentifier::fromString($data['target']);
@@ -593,9 +593,10 @@ class DefaultController extends ControllerAbstract {
throw new InvalidArgumentException('Invalid parameter: target must be provider:service:collection');
}
$source = ResourceIdentifier::fromArray($data['source']);
$source = ResourceIdentifier::fromString($data['source']);
if (!$source instanceof CollectionIdentifier) {
throw new InvalidArgumentException('Invalid parameter: sources must contain provider:service:collection identifiers');
throw new InvalidArgumentException('Invalid parameter: source must be provider:service:collection');
}
return $this->mailManager->collectionMove($tenantId, $userId, $target, $source);

View File

@@ -671,6 +671,42 @@ class Manager {
return $service->collectionDelete($collectionId, $force);
}
/**
* Move a specific collection to a new parent collection
*
* @since 2025.05.01
*
* @param string $tenantId Tenant identifier
* @param string|null $userId User identifier for context
* @param CollectionIdentifier $target Target collection identifier (new parent)
* @param CollectionIdentifier $source Source collection identifier (collection to move)
*
* @return CollectionBaseInterface Moved collection
*/
public function collectionMove(string $tenantId, ?string $userId, CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface {
// validate that source and target are the same provider and service
if ($source->provider() !== $target->provider() || $source->service() !== $target->service()) {
throw new InvalidArgumentException("Source and target collections must belong to the same provider and service");
}
// Validate that source and target are not the same
if ($source->collection() === $target->collection()) {
throw new InvalidArgumentException("Source and target collections are the same");
}
// retrieve service
$service = $this->serviceFetch($tenantId, $userId, $source->provider(), $source->service());
// Check if service supports collection move
if (!($service instanceof ServiceCollectionMutableInterface)) {
throw new InvalidArgumentException("Service does not support collection mutations");
}
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_MOVE)) {
throw new InvalidArgumentException("Service is not capable of moving collections");
}
// move collection
return $service->collectionMove($source->collection(), $target->collection());
}
// ==================== Message Operations ====================
/**