UpdatedAtListProvider.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * Retrieves ID's of not synced by `updated_at` column entities.
  11. * The result should contain list of entities ID's from the main table which have `updated_at` column greater
  12. * than in the grid table.
  13. */
  14. class UpdatedAtListProvider implements NotSyncedDataProviderInterface
  15. {
  16. /**
  17. * @var ResourceConnection
  18. */
  19. private $resourceConnection;
  20. /**
  21. * @var AdapterInterface
  22. */
  23. private $connection;
  24. /**
  25. * @param ResourceConnection $resourceConnection
  26. */
  27. public function __construct(ResourceConnection $resourceConnection)
  28. {
  29. $this->connection = $resourceConnection->getConnection('sales');
  30. $this->resourceConnection = $resourceConnection;
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function getIds($mainTableName, $gridTableName)
  36. {
  37. $mainTableName = $this->resourceConnection->getTableName($mainTableName);
  38. $gridTableName = $this->resourceConnection->getTableName($gridTableName);
  39. $select = $this->connection->select()
  40. ->from($mainTableName, [$mainTableName . '.entity_id'])
  41. ->joinInner(
  42. [$gridTableName => $gridTableName],
  43. sprintf(
  44. '%s.entity_id = %s.entity_id AND %s.updated_at > %s.updated_at',
  45. $mainTableName,
  46. $gridTableName,
  47. $mainTableName,
  48. $gridTableName
  49. ),
  50. []
  51. );
  52. return $this->connection->fetchAll($select, [], \Zend_Db::FETCH_COLUMN);
  53. }
  54. }