Magento: Reindexing All

Please find the custom PHP Script to reindex everything in Magento:
<?php
require_once('app/Mage.php');
umask(0);

if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit;
}

// Only for urls // Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
error_reporting(E_ALL);

try {
Mage::getConfig()->init();
Mage::app();
} catch (Exception $e) {
Mage::printException($e);
}
$indexCollection = Mage::getModel('index/process')->getCollection();
foreach ($indexCollection as $index) {
/* @var $index Mage_Index_Model_Process */
$index->reindexAll();
}
echo 'Successfully reindexed';

?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s