Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Last active September 20, 2017 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herveguetin/f021e2c4e06b755e5a880175b499f0bd to your computer and use it in GitHub Desktop.
Save herveguetin/f021e2c4e06b755e5a880175b499f0bd to your computer and use it in GitHub Desktop.
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
Copy link

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