Magento:当管理员启动手动重新索引以及何时开始和结束时,有没有办法记录?

时间:2012-09-28 08:34:37

标签: magento logging indexing

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

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

我认为这将有助于优化我们的数据输入策略,查看哪些流程需要花费很长时间以及谁将其解雇,以及在一天中的什么时间。

我使用过企业版的管理员日志,但这并没有捕获所有这些(而且我不会为此而升级到企业版)。有关如何处理此事的任何想法?

1 个答案:

答案 0 :(得分: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');
}