How to Change Index Status to REINDEX REQUIRED in Magento

Indexing and index processes were introduced in Magento since version 1.4.x. Here is how you can set one index to ‘REINDEX REQUIRED’ with code programmatically.

First you will need to know which specific index you want to set to dirty. By default in 1.4.2.0 these are the options:

process_id: 1, indexer_code: catalog_product_attribute
process_id: 2, indexer_code: catalog_product_price
process_id: 3, indexer_code: catalog_url
process_id: 4, indexer_code: catalog_product_flat
process_id: 5, indexer_code: catalog_category_flat
process_id: 6, indexer_code: catalog_category_product
process_id: 7, indexer_code: catalogsearch_stock
process_id: 8, indexer_code: cataloginventory_stock
process_id: 9, indexer_code: tag_summary

In order to mark one of them as ‘REINDEX REQUIRED’, use one of the two methods to select the specific index. You can choose by ID or by CODE.

by ID:
$process = Mage::getSingleton('index/indexer')->getProcessById(1);

by CODE:
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_attribute');

Now we need to change the status of this process:
$process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);

Alternatively, we can do it all at once:
Mage::getSingleton('index/indexer')
->getProcessById(1)
->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);

One Comment

Want to Chat with Experienced Magento Developers? Contact Us Now →