Skip to content

Instantly share code, notes, and snippets.

@antoinekociuba
Last active March 23, 2016 07:37
Show Gist options
  • Save antoinekociuba/ddca343f217f758f7ad6 to your computer and use it in GitHub Desktop.
Save antoinekociuba/ddca343f217f758f7ad6 to your computer and use it in GitHub Desktop.
Magento full reindex script (EE compatible)
<?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