1

我正在使用 Magento Community 1.6.1.0,我想跟踪我们的管理员何时开始手动重新索引,以及重新索引需要多长时间(即何时开始和停止)。输出将类似于:

Reindex process name, Datetime, Admin User, Start/End

我认为这将是有价值的信息,有助于优化我们的数据输入策略,了解哪些流程需要很长时间,谁在启动它们,以及一天中的什么时间。

我使用过 Enterprise 版本的 Admin Log,但这并没有捕获所有内容(而且我不会为此升级到 Enterprise)。关于如何解决这个问题的任何想法?

4

1 回答 1

0

为此,您需要创建一个扩展的自定义模块:

/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php

更新

public function reindexProcessAction()
{
    $process = $this->_initProcess();

    // start logger here and get admin user name

    if ($process) {
        try {
            Varien_Profiler::start('__INDEX_PROCESS_REINDEX_ALL__');

            $process->reindexEverything();
            Varien_Profiler::stop('__INDEX_PROCESS_REINDEX_ALL__');
            $this->_getSession()->addSuccess(
                Mage::helper('index')->__('%s index was rebuilt.', $process->getIndexer()->getName())
            );
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addException($e,
                 Mage::helper('index')->__('There was a problem with reindexing process.')
            );
        }
    } else {
        $this->_getSession()->addError(
            Mage::helper('index')->__('Cannot initialize the indexer process.')
        );
    }

     // stop timer and write information to db or file

    $this->_redirect('*/*/list');
}

public function massReindexAction()
{    
    // start logger here and get admin user name
    /* @var $indexer Mage_Index_Model_Indexer */
    $indexer    = Mage::getSingleton('index/indexer');
    $processIds = $this->getRequest()->getParam('process');
    if (empty($processIds) || !is_array($processIds)) {
        $this->_getSession()->addError(Mage::helper('index')->__('Please select Indexes'));
    } else {
        try {
            foreach ($processIds as $processId) {
                /* @var $process Mage_Index_Model_Process */
                $process = $indexer->getProcessById($processId);
                if ($process) {
                    $process->reindexEverything();
                }
            }
            $count = count($processIds);
            $this->_getSession()->addSuccess(
                Mage::helper('index')->__('Total of %d index(es) have reindexed data.', $count)
            );
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addException($e, Mage::helper('index')->__('Cannot initialize the indexer process.'));
        }
    }
    // stop timer and write information to db or file
    $this->_redirect('*/*/list');
}
于 2012-10-02T23:35:44.283 回答