Description
This issue is automatically created based on existing pull request: #32808: Do not trigger url rewrites re-generation for all store views
Description (*)
During creating a new website, Store Group and Store view using php bin/magento setup:upgrade
- we noticed that some URL rewrites for categories on different stores were re-generated in DB, that's absolutely not obvious and for sure not expected behavior. Such behavior, especially for us changed URLs for some categories w/o creating any redirect from old -> new URL (for some reason, we had incorrect url_path values in DB, that's another story).
As a result of this issue - some advertised categories started returning 404 pages, and we basically started burning our money.
Root cause analyze
Investigation showed, that app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php
plugin was executed due to 2 step saving of group:
- at first, we just creating a new group
- later we're assigning it to a website
magento2/app/code/Magento/Store/Model/Config/Importer/Processor/Create.php
Lines 165 to 195 in 6729b6e
As a store group still don't have any store IDs assigned (the store will be created on the next step) - $group->getStoreIds()
returns an empty array, we're setting this value to the category and trying to generate URL rewrites
Then it goes to this method, which tries to fetch a list of store Ids:
Here we don't have any saved store_ids
, so it fetches the list of stores where this category used as a root.
magento2/app/code/Magento/Catalog/Model/Category.php
Lines 534 to 570 in 68c7282
As a result - we're re-generating category URL rewrites for all store views with the same root category ID.
Related Pull Requests
Fixed Issues (if relevant)
- Fixes magento/magento2#<issue_number>
Manual testing scenarios (*)
- Install magento, so you'll have 1 website, 1 store group, 1 store view
- Create some categories structure
- Run
php bin/magento app:config:dump scopes
to dump all the stores data into the config.php - Create a DB dump
- Go to Admin, and create a new website, store group and a store view (re-use the same root category for that)
- Run
php bin/magento app:config:dump scopes
to dump all the stores data into the config.php, save the file - Apply the DB dump from the step 4 in order to emulate the case, when we didn't have 2nd website, store group, etc
- Run
php bin/magento setup:upgrade
orphp bin/magento app:config:import
to create a new website, store group, store view - Compare data in the
url_rewrites
table with a backup file for the store 1.
Expected result:
✔ URL rewrites for store 1 shouldn't be touched when we creating a new website / store group / store view
Actual result:
❌ URL rewrites for store 1 are re-generated when we creating a new website / store group / store view
Questions or comments
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)