Enabling New Modules Via Update.php

01.16.2008

UPDATE: There's a better way.

I work with 3 other developers, all of whom have their own local sandbox of our site. Since we're constantly adding new modules, I found a simple way to enable a new module via another module's .install file. That way, all we have to do is run update.php when we update our source tree.

Here's a simple example update function:

<?php

function some_enabled_module_update_1() {
 
$ret = array();
  switch (
$GLOBALS['db_type']) {
    case
'mysqli':
    case
'mysql':
     
//this function tells drupal to update its file directories, and insert records for any new modules it sees.
     
module_rebuild_cache();
     
$ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'some_completely_new_module'");
      break;
  }
  return
$ret;
}
;
?>

The major limitation of this method is that it doesn't run the new modules install file. I can live with that. It beats always bugging other developers to see if the build needs a new module enabled. I'm sure there's a workaround for that anyhow.

Comments

module_enable

how come you didn't just use module_enable() ?

I do this as well. It can save time plus we're devs and why go into an admin page in the side when we can just code it?

That's a great question! Now

That's a great question! Now I will.

sooo

with that modification in place, will it also run the install file?

No. Here's the complete

No. Here's the complete "full monty" solution that I just wrote up.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options