I have a module that imports some 10K shops (addresses, details, etc.) from a remote webservice to Magento. At the end of the import, I need to run a specific indexing.

The import part works fine (takes about 1 minute), but the indexing fails about 50% of the time. I was using the following code:

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

Now I have read about another way to run the indexing. I have removed everything from my module and left only the following code:

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

But this fails every time. I get an error on the frontend:

There has been an error processing your request

Edit: the above error was due to another issue in my module. Now I get no error display on the frontend, but still:

I get nothing in the system.log file.

What would be the correct approach to:

  1. Import data to the Magento database
  2. Run a reindex after the import has finished
  3. Log the results of the reindexing (log something if it succeeds or fails)

Edit: What I don't understand is that reindexing fails when ran from my script, but doing it manually from the backend works fine. What am I missing?

Thanks in advance for any help on that!


So to reindex programatically you can work with the following code.

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

This will load your indexer process and reindex it.

As to why it errors I do not know but one piece of advice I can give you is to wrap the call inside a try catch block. This way if an exception is thrown you will pick it up and be able to see what the problem is.

| improve this answer | |
  • That was a late answer but always welcome. And yes that's what I ended up doing. Thanks! – MrUpsidown Apr 9 '15 at 9:13

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.