public
Last active

Stop Indexing in Magento

  • Download Gist
class.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
class Klasse {
public static function switchIndexingOff() {
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');
}
 
public static function rebuildIndices() {
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');
}
}

I like how you used the walk method, should be used more often in Magento (low memory etc.). Cool thing with the walk method you can pass an anonymous function into it, like so:

<?php
$collection->walk(function($item, $secondArgument){
    //do stuff here
}, array('secondArgument'));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.