1

I am working on an extension right now that needs to have a URL rewrite setup when it is installed. Is the best place to do this in a data install script? If not, where should this be done?

3

It's not a big difference.
From what I saw, how Magento does, if you plan to use direct inserts, place your script in the sql install script.
If you plan to use models and the internal model API you should put it in the data folder.
Here are some examples. In the customer module in sql/.../install-1.6.0.0.php there is this:

$installer->getConnection()->insertForce($installer->getTable('customer/customer_group'), array(
    'customer_group_id'     => 0,
    'customer_group_code'   => 'NOT LOGGED IN',
    'tax_class_id'          => 3
)); 

In the catalog model there is this in data/.../install-1.6.0.0.php:

Mage::getModel('catalog/category')
    ->load(1)
    ->setId(1)
    ->setStoreId(0)
    ->setPath(1)
    ->setLevel(0)
    ->setPosition(0)
    ->setChildrenCount(0)
    ->setName('Root Catalog')
    ->setInitialSetupFlag(true)
    ->save(); 

[EDIT]
I forgot one thing. The upgrade scripts are executed when the modules are initialized and the data upgrades are executed a little later after the current store is initialized, after the full config is loaded, the translates are already loaded and others.
Based on this you can see what works for you best.

  • Thanks Marius. Basically you are confirming that the data script is the correct place to put it, right? I will be using the rewrite API. – Joseph Leedy Jul 26 '13 at 19:49
  • I've updated the answer with some additional info. – Marius Jul 26 '13 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.