2

a few time per day i get the following error (as listed in the reports)

a:5:{i:0;s:124:"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'catalog_url' for key 'UNQ_INDEX_PROCESS_INDEXER_CODE'";i:1;s:1900:"#0 /path-to-magento/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /path-to-magento/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /path-to-magento/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /path-to-magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `in...', Array)
#4 /path-to-magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `in...', Array)
#5 /path-to-magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(1998): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `in...', Array)
#6 /path-to-magento/app/code/core/Mage/Index/Model/Resource/Setup.php(82): Varien_Db_Adapter_Pdo_Mysql->insertArray('index_process', Array, Array)
#7 /path-to-magento/app/code/core/Mage/Index/Model/Resource/Setup.php(45): Mage_Index_Model_Resource_Setup->_syncIndexes()
#8 /path-to-magento/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Index_Model_Resource_Setup->applyUpdates()
#9 /path-to-magento/app/code/core/Mage/Core/Model/App.php(417): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#10 /path-to-magento/app/code/core/Mage/Core/Model/App.php(343): Mage_Core_Model_App->_initModules()
#11 /path-to-magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#12 /path-to-magento/index.php(89): Mage::run('', 'store')
#13 {main}";s:3:"url";s:98:"/accessoires/peuter_80_98.html";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

I have magento 1.8.1 CE. Does anyone know what is wrong?

1 Answer 1

2

According to the stack trace, Magento is trying to add the indexer catalog_url to the database for some reason.

I think this function is the key to finding out what might be wrong:

// Mage_Index_Model_Resource_Setup
protected function _syncIndexes()
{
    $connection = $this->getConnection();
    if (!$connection) {
        return $this;
    }
    $indexes = Mage::getConfig()->getNode(Mage_Index_Model_Process::XML_PATH_INDEXER_DATA);
    $indexCodes = array();
    foreach ($indexes->children() as $code => $index) {
        $indexCodes[] = $code;
    }
    $table = $this->getTable('index/process');
    $select = $connection->select()->from($table, 'indexer_code');
    $existingIndexes = $connection->fetchCol($select);
    $delete = array_diff($existingIndexes, $indexCodes);
    $insert = array_diff($indexCodes, $existingIndexes);

    if (!empty($delete)) {
        $connection->delete($table, $connection->quoteInto('indexer_code IN (?)', $delete));
    }
    if (!empty($insert)) {
        $insertData = array();
        foreach ($insert as $code) {
            $insertData[] = array(
                'indexer_code' => $code,
                'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX
            );
        }
        if (method_exists($connection, 'insertArray')) {
            $connection->insertArray($table, array('indexer_code', 'status'), $insertData);
        }
    }
}

Magento goes through the setup procedure of the Mage_Index module. This is where new indexers get added and old ones are deleted, etc. That's what you can see in the code above.

In your case, the indexer catalog_url isn't found, so Magento tries to add it again.

Take a look at the table index_process in your database. It will probably have an entry for catalog_url. So, when Magento tries to insert a new entry for this indexer, you will get the constraint violation.

5
  • Hi, in what file should I place this code?
    – Ronny
    Apr 20, 2015 at 18:59
  • This is part of the Magento core. You will find it here: app\code\core\Mage\Index\Model\Resource\Setup.php
    – Vicky
    Apr 21, 2015 at 11:22
  • Thanks. Is this safe to use in a live environment or only in a developer environment?
    – Ronny
    Apr 21, 2015 at 12:52
  • This code is part of the core, so it is safe to use. However, you should debug the problem in a development environment.
    – Vicky
    Apr 21, 2015 at 12:54
  • The problem was in the need of reindexing the flat catalog category. But this was disabled and only visible in the database
    – Ronny
    Apr 22, 2015 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.