generated from Nodarx/template
refactor: bunch of improvements
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -23,6 +23,8 @@ use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Delta\Delta;
|
||||
use KTXF\Resource\Filter\Filter;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Range\Range;
|
||||
use KTXF\Resource\Range\RangeTally;
|
||||
@@ -283,6 +285,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// ── ServiceConfigurableInterface ──────────────────────────────────────────
|
||||
@@ -521,4 +524,50 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
$uids = array_map('intval', $identifiers);
|
||||
return $this->mailService->entityFetch((string) $collection, ...$uids);
|
||||
}
|
||||
|
||||
public function entityDelete(EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
// validate identifiers and group by collection
|
||||
$collections = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$collections[$identifier->collection()][] = (int) $identifier->entity();
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
|
||||
// delete entities per collection and build result map
|
||||
$result = [];
|
||||
foreach ($collections as $collection => $uids) {
|
||||
$this->mailService->entityDestroy($collection, ...$uids);
|
||||
foreach ($uids as $uid) {
|
||||
$result[(string) $uid] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
// validate target belongs to this service
|
||||
if ($target->provider() !== $this->provider() || $target->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Target collection does not belong to this service');
|
||||
}
|
||||
|
||||
// validate identifiers and construct ID list
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
|
||||
return $this->mailService->entityMove($target->collection(), ...$ids);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user