GridAsyncInsert.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model;
  7. /**
  8. * Sales entity grids indexing observer.
  9. *
  10. * Performs handling of events and cron jobs related to indexing
  11. * of Order, Invoice, Shipment and Creditmemo grids.
  12. */
  13. class GridAsyncInsert
  14. {
  15. /**
  16. * Entity grid model.
  17. *
  18. * @var \Magento\Sales\Model\ResourceModel\GridInterface
  19. */
  20. protected $entityGrid;
  21. /**
  22. * Global configuration storage.
  23. *
  24. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  25. */
  26. protected $globalConfig;
  27. /**
  28. * @param \Magento\Sales\Model\ResourceModel\GridInterface $entityGrid
  29. * @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
  30. */
  31. public function __construct(
  32. \Magento\Sales\Model\ResourceModel\GridInterface $entityGrid,
  33. \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
  34. ) {
  35. $this->entityGrid = $entityGrid;
  36. $this->globalConfig = $globalConfig;
  37. }
  38. /**
  39. * Handles asynchronous insertion of the new entity into
  40. * corresponding grid during cron job.
  41. *
  42. * Also method is used in the next events:
  43. *
  44. * - config_data_dev_grid_async_indexing_disabled
  45. *
  46. * Works only if asynchronous grid indexing is enabled
  47. * in global settings.
  48. *
  49. * @return void
  50. */
  51. public function asyncInsert()
  52. {
  53. if ($this->globalConfig->getValue('dev/grid/async_indexing')) {
  54. $this->entityGrid->refreshBySchedule();
  55. }
  56. }
  57. }