Skip to content

Instantly share code, notes, and snippets.

@johnennewdeeson
Last active September 2, 2015 10:29
Show Gist options
  • Save johnennewdeeson/e5d77deaa5f45cb5de59 to your computer and use it in GitHub Desktop.
Save johnennewdeeson/e5d77deaa5f45cb5de59 to your computer and use it in GitHub Desktop.
Enabling modules in an update hook.
/**
* Enable modules.
* Normally we'd use master module for this but sometimes you can't run anything other than updb in production.
*/
function mymodule_update_7001(&$sandbox) {
$modules = array(
'mymodule_one',
'mymodule_two',
'mymodule_three',
);
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = count($modules);
}
$module = $modules[$sandbox['progress']];
module_enable(array($module));
drupal_flush_all_caches();
$sandbox['progress']++;
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment