feat: entity patch
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1017,6 +1017,21 @@ class Manager {
|
||||
return $responseData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes entities
|
||||
*
|
||||
* @since 2026.04.01
|
||||
*
|
||||
* @param string $tenantId Tenant identifier
|
||||
* @param string|null $userId User identifier for context
|
||||
* @param ResourceIdentifiers $sources Source entities to delete
|
||||
*
|
||||
* @return array<string, array{
|
||||
* disposition: 'moved'|'deleted'|'error',
|
||||
* destination: ?CollectionIdentifier,
|
||||
* mutation: EntityIdentifier
|
||||
* }> Results keyed by source entity identifier
|
||||
*/
|
||||
public function entityDelete(string $tenantId, string $userId, ResourceIdentifiers $sources): array {
|
||||
$operationOutcome = [];
|
||||
|
||||
@@ -1066,6 +1081,90 @@ class Manager {
|
||||
return $operationOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches entities
|
||||
*
|
||||
* @since 2026.04.01
|
||||
*
|
||||
* @param string $tenantId Tenant identifier
|
||||
* @param string|null $userId User identifier for context
|
||||
* @param ResourceIdentifiers $sources Source entities to patch
|
||||
* @param array $patchData Data to patch
|
||||
*
|
||||
* @return array<string, array{
|
||||
* disposition: 'patched'|'error',
|
||||
* error?: string
|
||||
* }> Results keyed by source entity identifier
|
||||
*/
|
||||
public function entityPatch(string $tenantId, string $userId, ResourceIdentifiers $targets, array $patch): array {
|
||||
$operationOutcome = [];
|
||||
|
||||
// Process targets grouped by provider and service to minimize redundant fetches and operations
|
||||
foreach ($targets->providers() as $providerName) {
|
||||
$providerTargets = $targets->byProvider($providerName);
|
||||
$provider = $this->providerFetch($tenantId, $userId, $providerName);
|
||||
|
||||
// If provider is not found, mark all identifiers as failed and continue to next provider
|
||||
if ($provider === null) {
|
||||
foreach ($providerTargets->services() as $serviceName) {
|
||||
$serviceTargets = $providerTargets->byService($serviceName);
|
||||
foreach ($serviceTargets as $identifier) {
|
||||
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'provider not found'];
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($providerTargets->services() as $serviceName) {
|
||||
$serviceTargets = $providerTargets->byService($serviceName);
|
||||
$service = $this->serviceFetch($tenantId, $userId, $providerName, $serviceName);
|
||||
// If service is not found, mark all identifiers as failed and continue to next service
|
||||
if ($service === null) {
|
||||
foreach ($serviceTargets as $identifier) {
|
||||
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'service not found'];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// If service does not support entity mutation, mark all identifiers as failed and continue to next service
|
||||
if (!($service instanceof ServiceEntityMutableInterface)) {
|
||||
foreach ($serviceTargets as $identifier) {
|
||||
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'entity mutations not supported'];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// If service does not support entity patching, mark all identifiers as failed and continue to next service
|
||||
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_PATCH)) {
|
||||
foreach ($serviceTargets as $identifier) {
|
||||
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'entity patching not supported'];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties = $service->entityFresh()->getProperties()->jsonDeserialize($patch);
|
||||
|
||||
return $service->entityPatch(...$serviceTargets->all(), patch: $patch);
|
||||
}
|
||||
}
|
||||
|
||||
return $operationOutcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves entities to another collection
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param string $tenantId Tenant identifier
|
||||
* @param string|null $userId User identifier for context
|
||||
* @param CollectionIdentifier $target Target collection identifier
|
||||
* @param ResourceIdentifiers $sources Source entities to move
|
||||
*
|
||||
* @return array<string, array{
|
||||
* disposition: 'moved'|'error',
|
||||
* destination: ?CollectionIdentifier,
|
||||
* mutation: EntityIdentifier
|
||||
* }> Results keyed by source entity identifier
|
||||
*/
|
||||
public function entityMove(string $tenantId, string $userId, CollectionIdentifier $target, ResourceIdentifiers $sources): array {
|
||||
|
||||
$targetService = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());
|
||||
|
||||
Reference in New Issue
Block a user