Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Getting magento to read mysql-setup files (eg like installation) PLEASE HELP
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

I’ve been trying to get an answer to these for over a week now, am I really this dumb?

#1: HOW do you get magento to read the setup files if the module is one you’ve been developing using that installation?  There’s no ‘installation’ needed so how can you get the database changes you want?  Is it automatically done based on the version number in config.xml?

#2: How can you add a completely new table to the database if you need one for your new module? 

#3: How do you set up the backend admin interface for a new module? 

Is everyone out there just reading code and figuring it out that way?  Or just apeing what they find in the files for the core modules?

I get the feeling that i’m doing it wrong but don’t know how to do it right!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 
zburnham - 03 March 2008 11:42 AM

I’ve been trying to get an answer to these for over a week now, am I really this dumb?

#1: HOW do you get magento to read the setup files if the module is one you’ve been developing using that installation?  There’s no ‘installation’ needed so how can you get the database changes you want?  Is it automatically done based on the version number in config.xml?
#2: How can you add a completely new table to the database if you need one for your new module? 

Yep, I got stuck on this and had to get an explanation from Moshe.  So, it’s my turn to spread the wisdom.

Table “core_resource” contains all the installed modules and their version numbers.  If a module is executed and it has no entry in core_resource, then the system tries to find the module’s “sql/modname_setup/mysql-install-1.6.0.php file.  The shell of this file is like this:

$installer $this;
/* @var $installer Mage_Catalog_Model_Entity_Setup */
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {
$this->getTable('customeradv_rma')};
CREATE TABLE {
$this->getTable('customeradv_rma')} (
  `customeradv_rma_id` int(10) unsigned NOT NULL auto_increment,
  `customer_id` int(10) unsigned NOT NULL default '0',
  `store_id` smallint(5) unsigned NOT NULL default '0',
  `sales_order_entity_id` smallint(5) unsigned NOT NULL default '0',
  `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
  `updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
  `is_active` tinyint(1) unsigned NOT NULL default '1',
  `rma_request` tinytext NOT NULL default '',
  PRIMARY KEY  (`customeradv_rma_id`),
  KEY `FK_catalog_category_ENTITY_STORE` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='RMA Requests';
    "
);
$installer->endSetup();

All of your SQL goes into 1 huge string and the $installer parses it up into multiple queries.  Use $this->getTable(’table’) so that the end user can specify a table prefix at install time.  While you’re developing, if you need to run this file again, just remove your module from core_resource.

If the module is found, but the version number in the config file is less than the version number in the database a matching “upgrade-1.6.0-1.6.0.php file is called.  I haven’t done one of these yet.

zburnham - 03 March 2008 11:42 AM

#3: How do you set up the backend admin interface for a new module?

I don’t know.  But I’ve seen some other posts dealing with this.

zburnham - 03 March 2008 11:42 AM

Is everyone out there just reading code and figuring it out that way?  Or just apeing what they find in the files for the core modules?

Yep and Yep.  A little bit of both.  You have to figure out some of the code to know even where to start, but if you find something that does the job you can just copy it without really understanding what it’s doing.  Luckily, it’s part of my job to write these modules so I’m spending all day tracing through this stuff.  I could probably count on 1 hand the number of people that I know are seriously working in module development.  So, don’t feel bad, you’re not the only one feeling in the dark.  The light will shine on documentation once 1.0 comes out.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 
Mark_Kimsal - 03 March 2008 01:39 PM

I don’t know.  But I’ve seen some other posts dealing with this.

As have I, but it remains a little opaque to me.  If you’re developing modules, you must have had to address this at some point; any help is appreciated.  Code samples would be most helpful.

Mark_Kimsal - 03 March 2008 01:39 PM

zburnham - 03 March 2008 11:42 AM

Is everyone out there just reading code and figuring it out that way?  Or just apeing what they find in the files for the core modules?

Yep and Yep.  A little bit of both.  You have to figure out some of the code to know even where to start, but if you find something that does the job you can just copy it without really understanding what it’s doing.  Luckily, it’s part of my job to write these modules so I’m spending all day tracing through this stuff.  I could probably count on 1 hand the number of people that I know are seriously working in module development.  So, don’t feel bad, you’re not the only one feeling in the dark.  The light will shine on documentation once 1.0 comes out.

I hope to $deity it does, this is the stupidest a block of code has ever made me feel.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

OH, and by the way, the core_modules thing is what I had been looking for, thank you very much.

*prays for documentation*

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top