DeleteEntityRow.php 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model\ResourceModel\Db;
  7. use Magento\Framework\EntityManager\MetadataPool;
  8. class DeleteEntityRow
  9. {
  10. /**
  11. * @var MetadataPool
  12. */
  13. protected $metadataPool;
  14. /**
  15. * @param MetadataPool $metadataPool
  16. */
  17. public function __construct(
  18. MetadataPool $metadataPool
  19. ) {
  20. $this->metadataPool = $metadataPool;
  21. }
  22. /**
  23. * @param string $entityType
  24. * @param array $data
  25. * @return bool
  26. * @throws \Exception
  27. */
  28. public function execute($entityType, $data)
  29. {
  30. $metadata = $this->metadataPool->getMetadata($entityType);
  31. $connection = $metadata->getEntityConnection();
  32. return $connection->delete(
  33. $metadata->getEntityTable(),
  34. [$metadata->getLinkField() . ' = ?' => $data[$metadata->getLinkField()]]
  35. );
  36. }
  37. }