-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RewriteController to allow easy handling of historic rewrites #37
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine. Can be merged @pkarw :). I will replace 500 with 404 if no route found in another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Nils, thank you for the PR! I appreciate the new feature.
Left a tiny request to improve performance.
|
||
$reader = Mage::getSingleton('core/resource')->getConnection('core_read'); | ||
$select = $reader->select() | ||
->from('core_url_rewrite', ['target_path'])->where('request_path = ?', $requestPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a LIMIT 1
to the query to improve performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly thought that ->fetchOne() would do exactly like that but you get surprised by magento/Zend/Varien internals every now and then:) Limiting beforehand now introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, it really sucks :/
Thanks!
Though using fetchOne() returns the expcted result it is internally limiting the result after querying it in full so this could lead to performance impact on bigger cataloges to prevent this we added the limitation directly to the sql query.
As core_url_rewrite stores rewrites based on store_id and request_path we need both to identify a correct target. Added lookup of default store_id=0 to the request to handle unspecific redirects at all. Order by is needed to ensure, if default and store specific rewrites are found, the default one is skipped and the more specific is used.
Added more specific http-status codes for different types of possible results as 500 was not really the correct one to use.
Also added store_id handling as this could also be an issue and we added more specific result-status codes to reflect on what really was the problem instead of only returning 200 and especially 500. |
Improved store_id values in sql where
Formatting
$select = $reader->select() | ||
->from('core_url_rewrite', ['target_path']) | ||
->where('request_path = ?', $requestPath) | ||
->where('store_id IN (?)', [Mage_Core_Model_App::ADMIN_STORE_ID, (int)Mage::app()->getStore()->getId()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally avoid using the globally set store id, had some issues in the past with having the wrong store.
might we require it to be set in the URL as param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here i think we should have both, the Mage::app()->getStore()->getId()
as a fallback when no storeId is set in the request?
Like for example:
$storeId = $this->getRequest()->getParam('storeId');
if (empty($storeId)) {
$storeId = (int)Mage::app()->getStore()->getId();
}
What do you think about that? @sandermangel
Do we still have open issues here? |
Any update on this one? |
Here I have found a small Problem. I will Update the PR in the next days. |
@ResuBaka hi! any update on the PR changes? |
I will update in the next days. The problem is that I need to send the request URLs html encoded. |
Added a new controller to be able to access the old rewrites vsf-api knows nothing about. It simply makes a DB call to core_url_rewrite, filtered by request_path and returns only the new final target.
Usage
Simply called by /vsbridge/rewrite/target?request_path=old_url this returns {"code":200,"result":"target_path"}
As we agreed with Łukasz Romanowicz on slack we should bring this functionality to the main magento1 trunk.