generated from Nodarx/template
Compare commits
3 Commits
c6935c47e3
...
ca646eec3c
| Author | SHA1 | Date | |
|---|---|---|---|
| ca646eec3c | |||
| b37da945f5 | |||
| 086d7a1366 |
@@ -17,6 +17,7 @@ use KTXF\Mail\Object\Address;
|
||||
use KTXF\Mail\Object\AddressInterface;
|
||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntityMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceConfigurableInterface;
|
||||
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||
@@ -605,10 +606,10 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
throw new \RuntimeException('Entity modification is not supported in this service');
|
||||
}
|
||||
|
||||
public function entityDelete(EntityIdentifier ...$identifiers): array
|
||||
public function entityDelete(EntityIdentifier ...$targets): array
|
||||
{
|
||||
// validate identifiers and group by collection
|
||||
$identifiers = $this->groupEntitiesByCollection(...$identifiers);
|
||||
$targets = $this->groupEntitiesByCollection(...$targets);
|
||||
|
||||
// determine delete mode and target collection (e.g. Trash) if applicable
|
||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||
@@ -645,7 +646,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
// entities need to be moved or deleted by collection
|
||||
$list = [];
|
||||
foreach ($identifiers as $sourceCollection => $sourceEntities) {
|
||||
foreach ($targets as $sourceCollection => $sourceEntities) {
|
||||
if ($deleteMode === 'soft' && $sourceCollection === $deleteTargetNative) {
|
||||
continue;
|
||||
}
|
||||
@@ -675,7 +676,30 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
throw new \RuntimeException('Entity patching is not supported in this service');
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array
|
||||
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
|
||||
{
|
||||
// validate identifiers and group by collection
|
||||
$targets = $this->groupEntitiesByCollection(...$targets);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach ($targets as $targetCollection => $targetIdentifiers) {
|
||||
$uids = array_keys($targetIdentifiers);
|
||||
|
||||
$mutations = $this->mailService->entityPatch($targetCollection, $properties, ...$uids);
|
||||
|
||||
foreach ($uids as $uid) {
|
||||
$list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched'];
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityCopy(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
{
|
||||
// validate target belongs to this service
|
||||
if ($target->provider() !== $this->provider() || $target->service() !== $this->identifier()) {
|
||||
@@ -683,12 +707,47 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
}
|
||||
|
||||
// validate identifiers and group by collection
|
||||
$identifiers = $this->groupEntitiesByCollection(...$identifiers);
|
||||
$sources = $this->groupEntitiesByCollection(...$sources);
|
||||
|
||||
// copy entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach ($sources as $sourceCollection => $sourceEntities) {
|
||||
$uids = array_keys($sourceEntities);
|
||||
|
||||
$mutations = $this->mailService->entityCopy($target->collection(), $sourceCollection, ...$uids);
|
||||
|
||||
foreach ($uids as $uid) {
|
||||
$mutatedUid = $mutations[$uid] ?? null;
|
||||
$list[(string)$sourceEntities[$uid]] = [
|
||||
'disposition' => $mutatedUid !== null ? 'copied' : 'error',
|
||||
'destination' => $target,
|
||||
'mutation' => $mutatedUid !== null ? new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $mutatedUid) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
{
|
||||
// validate target belongs to this service
|
||||
if ($target->provider() !== $this->provider() || $target->service() !== $this->identifier()) {
|
||||
throw new \InvalidArgumentException('Target collection does not belong to this service: ' . $target);
|
||||
}
|
||||
|
||||
// validate identifiers and group by collection
|
||||
$sources = $this->groupEntitiesByCollection(...$sources);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$list = [];
|
||||
foreach ($identifiers as $sourceCollection => $sourceEntities) {
|
||||
|
||||
foreach ($sources as $sourceCollection => $sourceEntities) {
|
||||
$uids = array_keys($sourceEntities);
|
||||
|
||||
$mutations = $this->mailService->entityMove($target->collection(), $sourceCollection, ...$uids);
|
||||
|
||||
@@ -59,8 +59,6 @@ class RemoteMailService
|
||||
|
||||
public function __construct(
|
||||
private readonly Client $client,
|
||||
private readonly string $provider,
|
||||
private readonly string|int $service,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -347,6 +345,31 @@ class RemoteMailService
|
||||
return array_fill_keys($uids, true);
|
||||
}
|
||||
|
||||
public function entityPatch(string $collection, array $flagsToAdd = [], array $flagsToRemove = [], int ...$uids): void
|
||||
{
|
||||
if (empty($uids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->client->perform(new SelectCommand($collection, false));
|
||||
|
||||
if (!empty($flagsToAdd)) {
|
||||
$this->client->perform(new StoreCommand(
|
||||
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
|
||||
$flagsToAdd,
|
||||
'+',
|
||||
));
|
||||
}
|
||||
|
||||
if (!empty($flagsToRemove)) {
|
||||
$this->client->perform(new StoreCommand(
|
||||
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
|
||||
$flagsToRemove,
|
||||
'-',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function entityMove(string $targetCollection, string $sourceCollection, int ...$uids): array
|
||||
{
|
||||
if (empty($uids)) {
|
||||
|
||||
Reference in New Issue
Block a user