Why and how does this Magento1's saveRewrite function work?
OK, so looking at Magento 1's Mage_Catalog_Model_Resource_Url class, there's a function called saveRewrite. I understand how the core_url_rewrite table works: we add "request paths" which internally redirect to category/product pages based on the rules defined in that table. Let me make an example so this story has its head and tail. Let's say I have a category with an ID 56 and I want a path of "first/second/category-name.html" to take me to that category page. I'd have a row with this data in core_url_rewrite (only the important columns): store_id: 1 category_id: 56 product_id: NULL id_path: category/56 request_path: first/second/category-name.html target_path: catalog/category/view/id/56
Everything fine until now. If I type in mydomain.com/first/second/category-name.html, it's fine.
OK, so, let's move on. Let's say i now want my request path to be "third/category-name.html". I run this: Mage::getModel('catalog/url')->refreshCategoryRewrite($categoryId, $storeId, false);
What's going on here? Magento uses this to create a query which will update the core_url_rewrite table (change the request path value from the old one to the new one) - OR AT LEAST IT SHOULD DO THAT? However, in both the WHERE sql query clause and in the parameters part, it uses the column "target_path" but associates its values with those of "request_path". Basically, what this would do is generate a query which would look like this:
UPDATEcore_url_rewriteSETtarget_path= ? WHERE (target_path = 'first/second/category-name.html') AND (store_id = 1)
Of course, the ? part would resolve to 'third/category-name.html'.
So, what is going on here? How is this supposed to work? Of course, this does not work for me, so I was digging up a bit, going from function to function and saw this in the end. I just don't understand why did they use "target_path" instead of "request_path" here, which would basically solve everything. What am I missing?