Folgend möchte ich zeigen, wie man per Script alle Indexe Aktualisiert, dies ist z.B. für eine Produkt-Schnittstelle sehr interessant.
Sript außerhalb von Magento:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function rebuildIndexes(){ $processes = array(); $collection = Mage::getSingleton('index/indexer')->getProcessesCollection(); foreach ($collection as $process) { try { $process->reindexEverything(); echo($process->getIndexer()->getName() . " index was rebuilt successfully"."\n"); } catch (Mage_Core_Exception $e) { echo($e->getMessage()); } catch (Exception $e) { echo($process->getIndexer()->getName() . " index process unknown error:\n" . $e ."\n"); } } } |
Script zum einbinden in eine Magento-Extension:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public function rebuildIndexes(){ $processes = array(); $collection = Mage::getSingleton('index/indexer')->getProcessesCollection(); foreach ($collection as $process) { try { $process->reindexEverything(); $this->_message($process->getIndexer()->getName() . " index was rebuilt successfully"); } catch (Mage_Core_Exception $e) { $this->_throwException($e->getMessage()); } catch (Exception $e) { $this->_throwException($process->getIndexer()->getName() . " index process unknown error:\n" . $e); } } } |
Übersicht einzelner Indexe (falls nicht alle aktualisiert werden sollen):
1 2 3 4 5 6 7 8 9 10 11 12 13 | Mage::getSingleton('catalog/index')->rebuild(); Mage::getResourceModel('catalog/product_flat_indexer')->rebuild(); Mage::getSingleton('catalog/url')->refreshRewrites(); Mage::getModel('catalog/product_image')->clearCache(); Mage::getSingleton('catalogsearch/fulltext')->rebuildIndex(); Mage::getSingleton('cataloginventory/stock_status')->rebuild(); $flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf(); if ($flag->getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING) { $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf(); $kill->setFlagData($flag->getFlagData())->save(); } $flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save(); Mage::getSingleton('catalogindex/indexer')->plainReindex(); |