Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #280 from MEEVO-Healthcare-GmbH/master
Browse files Browse the repository at this point in the history
Added events to reindex command.
  • Loading branch information
afirlejczyk authored May 22, 2020
2 parents 57b9cee + 5d82c12 commit 8451a85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Divante\VsbridgeIndexerCore\Model\IndexerRegistry;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\Console\Cli;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Indexer\Console\Command\AbstractIndexerCommand;
Expand Down Expand Up @@ -59,18 +60,26 @@ class RebuildEsIndexCommand extends AbstractIndexerCommand
*/
private $excludeIndices = [];

/**
* @var ManagerInterface
*/
private $eventManager;

/**
* RebuildEsIndexCommand constructor.
*
* @param ObjectManagerFactory $objectManagerFactory
* @param array $excludeIndices
* @param ObjectManagerFactory $objectManagerFactory
* @param ManagerInterface $eventManager
* @param array $excludeIndices
*/
public function __construct(
ObjectManagerFactory $objectManagerFactory,
ManagerInterface $eventManager, // Proxy
array $excludeIndices = []
) {
$this->excludeIndices = $excludeIndices;
parent::__construct($objectManagerFactory);
$this->eventManager = $eventManager;
}

/**
Expand Down Expand Up @@ -152,6 +161,10 @@ private function getInvalidIndices()
*/
private function reindex(OutputInterface $output, $storeId, $allStores)
{
$this->eventManager->dispatch('vsbridge_indexer_reindex_before', [
'storeId' => $storeId,
'allStores' => $allStores,
]);

if ($storeId) {
$store = $this->getStoreManager()->getStore($storeId);
Expand Down Expand Up @@ -182,6 +195,11 @@ private function reindex(OutputInterface $output, $storeId, $allStores)
// If failure returned in any store return failure now
return in_array(Cli::RETURN_FAILURE, $returnValues) ? Cli::RETURN_FAILURE : Cli::RETURN_SUCCESS;
}

$this->eventManager->dispatch('vsbridge_indexer_reindex_after', [
'storeId' => $storeId,
'allStores' => $allStores,
]);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/module-vsbridge-indexer-core/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@
</argument>
</arguments>
</type>

<type name="Divante\VsbridgeIndexerCore\Console\Command\RebuildEsIndexCommand">
<arguments>
<argument name="eventManager" xsi:type="object">Magento\Framework\Event\ManagerInterface\Proxy</argument>
</arguments>
</type>
</config>

0 comments on commit 8451a85

Please sign in to comment.