metadataPool = $metadataPool; $this->typeResolver = $typeResolver; $this->resourceConnection = $resourceConnection; $this->eventManager = $eventManager; $this->updateMain = $updateMain; $this->updateAttributes = $updateAttributes; $this->updateExtensions = $updateExtensions; } /** * @param object $entity * @param array $arguments * @return object * @throws \Exception */ public function execute($entity, $arguments = []) { $entityType = $this->typeResolver->resolve($entity); $metadata = $this->metadataPool->getMetadata($entityType); $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName()); $connection->beginTransaction(); try { $this->eventManager->dispatch( 'entity_manager_save_before', [ 'entity_type' => $entityType, 'entity' => $entity ] ); $this->eventManager->dispatchEntityEvent($entityType, 'save_before', ['entity' => $entity]); $entity = $this->updateMain->execute($entity, $arguments); $entity = $this->updateAttributes->execute($entity, $arguments); $entity = $this->updateExtensions->execute($entity, $arguments); $this->eventManager->dispatchEntityEvent($entityType, 'save_after', ['entity' => $entity]); $this->eventManager->dispatch( 'entity_manager_save_after', [ 'entity_type' => $entityType, 'entity' => $entity ] ); $connection->commit(); } catch (DuplicateException $e) { $connection->rollBack(); throw new AlreadyExistsException(new Phrase('Unique constraint violation found'), $e); } catch (\Exception $e) { $connection->rollBack(); throw $e; } return $entity; } }