Magento Auto Reindexing Using Cron.

0
97
views
Advertisement

Hello Everyone Below Script Is Used To Automatically Reindexing In Magento. This Script Is’nt Reindexing all the Index every time. But, It’ll Reindexing Only Index Type Which Is Required To Reindexing In Magento.

In Below Code I Have Create The Log File Using Following Line “Mage::log(‘Index ‘.$indexer->getIndexerCode().” Is Reindex.”,null,’Index_AutoRefresh.log’);”. So You Can Check The Indixing Log on “Index_AutoRefresh.log” File Which Locate In “var/log/Index_AutoRefresh.log”.

<?php


//Cache Refresh Start

ini_set('max_execution_time', 18000); 

require_once 'app/Mage.php';

$app = Mage::app('admin');

umask(0);

Mage::setIsDeveloperMode(true);

//Indexing Start

$indexerCollection=Mage::getResourceModel('index/process_collection');

$indexerCollection->addFieldToFilter("status",array("eq"=>Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX));

foreach($indexerCollection as $indexer)

{

$indexer->reindexEverything();

Mage::log('Index '.$indexer->getIndexerCode()." Is Reindex.",null,'Index_AutoRefresh.log'); 

}

//Indexing End

?>

For Automatically Reindexing You Just Need To Create One File On Magento Root Folder For Example AutocronReindex.php And Add This File On Cron.

Thanks for reading my blog. I hope it will help you, Please leave your comments here if it’s really help you. 🙂

Thank You :),
Mayank Zalavadia