magento-hackathon / firegento-contentsync

Share content between Magento installations through the file system (i.e. via Git)
42 stars 12 forks source link

Error: A page URL key "home" (id 2) for specified store already exists.. #2

Open amenk opened 11 years ago

amenk commented 11 years ago

I am getting this error:

Error: A page URL key "home" (id 2) for specified store already exists..

It is pretty much the standard Magento demo data.

mysql> select page_id, identifier from cms_page;
+---------+----------------------------------------+
| page_id | identifier                             |
+---------+----------------------------------------+
|       3 | about-magento-demo-store               |
|       4 | customer-service                       |
|       6 | enable-cookies                         |
|       2 | home                                   |
|       5 | home                                   |
|       1 | no-route                               |
|       7 | privacy-policy-cookie-restriction-mode |
+---------+----------------------------------------+
7 rows in set (0.00 sec)

mysql> select * from cms_page_store;
+---------+----------+
| page_id | store_id |
+---------+----------+
|       1 |        0 |
|       3 |        0 |
|       4 |        0 |
|       5 |        0 |
|       6 |        0 |
|       7 |        0 |
|       2 |        1 |
|       2 |        2 |
|       2 |        3 |
+---------+----------+
9 rows in set (0.00 sec)
amenk commented 11 years ago

Actually the original error message is "A page URL key for specified store already exists." - I just added more info to find out what's going on. But in fact, these seems to come from Magento core code...

avstudnitz commented 11 years ago

This can happen if you try to merge data from two systems with different IDs for a page with the same identifier (i.e. "home"). I experienced this too once. Could this be your problem too? At the moment, you should start from the same database for all shops. Any ideas on how to make this more robust? We have discussed getting rid of the need to use entity_ids for import, but can't see how to get around that (especially for content types like blocks and email templates which can be referenced by id)

amenk commented 11 years ago

I got this when checking on only one system. I am not sure if I did export or import first. But it was a almost clean Magento install. Have to check this with a completely clean Magento install again.

amenk commented 11 years ago

I can reproduce the issue in the current master, on a completely clean magento 1.7.0.2 with sample data, installed by n98-magerun.

First command after installation: php contentsync.php export

amenk commented 11 years ago

The problem is that I have a page "home" for store 0 which is disabled and another one for the stores which is enabled. This is valid (I just can not enable the other "home" page in the backend)

avstudnitz commented 11 years ago

Ah, thanks for the info, that clarifies things.

amenk commented 11 years ago

There is a workaround: Save both of those coexisting CMS home pages once - then it exports data. I am not 100% sure if my Magento installation is valid and if this is really a content sync bug.

amenk commented 11 years ago

Somehow it is a magento bug :-)

Mage_Cms_Model_Resource_Page::getIsUniquePageToStores

   public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object)
    {
        if (Mage::app()->isSingleStoreMode() || !$object->hasStores()) {
            $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
        } else {
            $stores = (array)$object->getData('stores');
        }

When contentsync saves the CMS page (in order to update the hash), $_data['stores'] is not set. When saving the CMS page from the admin interface, I think this comes from the admin form. So I think in my "special" (or not so special?) database constellation, I would guess that it is not possible to save this CMS page at all.

The question is if contentsync should work around that by filling the stores array from $_data['store_id']