PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/magento/module-catalog-permissions/Model/Indexer/Category.php

https://bitbucket.org/sergiu-tot-fb/vendors
PHP | 160 lines | 65 code | 16 blank | 79 comment | 3 complexity | d7581216d0bd475860b1b65c91c76d0d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogPermissions\Model\Indexer;
  7. use Magento\Framework\Indexer\CacheContext;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Category implements
  13. \Magento\Framework\Indexer\ActionInterface,
  14. \Magento\Framework\Mview\ActionInterface
  15. {
  16. /**
  17. * Indexer ID in configuration
  18. */
  19. const INDEXER_ID = 'catalogpermissions_category';
  20. /**
  21. * @var Category\Action\FullFactory
  22. */
  23. protected $fullActionFactory;
  24. /**
  25. * @var Category\Action\RowsFactory
  26. */
  27. protected $rowsActionFactory;
  28. /**
  29. * @var \Magento\Framework\Indexer\IndexerRegistry
  30. */
  31. protected $indexerRegistry;
  32. /**
  33. * @var \Magento\Framework\Indexer\CacheContext
  34. * @since 100.0.6
  35. */
  36. protected $cacheContext;
  37. /**
  38. * @param Category\Action\FullFactory $fullActionFactory
  39. * @param Category\Action\RowsFactory $rowsActionFactory
  40. * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
  41. */
  42. public function __construct(
  43. Category\Action\FullFactory $fullActionFactory,
  44. Category\Action\RowsFactory $rowsActionFactory,
  45. \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
  46. ) {
  47. $this->fullActionFactory = $fullActionFactory;
  48. $this->rowsActionFactory = $rowsActionFactory;
  49. $this->indexerRegistry = $indexerRegistry;
  50. }
  51. /**
  52. * Execute full indexation
  53. *
  54. * @return void
  55. */
  56. public function executeFull()
  57. {
  58. $this->fullActionFactory->create()->execute();
  59. $this->registerTags();
  60. }
  61. /**
  62. * Add tags to cache context
  63. *
  64. * @return void
  65. * @since 100.0.6
  66. */
  67. protected function registerTags()
  68. {
  69. $this->getCacheContext()->registerTags([\Magento\Catalog\Model\Category::CACHE_TAG]);
  70. }
  71. /**
  72. * Execute partial indexation by ID list
  73. *
  74. * @param int[] $ids
  75. * @return void
  76. */
  77. public function executeList(array $ids)
  78. {
  79. $this->executeAction($ids);
  80. }
  81. /**
  82. * Execute partial indexation by ID
  83. *
  84. * @param int $id
  85. * @return void
  86. */
  87. public function executeRow($id)
  88. {
  89. $this->executeAction([$id]);
  90. }
  91. /**
  92. * Execute materialization on ids entities
  93. *
  94. * @param int[] $ids
  95. * @return void
  96. */
  97. public function execute($ids)
  98. {
  99. $this->executeAction($ids);
  100. $this->registerEntities($ids);
  101. }
  102. /**
  103. * Add entities to cache context
  104. *
  105. * @param int[] $ids
  106. * @return void
  107. * @since 100.0.6
  108. */
  109. protected function registerEntities($ids)
  110. {
  111. $this->getCacheContext()->registerEntities(\Magento\Catalog\Model\Category::CACHE_TAG, $ids);
  112. }
  113. /**
  114. * Execute action for single entity or list of entities
  115. *
  116. * @param int[] $ids
  117. * @return void
  118. */
  119. protected function executeAction($ids)
  120. {
  121. $ids = array_unique($ids);
  122. /** @var Category\Action\Rows $action */
  123. $action = $this->rowsActionFactory->create();
  124. if ($this->indexerRegistry->get(static::INDEXER_ID)->isWorking()) {
  125. $action->execute($ids, true);
  126. }
  127. $action->execute($ids);
  128. }
  129. /**
  130. * Get cache context
  131. *
  132. * @return \Magento\Framework\Indexer\CacheContext
  133. * @deprecated 100.0.6
  134. * @since 100.0.6
  135. */
  136. protected function getCacheContext()
  137. {
  138. if (!($this->cacheContext instanceof CacheContext)) {
  139. return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
  140. } else {
  141. return $this->cacheContext;
  142. }
  143. }
  144. }