46 if (!$checkResult->isSuccess())
53 $validationResult = $this->validate($command);
54 if (!$validationResult->isSuccess())
60 if (!$operationResult->isSuccess())
65 $entity = $operationResult->getGroup();
71 $result->merge($operationResult);
73 $handlerResult = $this->runAddHandlers($command,
$entity);
89 if (!$checkResult->isSuccess())
96 $validationResult = $this->validate($command);
97 if (!$validationResult->isSuccess())
102 $entityBefore = $this->getEntityById($command->getId(),
false);
103 if ($entityBefore ===
null)
113 if (!$operationResult->isSuccess())
118 $entityAfter = $operationResult->getGroup();
119 if ($entityAfter ===
null)
124 $result->merge($operationResult);
126 $handlerResult = $this->runUpdateHandlers($command, $entityBefore, $entityAfter);
130 $result->merge($handlerResult);
132 $entity = $this->getEntityById($entityAfter->getId());
142 if (!$checkResult->isSuccess())
149 $validationResult = $this->validate($command);
150 if (!$validationResult->isSuccess())
155 $entityBefore = $this->getEntityById($command->getId(),
false);
156 if ($entityBefore ===
null)
166 if (!$operationResult->isSuccess())
171 $result->merge($operationResult);
173 $handlerResult = $this->runDeleteHandlers($command, $entityBefore);
177 $result->merge($handlerResult);
232 protected function init(): void
234 $this->validationService = ServiceLocator::getInstance()->get(
'main.validation.service');
235 $this->registry = GroupRegistry::getInstance();
245 $handlerResult = $handler->add($command,
$entity);
246 if ($handlerResult->isGroupChanged())
248 $entity = $this->registry->invalidate($id)->get($id);
256 $result->merge($handlerResult);
262 private function runUpdateHandlers(
263 UpdateCommand $command,
264 Workgroup $entityBefore,
265 Workgroup &$entityAfter,
268 $id = $command->getId();
273 $handlerResult = $handler->update($command, $entityBefore, $entityAfter);
274 if ($handlerResult->isGroupChanged())
276 $entityAfter = $this->registry->invalidate($id)->get($id);
277 if ($entityAfter ===
null)
279 $result->addError(
new Error(
'Collab lost during update'));
285 $result->merge($handlerResult);
291 private function runDeleteHandlers(DeleteCommand $command, Workgroup $entityBefore): GroupResult
296 $handlerResult = $handler->delete($command, $entityBefore);
297 $result->merge($handlerResult);
303 private function getEntityById(
int $id,
bool $force =
true): ?Workgroup
307 $this->registry->invalidate($id);
310 return $this->registry->get($id);
313 private function validate(AbstractCommand $command): GroupResult
317 $validationResult = $this->validationService->validate($command);
318 if (!$validationResult->isSuccess())
320 $result->merge($validationResult);