0

I'd like a module to install some content, for instance add some static blocks to the CMS section when the module is installed (I know how to do this).

It'd only be PHP and Magento stuff, there's no direct need for SQL, no database table, nothing like that.

So a generic PHP script that configures Magento the right way, but only during installs or upgrades of that particular module.

I know I could use the Setup Resource mysql4-install-#.#.#.php script method for this, but that just feels plain wrong.

Any ideas?

Kara
  • 6,115
  • 16
  • 50
  • 57
pancake
  • 1,923
  • 2
  • 21
  • 42

2 Answers2

3

This is an appropriate usage - you are working with the database if you are adding or updating CMS. In fact, it's how the initial homepage fixture data is implemented.

Note that in CE >= 1.6 and EE >= 1.11 there is a complete DDL which should be used: ALTER TABLE in Magento setup script without using SQL

Community
  • 1
  • 1
benmarks
  • 23,384
  • 1
  • 62
  • 84
  • ah, fixtures! that was the term I should have been using all along. Can you PLEASE tell me something about the data folder in which the initial homepage fixture data is located (as opposed to the 'sql' folder which I was planning on using)? I have never seen this before, and I can't find any info on it on the web. This is exactly the thing I need. – pancake Feb 02 '12 at 15:59
  • It's new as of CE1.6/EE1.11. There have been data-install and data-upgrade scripts since 1.4.something. They work in the same way as original install and upgrade scripts, but were previously differentiated by filename (eg. `mysql4-data-install-versionnum.php`). The only sign diff between regular and data setup scripts is that the latter are triggered after the store object has been loaded. See `Mage_Core_Model_Resource_Setup::applyAllDataUpdates()` and `Mage_Core_Model_App::run()`. – benmarks Feb 02 '12 at 18:09
1

Thats not wrong at all. The setup resource is there to perform one-time-only actions. I personally think that that is a perfect use of the Install resource. You don't have to use it to do direct DB queries. You can also use it to make indirect DB queries (which is what you're doing when you add new content to the CMS)

Max
  • 8,671
  • 4
  • 33
  • 46
  • But the fact that it's called mysql4-install-#.#.#.php which is located in sql/ is just because it's DB stuff *most* of the time? The 'sql' and the 'mysql4' is what needs to be emphasized here. – pancake Feb 02 '12 at 14:39