/** * Handle individual entity * * @param Transaction $transaction Transaction * @param CrudEntityInterface $entity Entity * * @return void */ private function handleEntity($transaction, CrudEntityInterface $entity) { $transaction->setRequestSource(Transaction::SOURCE_SERVICE); $transaction->setId(UUID::generate()); $transaction->setRequestId(microtime()); $transaction->setRelatedIds($entity->getIds()); $errors = $this->errorBuilder->getEntityErrors($entity->getPrimaryKey()); $messages = new ArrayCollection(); $success = $errors->isEmpty(); $status = $success ? Transaction::STATUS_CREATED : Transaction::STATUS_CONFLICT; $transaction->setStatus($status); $transaction->setSuccess($success); if ($success) { $this->noticeBuilder->addSuccess(); } else { $messages->set('errors', $errors); $this->noticeBuilder->addFail(); } $transaction->setMessages($messages); $em = $this->registry->getManagerForClass(get_class($transaction)); $em->persist($transaction); $entity->setTransaction($transaction); }
/** * Setting transaction errors * * @param Transaction &$transaction * * @return void */ public function setTransactionErrors(Transaction &$transaction) { $messages = new ArrayCollection(); $globalErrors = $this->getErrors(Error::CONTEXT_GLOBAL); if (!$globalErrors->isEmpty()) { $transaction->setStatus(Transaction::STATUS_NOT_FOUND); } $errors = $this->getErrors(); if (!$errors->isEmpty()) { $messages->set('errors', $errors); } if ($messages->count()) { $transaction->setMessages($messages); } }