Last active
December 23, 2021 10:25
-
-
Save keithgreer/9534645a7ba18e82dd227ec31b340ba5 to your computer and use it in GitHub Desktop.
Stand alone script to reindex Magento 2 - https://keithgreer.dev/magento-2-reindex-script-indexer
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 | |
use Magento\Framework\App\Bootstrap; | |
include('app/bootstrap.php'); // Update as required, this line will work if placed in the Magento Root Directory | |
$bootstrap = Bootstrap::create(BP, $_SERVER); | |
$objectManager = $bootstrap->getObjectManager(); | |
$params = $_SERVER; | |
$bootstrap = Bootstrap::create(BP, $params); | |
$obj = $bootstrap->getObjectManager(); | |
$state = $obj->get('Magento\Framework\App\State'); | |
$state->setAreaCode('frontend'); | |
$indexer = $obj->get('Magento\Indexer\Model\Indexer\CollectionFactory')->create(); | |
$ids = $indexer->getAllIds(); | |
?><div style='top:45%; position:absolute; width:75%; text-align:center; color:#666; font-weight:bold; font-size:1.8em; '><?php | |
?><span style='color:green'>● Reindexing... </span> <?php | |
foreach ($ids as $indexerId) { | |
$indexer = $obj->get('Magento\Framework\Indexer\IndexerRegistry')->get($indexerId); | |
$indexer->reindexAll($indexerId); // this reindexes all | |
echo '█'; | |
} | |
echo ' Complete. '; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment