3

I tried locking my indexer programmatically with this code as I used to do:

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

I noticed that my indexer didn't get locked and when i went looking in the core files I saw it was deprecated. Is there any other way to lock the indexer? I looked into it and didn't exactly see one.

6

You could just touch the lock file.

<?php touch('BP.DS.'var'.DS.'locks'.DS.'index_process_1.lock')

or

#!/bin/bash
touch /home/path/public_html/var/locks/index_process_1.lock

This is obviously a low quality solution - but if you wanted to perform this action peripherally to Magento (eg. from a bash script, it would be suitable).


Otherwise, the methods you need are in Mage_Index_Model_Process

Such as isLocked(), lockAndBlock(), and unlock()

Assuming your module extends said class, you need only declare

const PROCESS_ID = 'my_indexer'

And use the methods as appropriate

$this->lockAndBlock();
1
  • Don't really agree with creating them with touch as i rather go the Magento way but lockAndBlock did the trick :) Feb 1 '13 at 9:42
2

You can lock each index process individually:

Mage::getModel('index/process')->load(x)->lock();
1
  • Does it return true if lock succeeds and false if not?
    – snh_nl
    Jan 24 '19 at 11:17

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.