Last active
September 20, 2017 21:49
-
-
Save herveguetin/f021e2c4e06b755e5a880175b499f0bd to your computer and use it in GitHub Desktop.
Reindexing programmatically in Magento 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | |
* @author Hervé Guétin <[email protected]> <@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() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/ ?