Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nntoan/b891ca541baee6cf44a1 to your computer and use it in GitHub Desktop.
Save nntoan/b891ca541baee6cf44a1 to your computer and use it in GitHub Desktop.
Disable/Enable EE index updates (might be useful during a script execution to speed it up...)
<?php
/**********************
****** DISABLE *******
**********************/
/** var Mage_Core_Model_Config $config */
$config = Mage::app()->getConfig();
/**
* Disable on save index updates
*/
$config->saveConfig('index_management/index_options/category_url_rewrite', 0);
$config->saveConfig('index_management/index_options/product_url_rewrite', 0);
$config->saveConfig('index_management/index_options/redirect_url_rewrite', 0);
$config->saveConfig(Enterprise_CatalogSearch_Model_Observer::XML_PATH_LIVE_FULLTEXT_REINDEX_ENABLED, 0);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Flat::XML_PATH_LIVE_PRODUCT_REINDEX_ENABLED, 0);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Flat::XML_PATH_LIVE_CATEGORY_REINDEX_ENABLED, 0);
$config->saveConfig(Enterprise_CatalogInventory_Helper_Index::XML_PATH_LIVE_PRICE_AND_STOCK_REINDEX_ENABLED, 0);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Category_Product::XML_PATH_LIVE_CATEGORY_PRODUCT_REINDEX_ENABLED, 0);
/**
* Refresh config cache
*/
$config->reinit();
/**
* Lock full reindex process (so 'enterprise_refresh_index' cron will do nothing)
* This should be on a try catch, as the cron could be already running when this code is executed
*/
Mage::dispatchEvent('shell_reindex_init_process');
/**
*
*
*
*
*
* Do whatever you want! =)
*
*
*
*
*
*/
/**********************
**** ENABLE BACK *****
**********************/
/**
* Enable on save index updates
*/
$config->saveConfig('index_management/index_options/category_url_rewrite', 1);
$config->saveConfig('index_management/index_options/product_url_rewrite', 1);
$config->saveConfig('index_management/index_options/redirect_url_rewrite', 1);
$config->saveConfig(Enterprise_CatalogSearch_Model_Observer::XML_PATH_LIVE_FULLTEXT_REINDEX_ENABLED, 1);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Flat::XML_PATH_LIVE_PRODUCT_REINDEX_ENABLED, 1);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Flat::XML_PATH_LIVE_CATEGORY_REINDEX_ENABLED, 1);
$config->saveConfig(Enterprise_CatalogInventory_Helper_Index::XML_PATH_LIVE_PRICE_AND_STOCK_REINDEX_ENABLED, 1);
$config->saveConfig(Enterprise_Catalog_Model_Index_Observer_Category_Product::XML_PATH_LIVE_CATEGORY_PRODUCT_REINDEX_ENABLED, 1);
/**
* Refresh config cache
*/
$config->reinit();
/**
* Release full reindex process lock (so cron will be back on track)
*/
Mage::dispatchEvent('shell_reindex_finalize_process');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment