In our last episode of enabling new modules via update.php, Steve McKenzie pointed me to a better method: module_enable(). A quick test found, however, that it didn't run the install files, and didn't rebuild the module files cache. So after spending 5 minutes in system.module, I found all the missing pieces. The example update function below will install and enable the new module, as well as rebuild all the css, node type, and menu caches. In simple language, it does everything that happens when the modules admin page is submitted. Enjoy.
<?php
function example_update_1() {
$ret = array();
// your array of modules you wish to enable and install in the update
$modules = array('some_module', 'some_other_module');
// You must rebuild the module cache for the system table to see the modules
module_rebuild_cache();
// enable modules first
module_enable($modules);
// now run their install files
drupal_install_modules($modules);
// other magic functions that are only called when admin/build/modules form is submitted
menu_rebuild();
node_types_rebuild();
drupal_clear_css_cache();
// just a report for the install page -- otherwise this update will show up as "FAILED"
$ret[] = array('success' => true, 'query' => "enabled some module, and some other module");
return $ret;
}
?>
Comments
thanks for your post! I have
thanks for your post!
I have question.
I tried to install module this way. worked fine.
But if i try to fill module's table with records it failes. It seems drupal doesn't see new module's table.
i was installing "upload.module".
What can be the problem?
Drush
Drush already has a significant amount of package management features, which allows you to
even install modules straight from cvs.
Someone consider installing
Someone consider installing modules straight from CVS potential dangerous.
Install (Drush) vs Enable (this)
Potentially complementary solutions, not competing.
benjamin, Agaric Design Collective
YAY!
I never get mentioned by ANYONE :)
I actually just reviewed the project where I was doing this and forgot to mention about the drupal_install_modules() function.
The other stuff I wasn't doing though so this is great to know.
Thanks Nick.
Btw.. the math question captcha is always saying I'm wrong on first try but 7 + 3 IS 10!!!
How can that be, you're
How can that be, you're everywhere. Its rude to talk only about one's self! (unless your in politics, or a non-profit)
And.. The captcha does not lie. Perhaps you lack the perspective of the captcha.
7 + 3 is not always 10 -- do not question the captcha's wisdom, or face its wrath. (ill see about fixing that).
Nice.
I wonder if this could be put in Drush...
Post new comment