BulkSummaryMapper.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Model\Entity;
  7. use Magento\Framework\EntityManager\MapperInterface;
  8. use Magento\Framework\App\ResourceConnection;
  9. use Magento\Framework\EntityManager\MetadataPool;
  10. /**
  11. * @deprecated 100.2.0
  12. */
  13. class BulkSummaryMapper implements MapperInterface
  14. {
  15. /**
  16. * @var MetadataPool
  17. */
  18. private $metadataPool;
  19. /**
  20. * @var ResourceConnection
  21. */
  22. private $resourceConnection;
  23. /**
  24. * @param MetadataPool $metadataPool
  25. * @param ResourceConnection $resourceConnection
  26. */
  27. public function __construct(
  28. MetadataPool $metadataPool,
  29. ResourceConnection $resourceConnection
  30. ) {
  31. $this->metadataPool = $metadataPool;
  32. $this->resourceConnection = $resourceConnection;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function entityToDatabase($entityType, $data)
  38. {
  39. // workaround for delete/update operations that are currently using only primary key as identifier
  40. if (!empty($data['uuid'])) {
  41. $metadata = $this->metadataPool->getMetadata($entityType);
  42. $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
  43. $select = $connection->select()->from($metadata->getEntityTable(), 'id')->where("uuid = ?", $data['uuid']);
  44. $identifier = $connection->fetchOne($select);
  45. if ($identifier !== false) {
  46. $data['id'] = $identifier;
  47. }
  48. }
  49. return $data;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. * @codeCoverageIgnore
  54. */
  55. public function databaseToEntity($entityType, $data)
  56. {
  57. return $data;
  58. }
  59. }