Esempio n. 1
0
 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $connection->update($metadata->getEntityTable(), $this->prepareData($metadata, $connection, $data), [$metadata->getLinkField() . ' = ?' => $data[$metadata->getLinkField()]]);
     return $data;
 }
Esempio n. 2
0
 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $linkField = $metadata->getLinkField();
     $entityTable = $metadata->getEntityTable();
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $connection->insert($entityTable, $this->prepareData($metadata, $connection, $data));
     $data[$linkField] = $connection->lastInsertId($entityTable);
     return $data;
 }
Esempio n. 3
0
 /**
  * @param CustomerInterface $entity
  * @param array $arguments
  * @return CustomerInterface
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $metadata = $this->metadataPool->getMetadata(ExtensionAttributeInterface::class);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $id = $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where('customer_id = ?', $entity->getId())->limit(1));
     $extensionAttribute = $this->extensionAttributeFactory->create();
     $extensionAttribute = $this->entityManager->load($extensionAttribute, $id);
     $customerExtension = $this->customerExtensionFactory->create(['data' => ['extension_attribute' => $extensionAttribute]]);
     $entity->setExtensionAttributes($customerExtension);
     return $entity;
 }
Esempio n. 4
0
 /**
  * @param string $entityType
  * @param string $identifier
  * @param array $context
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $identifier, $context = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $metadata = $this->metadataPool->getMetadata($entityType);
     $select = $connection->select()->from(['t' => $metadata->getEntityTable()])->where($metadata->getIdentifierField() . ' = ?', $identifier);
     foreach ($context as $field => $value) {
         $select->where($connection->quoteIdentifier($field) . ' = ?', $value);
     }
     $data = $connection->fetchRow($select);
     return $data ?: [];
 }
Esempio n. 5
0
 /**
  * @param object $entity
  * @param array $arguments
  * @return bool
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $entityType = $this->typeResolver->resolve($entity);
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->hydratorPool->getHydrator($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $entityData = $hydrator->extract($entity);
     if (!isset($entityData[$metadata->getIdentifierField()])) {
         return false;
     }
     return (bool) $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where($metadata->getIdentifierField() . ' = ?', $entityData[$metadata->getIdentifierField()])->limit(1));
 }
Esempio n. 6
0
 /**
  * @param string $entityType
  * @param int $identifier
  * @return int
  * @throws \Exception
  */
 public function delete($entityType, $identifier)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $sequenceInfo = $this->sequenceRegistry->retrieve($entityType);
     if (!isset($sequenceInfo['sequenceTable'])) {
         throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists');
     }
     try {
         $connection = $this->appResource->getConnectionByName($metadata->getEntityConnectionName());
         return $connection->delete($this->appResource->getTableName($sequenceInfo['sequenceTable']), ['sequence_value = ?' => $identifier]);
     } catch (\Exception $e) {
         $this->logger->critical($e->getMessage(), $e->getTrace());
         throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
     }
 }
Esempio n. 7
0
 /**
  * @param string $entityType
  * @param object $entity
  * @param array $arguments
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity, $arguments = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $this->transactionManager->start($connection);
     try {
         $this->eventManager->dispatch(
             'entity_manager_delete_before',
             [
                 'entity_type' => $entityType,
                 'entity' => $entity
             ]
         );
         $this->eventManager->dispatchEntityEvent($entityType, 'delete_before', ['entity' => $entity]);
         $entity = $this->deleteExtensions->execute($entityType, $entity, $arguments);
         $entity = $this->deleteAttributes->execute($entityType, $entity, $arguments);
         $entity = $this->deleteMain->execute($entityType, $entity, $arguments);
         $this->eventManager->dispatchEntityEvent($entityType, 'delete_after', ['entity' => $entity]);
         $this->eventManager->dispatch(
             'entity_manager_delete_before',
             [
                 'entity_type' => $entityType,
                 'entity' => $entity
             ]
         );
         $this->transactionManager->commit();
     } catch (\Exception $e) {
         $this->transactionManager->rollBack();
         throw $e;
     }
     return $entity;
 }
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Connection "invalid" is not defined
  */
 public function testGetConnectionFail()
 {
     $this->resource->getConnectionByName('invalid');
 }
Esempio n. 9
0
 /**
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getEntityConnection()
 {
     return $this->appResource->getConnectionByName($this->connectionName);
 }