UpdatedIdListProvider.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Provider;
  7. use Magento\Framework\App\ResourceConnection;
  8. use Magento\Framework\DB\Adapter\AdapterInterface;
  9. /**
  10. * Provides latest updated entities ids list
  11. */
  12. class UpdatedIdListProvider implements NotSyncedDataProviderInterface
  13. {
  14. /**
  15. * @var ResourceConnection
  16. */
  17. private $resourceConnection;
  18. /**
  19. * @var AdapterInterface
  20. */
  21. private $connection;
  22. /**
  23. * NotSyncedDataProvider constructor.
  24. * @param ResourceConnection $resourceConnection
  25. */
  26. public function __construct(
  27. ResourceConnection $resourceConnection
  28. ) {
  29. $this->resourceConnection = $resourceConnection;
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function getIds($mainTableName, $gridTableName)
  35. {
  36. $mainTableName = $this->resourceConnection->getTableName($mainTableName);
  37. $gridTableName = $this->resourceConnection->getTableName($gridTableName);
  38. $select = $this->getConnection()->select()
  39. ->from($mainTableName, [$mainTableName . '.entity_id'])
  40. ->joinLeft(
  41. [$gridTableName => $gridTableName],
  42. sprintf(
  43. '%s.%s = %s.%s',
  44. $mainTableName,
  45. 'entity_id',
  46. $gridTableName,
  47. 'entity_id'
  48. ),
  49. []
  50. )
  51. ->where($gridTableName . '.entity_id IS NULL');
  52. return $this->getConnection()->fetchAll($select, [], \Zend_Db::FETCH_COLUMN);
  53. }
  54. /**
  55. * Returns connection.
  56. *
  57. * @return AdapterInterface
  58. */
  59. private function getConnection()
  60. {
  61. if (!$this->connection) {
  62. $this->connection = $this->resourceConnection->getConnection('sales');
  63. }
  64. return $this->connection;
  65. }
  66. }