Locking indexer programmatically
سؤال
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.
المحلول
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();
نصائح أخرى
You can lock each index process individually:
Mage::getModel('index/process')->load(x)->lock();