Skip to content

Instantly share code, notes, and snippets.

@keithgreer
Last active December 23, 2021 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithgreer/9534645a7ba18e82dd227ec31b340ba5 to your computer and use it in GitHub Desktop.
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
<?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'>&#9679; Reindexing... </span> <?php
foreach ($ids as $indexerId) {
$indexer = $obj->get('Magento\Framework\Indexer\IndexerRegistry')->get($indexerId);
$indexer->reindexAll($indexerId); // this reindexes all
echo '&block;';
}
echo ' Complete. ';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment