Magento re-indexes everything correctly

I searched for a while, after which this answer even looked at the script shell indexer, and I came up with this. In principle, 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" indexes?

** UPDATE **

The problem is solved!

To index everything correctly, just call everyone!

 // 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'); 
+4
source share
2 answers

If you run indexer.php from cli using the following options, do you enable alerts:

indexer.php reindex all

If so, is indexer.php executed with these parameters as part of your script option?

Edit: also in Mage_Index_Model_Process look at the reindexEverything() method.

indexer.php has an example of its use.

+3
source

I ran into this problem in CE v1.9.0.1. My admin module received all processes as a collection and iterated over all calls to reindexEverything (). I based the code on the adminhtml process controller, which worked fine, but my code didn't work at all.

It finally turned out that I had previously set the reindex mode to manual (in order to speed up my product import procedure) 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 the 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 fragments from several different methods, therefore, re-assignment of $ processes, etc.

It seemed that reindexEverything () was not doing anything when the process index mode was set to MODE_MANUAL. The setup mode will return to MODE_REAL_TIME, and then the call to reindexEverything worked fine.

Hope this helps someone since I had a few disappointing hours when we found out!

thanks

+2
source

Source: https://habr.com/ru/post/1412102/


All Articles