feat: entity move
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -21,7 +21,12 @@ use KTXF\Mail\Queue\SendOptions;
|
||||
use KTXF\Mail\Service\IServiceSend;
|
||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntityMutableInterface;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||
use KTXF\Resource\Identifier\ResourceIdentifier;
|
||||
use KTXF\Resource\Identifier\ResourceIdentifiers;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
@@ -976,6 +981,56 @@ class Manager {
|
||||
return $responseData;
|
||||
}
|
||||
|
||||
public function entityMove(string $tenantId, string $userId, CollectionIdentifier $target, ResourceIdentifiers $sources): array {
|
||||
|
||||
$targetService = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());
|
||||
|
||||
// Check if service supports entity move
|
||||
if ($targetService instanceof ServiceEntityMutableInterface === false) {
|
||||
//return [];
|
||||
}
|
||||
|
||||
$operationOutcome = [];
|
||||
|
||||
$destinationSources = $sources->byProvider($targetService->provider())->byService((string)$targetService->identifier());
|
||||
if (!$destinationSources->isEmpty()) {
|
||||
$entitiesToMove = [];
|
||||
foreach ($destinationSources as $identifier) {
|
||||
$entitiesToMove[$identifier->collection()][] = $identifier->entity();
|
||||
}
|
||||
$operationResult = $targetService->entityMove($target->collection(), $entitiesToMove);
|
||||
|
||||
foreach ($destinationSources as $identifier) {
|
||||
$sourceIdentifier = (string)$identifier;
|
||||
$entityIdentifier = $identifier->entity();
|
||||
$result = $operationResult[$entityIdentifier] ?? null;
|
||||
|
||||
if ($result === true) {
|
||||
$operationOutcome[$sourceIdentifier] = [
|
||||
'success' => true,
|
||||
'identifier' => (string)new EntityIdentifier(
|
||||
$target->provider(),
|
||||
$target->service(),
|
||||
$target->collection(),
|
||||
$entityIdentifier,
|
||||
),
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$operationOutcome[$sourceIdentifier] = [
|
||||
'success' => false,
|
||||
'error' => is_string($result) && $result !== '' ? $result : 'unknownError',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Handle moving entities across different services/providers by fetching each entity and re-creating it in the target collection,
|
||||
// then deleting the original if the move is successful. This will require additional logic to handle potential failures and ensure data integrity.
|
||||
|
||||
return $operationOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a mail message
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user