Simpler Alternative to Install Profile
I was thinking about calling this article "Install Profile Considered Harmful". I know a lot of good people have put a lot of work into this feature, but as of Drupal 6 it seems to be a tar pit. People get excited about creating an install profile, waste some time banging their heads against it, and just move on. It is likely to keep improving, but for the present moment, you can do everything many of the things an install profile does, quicker and easier, by just creating an install module. Here's how.
First, create a new module. Let's call it myinstall. Then list all of the modules you want included and enabled as dependencies. This is the array that you would have returned in my_profile_modules(), except it can handle all modules .install files.
myinstall.info
<?php
name = My Install
description = My Custom Install Profile as a module.
package = "1st Step"
core = 6.x
dependencies[] = contact
dependencies[] = ...
?>Now create your myinstall.module file with two functions. The first one uses hook_init to call the second function, and then disable itself.
<?php
function myinstall_init() {
drupal_set_message("My Install: Doing the installation.");
drupal_set_message(myinstall_install());
module_disable(array('myinstall'));
drupal_set_message("My Install: Done with installation. Turning off.");
}
?>Then put all the stuff that would have gone into my_profile_final into myinstall_install.
<?php
function myinstall_install() {
$msg = array();
// Here are a couple of examples:
// set up an admin role, and tell adminrole to use it
if (!variable_get('adminrole_adminrole', false)) {
db_query("INSERT INTO {role} (name) VALUES ('admin')");
variable_set('adminrole_adminrole', '3'); // admin will be the 3rd option
adminrole_update_perms();
$msg[] = "Setup an admin role.";
}
// setup admin theme.
variable_set('admin_theme', "garland");
$msg[] = "Admin Theme: set to Garland.";
// Add more here
return '<ul><li>' . implode('</li><li>', $msg). '</li></ul>';
?>There you go. Install this module on your new Drupal 6 site and go to admin/build/modules. It will be the first item in the list, and it will tell you all the modules that you need to install. I haven't tested it, but you might be able to then use Drush to pull them all down at once. Either way, once you have all the required modules install, enable My Install. Smile and say yes when it asks you if you want to enable all it's dependencies. That is it.
The best thing about this method (aside from it actually working) is that it makes it easy to test of parts of the install independently. You can have multiple function and toss in a myinstall_menu hook with callbacks to each one. Be sure to comment out the module_disable while you are testing.
There's a couple of things missing in my mind
And that’s a directory for files relating only to the install profile,
and the ability to select the install profile from the installation.
If i have 100 sites, each having one of 10 profiles, I don’t want all
the modules for all the profiles in all the sites, I want to be able
to separate concerns.
My install profiles tend to have custom installation and configuration
wizards and lots of things that should really happen as part of
installation (one of the things the Tasks list is great for).
Modules and install profiles actually have much more in common
than not, which is why I’m not a fan of the separate API’s for them.
What is now a .profile should be a .install, and the profile should be
able to have code that is loaded into memory at all times, and access
to the form_alter hooks etc.
This has meant that almost all profiles have needed to have a .module
companion so far, which is just dumb.
Fair enough. I updated the
Fair enough. I updated the article to reflect the fact that there are somethings you can do in an install profile that you can’t do with this simple install module approach.
Circle is round
And then you enable this module from your install profile and the circle is round :)
Sadly, I don’t think that
Sadly, I don’t think that would work. The reason I started exploring this is that there is a bug/limitation in Drupal 6 that prevents certain modules from being loaded correctly by hook_profile_modules.
Yes
Yes.
What’s the hard part? All the crufty db queries in system.module and elsewhere, where we don’t have functions to install a “base” Drupal, we just poke the database.
So, install profiles as modules for D7, please :P Can even do dependencies and stuff, where a module == a package (e.g. multiblog_install.module depends on awesomeblog_install.module).
Don’t worry about “I know a lot of good people have put a lot of work into this feature” — ‘cause it’s not true. There is very little there. Very few people have done any work on improving this for core. And it, like all other core features, will continue to not improve until someone cares.
I meant to mention the that
I meant to mention the that Install Profile API (http://drupal.org/project/install_profile_api) you and Nate have been working on has lots of promise. I am actually using a hacked up version of the Profile Wizard to generate code to put in the _install function.
Port API
Looks like we’re working on the same problems. I’d love to get your opinion on http://groups.drupal.org/node/14395
Very clever!
This actually looks a lot simpler than the install profile thing – and for a start, a great many more of us are going to be knowledgeable about the syntax of this kind of module, as opposed to the different format expected by the install profile.
I think I’ll give this a try!
Amen!
Amen to this. I feel like Drupal is often robust enough to skip relying on helpers and simple directly code what you need, and this is an excellent example.
As a sidenote, I’ve been pondering rolling a patch for SimpleTest that will allow the use of fixtures for testing, ala Django (with JSON on the filesystem as the main fixture storage mechanism). If I spin that out as a module, one could consume a fixture during the install hook and have a super lightweight install profile system.
Thought about it, never tried it.
That’s interesting… I was playing with this idea (see http://jeff.viapositiva.net/archives/2008/10/power-people-new-approach-d... ) but actually never tried it – thanks for posting.
What concretely are you using this approach for? Just as an alternative to install profiles or for actually packaging feature sets for web site building?
I am just using this
I am just using this locally. I have been kicking out a bunch of Drupal 6 sites lately, and I hate wasting time doing the same configuration steps every time. And the Drupal 6 modules page seems to be a lot slower that the Drupal 5 one. Probably because it now rebuilds and caches tons of stuff, like the menu.