Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the new Magento1.13 EE URL rewrites work/ How do the new database tables relate to each other?

I've been playing with the Magento 1.13 code for a few hours, and I'm having trouble understanding what they have done with URL rewrites. I was hoping that someone who has looked into this could point me in the right direction.

I noticed that core_url_rewrite is no longer being used (or at least by default it is empty and any new products and categories I add aren't being reflected in the core_url_rewrite table). Instead, they are being added to the new enterprise_url_rewrite table.

This was pretty straightforward, however, I noticed the addition of quite a few other tables (i.e. enterprise_url_rewrite_category_cl, enterprise_url_rewrite_product_cl, enterprise_url_rewrite_redirect_cl, enterprise_url_rewrite_redirect_rewrite) . I reverse engineered the tables using MySQL Workbench and I came up with the following EER diagram:

enter image description here

The above EER diagram doesn't show the connection between enterprise_url_rewrite_redirect and enterprise_url_rewrite, but there is (at least I assume) a relationship between the two managed in the enterprise_url_rewrite_redirect_rewrite table. My questions are about what the other tables do. They each have a version_id as a primary key and a redirect_id or entity_id foreign key. The enterprise_url_rewrite_redirect_cl foreign key I assume relates to the enterprise_url_rewrite_redirect primary key.

My first question is what this table's purpose even is? I don't see how it could be helpful. I did a project wide search for the table and couldn't find where it is even being created let alone used. Forgive me if the answer to this question is obvious.

My second question has to do with the enterprise_url_rewrite_product_cl and enterprise_url_rewrite_category_cl tables. It seems that these two tables both have entity_ids. I was wondering if anyone has any idea of what these entity_ids could be referring to?

I also noticed from the code that the typical way of accessing models has been changed. As an example, Line 781 of Enterprise/AdminGws/Model/Controllers.php has the following code change:

From:

$object = Mage::getModel('core/url_rewrite')->load($id);

To:

$object = Mage::getSingleton('core/factory')->getUrlRewriteInstance()->load($id);

Now, from Mage_Core_Model_Factory:

const XML_PATH_URL_REWRITE_MODEL = 'global/url_rewrite/model';
. . .
public function getUrlRewriteInstance()
{
    return $this->getModel($this->getUrlRewriteClassAlias());
}
. . .
    public function getUrlRewriteClassAlias()
{
    return (string)$this->_config->getNode(self::XML_PATH_URL_REWRITE_MODEL);
}

We see that the XML Path is global/url_rewrite/model. If we look at the matching Config.xml:

    <url_rewrite>
        <model>core/url_rewrite</model>
    </url_rewrite>

Finally, looking into Mage/Core/Model/Url/Rewrite.php, I found the following two functions:

 /**
 * Implement logic of custom rewrites
 . . . 
 * @deprecated since 1.7.0.2. Refactored and moved to Mage_Core_Controller_Request_Rewrite
 */

public function rewrite( . . .) { . . .

And

/**
 * Prepare and return QUERY_STRING
. . .
 * @deprecated since 1.7.0.2. Refactored and moved to Mage_Core_Controller_Request_Rewrite
 */
protected function_getQueryString() { . . .

The comments seem to imply that a Mage_Core_Controller_Request_Rewrite class should exist, but there is no such class in Mage/Core/Controller/Request. I was able to find that the Magento team is probably referring to Mage_Core_Model_Url_Rewrite_Request (I'm guessing they just forgot to change the comment. I tried to run through this in the debugger, but it keeps on crashing for reasons that are unknown to me. I keep getting the following log:

a:5:{i:0;s:77:"Invalid method Mage_Core_Controller_Varien_Front::_getRequestPath(Array
(
)
)";i:1;s:611:"#0 xdebug://debug-eval(1): Varien_Object->__call('_getRequestPath', Array)
1 xdebug://debug-eval(1): Mage_Core_Controller_Varien_Front->_getRequestPath()
2 C:\user\emil\projects\magento\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(1    67): Mage_Core_Controller_Varien_Front::dispatch()
3 C:\user\emil\projects\magento\magento\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
4 C:\user\emil\projects\magento\magento\app\Mage.php(683): Mage_Core_Model_App->run(Array)
5 C:\user\emil\projects\magento\magento\index.php(87): Mage::run('', 'store')
6 {main}";s:3:"url";s:14:"/magento/admin";s:11:"script_name";s:18:"/magento/index.php";s:4:"skin";s:7:"default";}

The above issue only occurs when I enter debug mode. Overall, I tried to go through the code to try and make sense of how the new rewrite works but ultimately came up empty handed and got stuck. I've searched Google and haven't come up with much. I was wondering if anyone has done any research on how the new version of Magento EE works for URL rewrites yet?

Thank you.

Emil

like image 569
Emil Stewart Avatar asked Jun 07 '13 20:06

Emil Stewart


1 Answers

It's difficult to answer your question, as the new Enterprise URL rewrite module has undergone and is still undergoing very significant changes. A stable version is expected with the next release (1.13.0.2), but until then, no one outside of the Magento core team can tell you exactly how the rewrite module will look and work.

The gist of the new setup, though, is that Magento now pulls rewrites from enterprise_url_rewrite, and all the other tables you identify are used to rebuild it during the reindexing process.

All the releated tables ending in _cl are change logs that are tied to database triggers.

like image 196
giaour Avatar answered Nov 12 '22 08:11

giaour