4

I have searched for a while, followed this answer even looked at the shell indexer script, and I came with this. Basically, I have

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');

// Importing data here...

Mage::getModel('catalog/product_image')->clearCache();

// rebuild everything!!!
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexEverything');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

But I still get this screen in my backend

enter image description here

...How to "update" the indexes?

** UPDATE **

Problem solved!

To properly index everything, just call everything!

// rebuild everything!!!
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

$processes->walk('reindexAll');
$processes->walk('reindexEverything');
Community
  • 1
  • 1
Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214

2 Answers2

2

If you run indexer.php from cli, using the following parameters, do the alerts become resolved:

indexer.php reindex all

If so, is executing indexer.php with those params as part of your script an option?

Edit: also, in Mage_Index_Model_Process take a look at reindexEverything() method.

indexer.php has an example of its usage.

djdy
  • 6,779
  • 6
  • 38
  • 62
  • take a look at indexer.php and please tell me what is there in it that I don't have in my code? That's what I want to know; why can't I re-index everything properly in my own script? – Yanick Rochon May 12 '12 at 02:22
  • OK I see... hmm Have you seen this answer? http://stackoverflow.com/a/4343900/634843 Have you tried using reindexAll() instead of reindexEverything()? – djdy May 12 '12 at 02:33
  • Yes, I have tried both. And, frankly, I have no idea what's the difference between them both; I mean, isn't both terms "all" <==> "everything" just the same?? – Yanick Rochon May 12 '12 at 02:34
  • reindexEverything() appears to check and use depends prior to moving on to reindexAll(). I may be out of ideas for the moment. Sorry. I'll think about it some more though, and post if I come up with something. – djdy May 12 '12 at 02:38
2

I just encountered this issue in CE v1.9.0.1. My admin module was getting all processes as a collection and looping through each one calling reindexEverything(). I based the code on the adminhtml process controller which was working fine, but my code wasn't working at all.

I finally figured out the issue was that I had previously set the reindex mode to manual (to speed up my product import routine) as follows:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));


// run product import 


$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach($processes as $p)
{
    if($p->getIndexer()->isVisible())
    {
        $p->reindexEverything();
        //echo $p->getIndexer()->getName() . ' reindexed<br>';
    }
}



$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));

SOLUTION: set mode back to MODE_REAL_TIME before reindexing everything:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));


// run product import 


$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));



$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach($processes as $p)
{
    if($p->getIndexer()->isVisible())
    {
        $p->reindexEverything();
        //echo $p->getIndexer()->getName() . ' reindexed<br>';
    }
}

Note: these are snips from a few different methods hence the repeated assignment of $processes etc..

It seemed reindexEverything() wasn't doing anything when the processes index mode was set to MODE_MANUAL. Setting mode back to MODE_REAL_TIME and then calling reindexEverything worked fine.

I hope this helps someone as I had a few frustrated hours figuring this one out!

Thanks

  • Yes, this is why I added an **update** to the question with a snippet of my working solution, based on the chosen answer. Your answer explains why. Thanks. (BTW: the `'save'` part is to flush everything in cache before reindexing.) – Yanick Rochon Aug 03 '14 at 21:46