Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reindexing programmatically in Magento 2
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Hervé Guétin <herve.guetin@gmail.com> <@herveguetin>
*/
class Reindex
{
/**
* @var \Magento\Indexer\Console\Command\IndexerReindexCommand
*/
private $reindexCommand;
public function __construct(
\Magento\Indexer\Console\Command\IndexerReindexCommand $reindexCommand
)
{
$this->reindexCommand = $reindexCommand;
}
public function reindexAll()
{
$this->reindexCommand->run(
new \Symfony\Component\Console\Input\StringInput('index'),
new \Symfony\Component\Console\Output\ConsoleOutput()
);
}
}
@gediminaskv

This comment has been minimized.

Copy link

gediminaskv commented May 13, 2017

I can't run reindexAll(), because of wrong instances... May you check https://magento.stackexchange.com/questions/174282/get-to-work-reindexing-in-external-code/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.