2

I need to easily and quickly check if indexing needs to be done. I have been looking around and have

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

or

$process = Mage::getSingleton('index/indexer')->getProcessByCode(<process_code>);

Process Name ID Code 
Product Attributes 1 catalog_product_attribute 
Product Prices 2 catalog_product_price 
Catalog URL Rewrites 3 catalog_url 
Product Flat Data 4 catalog_product_flat 
Category Flat Data 5 catalog_category_flat 
Category Products 6 catalog_category_product 
Catalog Search Index 7 catalogsearch_stock 
Stock Status 8 cataloginventory_stock 
Tag Aggregation Data 9 tag_summary 

but I need to just quickly get the status. Is there a better way?

3
$process = Mage::getSingleton('index/indexer')->getProcessByCode('some_process_code');
if($process->getStatus()==Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX){
    $process->reindexEverything();
}

By the way it has 3 statuses:

class Mage_Index_Model_Process extends Mage_Core_Model_Abstract
{
    const XML_PATH_INDEXER_DATA     = 'global/index/indexer';
    /**
     * Process statuses
     */
    const STATUS_RUNNING            = 'working';
    const STATUS_PENDING            = 'pending';
    const STATUS_REQUIRE_REINDEX    = 'require_reindex';

    /* class body here*/
}
1
  • well that I get, I was more asking if there was another way that was more to the point then me needing to check each one. See it's not that I'm trying to reindex here, it's that I'm going to keep a process in a module I'm making.
    – Quantum
    Jul 17 '13 at 11:53
0

"More to the point" can be achieved by filtering the processes collection by the status your looking for:

$indices = Mage::getSingleton('index/indexer')
        ->getProcessesCollection()
        ->addFieldToFilter('status', Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX)
        ->getSize();
if($indices > 0) {
    // something needs to be re-indexed
}

In case you're looking for what is to be re-indexed you may want to get an array of relevant indices that require further processing:

$indices = Mage::getSingleton('index/indexer')
        ->getProcessesCollection()
        ->addFieldToFilter('status', 'require_reindex')
        ->getColumnValues('indexer_code');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.