Created
December 15, 2021 01:26
-
-
Save dev-4458/10b6aa4302fb23bce1c3c4b56aa79e1f to your computer and use it in GitHub Desktop.
Magento 2 : PHP Static Script for Re-Indexing
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; | |
require __DIR__ . '/app/bootstrap.php'; | |
ini_set('display_errors', 1); | |
$host = $_SERVER['HTTP_HOST']; | |
$params = $_SERVER; | |
$bootstrap = Bootstrap::create(BP, $params); | |
$objectManager = $bootstrap->getObjectManager(); | |
$state = $objectManager->get('Magento\Framework\App\State'); | |
$state->setAreaCode('frontend'); | |
$indexerFactory = $objectManager->get('Magento\Indexer\Model\IndexerFactory'); | |
$indexerCollectionFactory = $objectManager->get('Magento\Indexer\Model\Indexer\CollectionFactory'); | |
$indexerCollection = $indexerCollectionFactory->create(); | |
$ids = $indexerCollection->getAllIds(); | |
foreach ($ids as $id) { | |
echo " create index: ".$id."<br />"; | |
$idx = $indexerFactory->create()->load($id); | |
$idx->reindexAll($id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment