Magento Forum

   
Page 1 of 3
Reindexing “Catalog URL Rewrites” fails
 
gatinho
Member
 
Total Posts:  54
Joined:  2010-02-25
 

In index-management “Catalog URL Rewrites” is in state processing (but seems that there is no progress). Triggering reindex fails with message “An error occurred while saving the URL rewrite”.

Deleting var/cache, var/session as I read in other thread didn’t fix.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3215
Joined:  2009-02-26
Minneapolis MN
 

Can you try this

php shell/indexer.php reindexall

 
Magento Community Magento Community
Magento Community
Magento Community
 
gatinho
Member
 
Total Posts:  54
Joined:  2010-02-25
 

called the script manually and checked the exception log

2011-09-01T23:33:49+00:00 ERR (3):
exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘category/13-1-2’ for key 3’ in /var/www/magento/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/magento/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/magento/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/magento/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/magento/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /var/www/magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `co...’, Array)
#5 /var/www/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `co...’, Array)
#6 /var/www/magento/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `co...’, Array)
#7 /var/www/magento/app/code/core/Mage/Catalog/Model/Resource/Url.php(283): Zend_Db_Adapter_Abstract->insert(’core_url_rewrit...’, Array)
#8 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(290): Mage_Catalog_Model_Resource_Url->saveRewrite(Array, NULL)
#9 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(317): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), ‘/’, false)
#10 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(458): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), NULL, false)
#11 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(252): Mage_Catalog_Model_Url->refreshCategoryRewrite(’2’, ‘2’, false)
#12 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(246): Mage_Catalog_Model_Url->refreshRewrites(’2’)
#13 /var/www/magento/app/code/core/Mage/Catalog/Model/Indexer/Url.php(249): Mage_Catalog_Model_Url->refreshRewrites()
#14 /var/www/magento/app/code/core/Mage/Index/Model/Process.php(159): Mage_Catalog_Model_Indexer_Url->reindexAll()
#15 /var/www/magento/app/code/core/Mage/Index/Model/Process.php(187): Mage_Index_Model_Process->reindexAll()
#16 /var/www/magento/shell/indexer.php(158): Mage_Index_Model_Process->reindexEverything()
#17 /var/www/magento/shell/indexer.php(198): Mage_Shell_Compiler->run()
#18 {main}

Next exception ‘Zend_Db_Statement_Exception’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘category/13-1-2’ for key 3’ in /var/www/magento/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /var/www/magento/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /var/www/magento/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /var/www/magento/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /var/www/magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `co...’, Array)
#4 /var/www/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `co...’, Array)
#5 /var/www/magento/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `co...’, Array)
#6 /var/www/magento/app/code/core/Mage/Catalog/Model/Resource/Url.php(283): Zend_Db_Adapter_Abstract->insert(’core_url_rewrit...’, Array)
#7 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(290): Mage_Catalog_Model_Resource_Url->saveRewrite(Array, NULL)
#8 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(317): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), ‘/’, false)
#9 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(458): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), NULL, false)
#10 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(252): Mage_Catalog_Model_Url->refreshCategoryRewrite(’2’, ‘2’, false)
#11 /var/www/magento/app/code/core/Mage/Catalog/Model/Url.php(246): Mage_Catalog_Model_Url->refreshRewrites(’2’)
#12 /var/www/magento/app/code/core/Mage/Catalog/Model/Indexer/Url.php(249): Mage_Catalog_Model_Url->refreshRewrites()
#13 /var/www/magento/app/code/core/Mage/Index/Model/Process.php(159): Mage_Catalog_Model_Indexer_Url->reindexAll()
#14 /var/www/magento/app/code/core/Mage/Index/Model/Process.php(187): Mage_Index_Model_Process->reindexAll()
#15 /var/www/magento/shell/indexer.php(158): Mage_Index_Model_Process->reindexEverything()
#16 /var/www/magento/shell/indexer.php(198): Mage_Shell_Compiler->run()
#17 {main}

Checked Catalog -> URL Rewrite Management

Sorted the Target Path column and filtered for “category/13” (as there was sth with category/13-xxx in the log). So there where 2 rows, one for the default store and for our current store, however with different request paths. Corrected the path and now it’s running.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3215
Joined:  2009-02-26
Minneapolis MN
 

Did your upgrade complete? It seems that you may have had an error during your upgrade?

 
Magento Community Magento Community
Magento Community
Magento Community
 
barnholdy
Jr. Member
 
Total Posts:  3
Joined:  2011-06-10
 

I am experiencing the same problems as gatinho. Deleting the cache or session date doesn’t work for me either.
Running the PHP indexer script gives me the following exceptions:

Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [2002] No such file or directory’ in [...]/lib/Zend/Db/Adapter/Pdo/Abstract.php:129
Stack trace:
#0 [...]/lib/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct(’mysql:host=loca...’, ‘root’, ‘root’, Array)
#1 [...]/lib/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#2 [...]/lib/Varien/Db/Adapter/Pdo/Mysql.php(300): Zend_Db_Adapter_Pdo_Mysql->_connect()
#3 [...]/lib/Zend/Db/Adapter/Abstract.php(459): Varien_Db_Adapter_Pdo_Mysql->_connect()
#4 [...]/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’SET NAMES utf8’, Array)
#5 [...]/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query(’SET NA in [...]/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 144

I tried this with an updated version of 1.6. and a new installed one with old data imported in db.

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
gatinho
Member
 
Total Posts:  54
Joined:  2010-02-25
 

Well,

my problem is solved (see previous post). Your problem has a different cause. Do all the folders have the right permissions?

I performed the update as “root”. So I had to conclude the update with correcting the file permissions:

e.g. sth like “chown -R www-data:www-data /var/www/magento”
probably you also want to a chmod -R 750 ....

 
Magento Community Magento Community
Magento Community
Magento Community
 
barnholdy
Jr. Member
 
Total Posts:  3
Joined:  2011-06-10
 

Finally got it working!

I emptied the core_url_rewrite table and was able to rebuild the indices for the backend. Just to make sure I also reset the rights. Finally running the indexer worked for me on the server environment.
Rebuilding the indices locally with the PHP-script still gives me the exceptions above.

But thats ok for me smile

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3215
Joined:  2009-02-26
Minneapolis MN
 

@barnholdy:: How did you empty you table?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Andy_GS
Sr. Member
 
Total Posts:  126
Joined:  2010-05-21
 

Hello,

i’ve had this reindex fail for me as well on 1.6.0.0 CE

An error occurred while saving the URL rewrite

i saw this in the magento wiki:
http://www.magentocommerce.com/wiki/steps_to_solve_re-indexing_errors_in_magento_admin

but i’m not liking the looks of it as it seems a bit drastic that you have to manually delete stuff from the database in order to get it functioning again - so i havn’t tried this.

Did you guys come up with a solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
barnholdy
Jr. Member
 
Total Posts:  3
Joined:  2011-06-10
 

@Brent W Peterson

Bit late, but I used phpmyadmin gui. Was faster than using command line ui for me wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Djay
Jr. Member
 
Total Posts:  10
Joined:  2010-03-21
 

Hi,

The problem comes from the method _refreshProductRewrite() in the model Mage_Catalog_Model_Url

This condition was changed from Magento 1.4

// v. 1.4
$categoryId null;
if (
$category->getUrlPath()) {
    $categoryId 
$category->getId();
    
$updateKeys false;
}

to

// v. 1.6
$categoryId null;
if (
$category->getLevel() > 1{
    $categoryId 
$category->getId();
    
$updateKeys false;
}
So if you have a product in 2 (or more) categories (in the root category (level 1)), Magento’ll try to insert 2 times the sames datas..
So an exception is launch and kill the script (in Mage_Catalog_Model_Resource_Url)

public function saveRewrite($rewriteData$rewrite)
{
    
....
        try 
{
            $adapter
->insert($this->getMainTable(), $rewriteData);
        
catch (Exception $e{
            Mage
::logException($e);
            
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
        
}
    }
    
unset($rewriteData);

    return 
$this;
}

A simple correction is to launch the exception only if the datas contains a valid category_id :

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}
}

or use the previous conditon from 1.4 (not tested).

Djay

 
Magento Community Magento Community
Magento Community
Magento Community
 
hillzzz
Jr. Member
 
Total Posts:  8
Joined:  2009-01-30
Southampton UK
 

I had the URL indexing Processing issue after upgrading from 1.4.01 to 1.6.
I tried re-indexing from the admin screen and the URL Rewrite just hangs forever.
I tried re-indexing from the command line via ssh with

php shell/indexer.php reindexall

and it gave an error message on the URL-Rewrite index Error saving URL Re-Wite to database

The problem is I am running multiple stores on one instance of magento.

Then I had an idea I used phpmyadmin to truncate the core_url_rewrite table. Note I did not delete it I emptied the table that is I deleted all the rows but left the table structure intact.

Next I re-indexed from the command line again and it worked without errors. I tried re-indexing in the admin interface and again it worked without errors.

It appears to have fixed the problem

 
Magento Community Magento Community
Magento Community
Magento Community
 
webrgr
Jr. Member
 
Total Posts:  7
Joined:  2010-10-04
 

Spam / Advertising Harassment Language Other

 
Magento Community Magento Community
Magento Community
Magento Community
 
twotoofs
Jr. Member
 
Total Posts:  7
Joined:  2011-08-18
 
Djay - 10 October 2011 03:34 AM

Hi,

The problem comes from the method _refreshProductRewrite() in the model Mage_Catalog_Model_Url

This condition was changed from Magento 1.4

// v. 1.4
$categoryId null;
if (
$category->getUrlPath()) {
    $categoryId 
$category->getId();
    
$updateKeys false;
}

to

// v. 1.6
$categoryId null;
if (
$category->getLevel() > 1{
    $categoryId 
$category->getId();
    
$updateKeys false;
}
So if you have a product in 2 (or more) categories (in the root category (level 1)), Magento’ll try to insert 2 times the sames datas..
So an exception is launch and kill the script (in Mage_Catalog_Model_Resource_Url)

public function saveRewrite($rewriteData$rewrite)
{
    
....
        try 
{
            $adapter
->insert($this->getMainTable(), $rewriteData);
        
catch (Exception $e{
            Mage
::logException($e);
            
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
        
}
    }
    
unset($rewriteData);

    return 
$this;
}

A simple correction is to launch the exception only if the datas contains a valid category_id :

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}
}

or use the previous conditon from 1.4 (not tested).

Djay

Where do I find this?  I had my store moved from one domain to another and I’m getting this same problem.  I’ve been working on it for hours.

 
Magento Community Magento Community
Magento Community
Magento Community
 
twotoofs
Jr. Member
 
Total Posts:  7
Joined:  2011-08-18
 
hillzzz - 13 October 2011 01:58 PM

I had the URL indexing Processing issue after upgrading from 1.4.01 to 1.6.
I tried re-indexing from the admin screen and the URL Rewrite just hangs forever.
I tried re-indexing from the command line via ssh with

php shell/indexer.php reindexall

and it gave an error message on the URL-Rewrite index Error saving URL Re-Wite to database

The problem is I am running multiple stores on one instance of magento.

Then I had an idea I used phpmyadmin to truncate the core_url_rewrite table. Note I did not delete it I emptied the table that is I deleted all the rows but left the table structure intact.

Next I re-indexed from the command line again and it worked without errors. I tried re-indexing in the admin interface and again it worked without errors.

It appears to have fixed the problem

This seems to have worked.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrmeech
Member
 
Total Posts:  58
Joined:  2008-11-07
New York City, USA
 

Truncating the ‘core_url_rewrite’ table seems to have completely resolved this issue for me as well.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 3