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