-
-
Save nntoan/d61e01be03fec2443faa to your computer and use it in GitHub Desktop.
Magento full reindex script (EE compatible)
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 | |
/** Full reindex script */ | |
/** | |
* @var array | |
*/ | |
$processes = array(); | |
/** | |
* @var Mage_Core_Model_Factory $factory | |
*/ | |
$factory = Mage::getSingleton('core/factory'); | |
/** | |
* @var Mage_Index_Model_Indexer $indexer | |
*/ | |
$indexer = $factory->getSingleton($factory->getIndexClassAlias()); | |
foreach ($indexer->getProcessesCollection() as $process) { | |
if ($process->getIndexer()->isVisible() === false) { | |
continue; | |
} | |
$processes[] = $process; | |
} | |
try { | |
/** | |
* Lock full reindex process (for EE versions) | |
*/ | |
Mage::dispatchEvent('shell_reindex_init_process'); | |
foreach ($processes as $process) { | |
/** @var $process Mage_Index_Model_Process */ | |
try { | |
$process->reindexEverything(); | |
Mage::dispatchEvent($process->getIndexerCode() . '_shell_reindex_after'); | |
echo $process->getIndexer()->getName() . " index was rebuilt successfully" . PHP_EOL; | |
} catch (Mage_Core_Exception $e) { | |
echo $e->getMessage() . PHP_EOL; | |
} catch (Exception $e) { | |
echo $process->getIndexer()->getName() . " index process unknown error:" . PHP_EOL; | |
echo $e . PHP_EOL; | |
} | |
} | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
} | |
/** | |
* Release full reindex process lock (for EE versions) | |
*/ | |
Mage::dispatchEvent('shell_reindex_finalize_process'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment