During the past days we have had some problems when updating our Magento custom modules. Oddly, even though we created the mysql4-upgrade file and edited the config.xml with the new version, the upgrade script wouldn’t run. Why? We don’t know.

But we needed a quick solution because there was an important issue in the production server. We finally decided to create a custom setup script to edit one of the attributes. So here is how you can simulate the Magento module $setup from your custom script (I’m assuming that you’re creating your php script in the Mageto root directory.

Note that when you call the model/resourcemodel you need, you have to add the ‘core_setup’ parameter. If it is not added, then the script won’t work:


<?php

require_once 'app/Mage.php';

umask(0);
Mage::app('admin');

$setup = Mage::getResourceModel('catalog/setup', 'core_setup');
$setup->startSetup();

/** Do whatever you need to do here */

$setup->endSetup();

?>
Categories: Development

1 Comment

Roman · July 7, 2012 at 8:37 am

This is a good practice to use this script , we can check modules on conflict if for example we are doing rewrites

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.