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 #127 from DivanteLtd/bugfix/fix-vsbridge-rebuild-c…
Browse files Browse the repository at this point in the history
…ommand

Fix vsbridge:reindex command.
  • Loading branch information
afirlejczyk authored Oct 9, 2019
2 parents 81104e8 + 3d12f8f commit ebb9fcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
use Divante\VsbridgeIndexerCore\Indexer\StoreManager;
use Divante\VsbridgeIndexerCore\Index\IndexOperations;
use Magento\Backend\App\Area\FrontNameResolver;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Indexer\Console\Command\AbstractIndexerCommand;
use Magento\Store\Api\Data\StoreInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\Command;
Expand All @@ -25,19 +26,14 @@
/**
* Class IndexerReindexCommand
*/
class RebuildEsIndexCommand extends Command
class RebuildEsIndexCommand extends AbstractIndexerCommand
{
const INPUT_STORE = 'store';
const INPUT_ALL_STORES = 'all';
const INPUT_DELETE_INDEX = 'delete-index';

const INDEX_IDENTIFIER = 'vue_storefront_catalog';

/**
* @var \Magento\Indexer\Model\Indexer\CollectionFactory
*/
private $collectionFactory;

/**
* @var IndexOperations
*/
Expand All @@ -49,37 +45,21 @@ class RebuildEsIndexCommand extends Command
private $storeManager;

/**
* @var IndexerRegistry
*/
private $indexerRegistry;

/**
* @var \Magento\Framework\App\State
*/
private $state;

/**
* Construct
* RebuildEsIndexCommand constructor.
*
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
* @param IndexOperations\Proxy $indexOperations
* @param StoreManager\Proxy $storeManager
* @param \Magento\Framework\App\State\Proxy $state
* @param \Magento\Indexer\Model\Indexer\CollectionFactory\Proxy $collectionFactory
* @param ObjectManagerFactory $objectManagerFactory
* @param IndexOperations $indexOperations
* @param StoreManager $storeManager
*/
public function __construct(
IndexerRegistry $indexerRegistry,
ObjectManagerFactory $objectManagerFactory,
IndexOperations $indexOperations,
StoreManager $storeManager,
\Magento\Framework\App\State $state,
\Magento\Indexer\Model\Indexer\CollectionFactory $collectionFactory
StoreManager $storeManager
) {
$this->indexerRegistry = $indexerRegistry;
$this->collectionFactory = $collectionFactory;
$this->indexOperations = $indexOperations;
$this->storeManager = $storeManager;
$this->state = $state;
parent::__construct();

parent::__construct($objectManagerFactory);
}

/**
Expand Down Expand Up @@ -120,6 +100,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->initObjectManager();
$output->setDecorated(true);
$storeId = $input->getOption(self::INPUT_STORE);
$allStores = $input->getOption(self::INPUT_ALL_STORES);
Expand All @@ -133,7 +114,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$store = $stores[0];
$output->writeln("<info>Reindexing all VS indexes for store " . $store->getName() . "...</info>");

$this->setAreaCode();
$returnValue = $this->reindexStore($store, $deleteIndex, $output);

$output->writeln("<info>Reindexing has completed!</info>");
Expand All @@ -142,7 +122,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
} elseif ($allStores) {
$output->writeln("<info>Reindexing all stores...</info>");
$this->setAreaCode();
$returnValues = [];

/** @var \Magento\Store\Api\Data\StoreInterface $store */
Expand Down Expand Up @@ -202,24 +181,14 @@ private function reindexStore(StoreInterface $store, bool $deleteIndex, OutputIn
return $returnValue;
}

/**
* @return void
*/
private function setAreaCode()
{
try {
$this->state->setAreaCode(FrontNameResolver::AREA_CODE);
} catch (\Exception $e) {
}
}

/**
* @return IndexerInterface[]
*/
protected function getIndexers()
private function getIndexers()
{
/** @var IndexerInterface[] */
$indexers = $this->collectionFactory->create()->getItems();
$indexers = $this->getAllIndexers();

unset($indexers[ProductCategoryProcessor::INDEXER_ID]);
$vsbridgeIndexers = [];

Expand All @@ -231,4 +200,12 @@ protected function getIndexers()

return $vsbridgeIndexers;
}

/**
* Initiliaze object manager
*/
private function initObjectManager()
{
$this->getObjectManager();
}
}
2 changes: 0 additions & 2 deletions src/module-vsbridge-indexer-core/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
<arguments>
<argument name="indexOperations" xsi:type="object">Divante\VsbridgeIndexerCore\Index\IndexOperations\Proxy</argument>
<argument name="storeManager" xsi:type="object">Divante\VsbridgeIndexerCore\Indexer\StoreManager\Proxy</argument>
<argument name="state" xsi:type="object">Magento\Framework\App\State\Proxy</argument>
<argument name="collectionFactory" xsi:type="object">Magento\Indexer\Model\Indexer\CollectionFactory\Proxy</argument>
</arguments>
</type>
</config>

0 comments on commit ebb9fcf

Please sign in to comment.