1 update.inc update_module_enable(array $modules)

Helper function to install a new module in Backdrop 1.x via hook_update_N().

File

core/includes/update.inc, line 429
Backdrop site update API.

Code

function update_module_enable(array $modules) {
  foreach ($modules as $module) {
    // Check for initial schema and install it. The schema version of a newly
    // installed module is always 0. Using 1000 here would be inconsistent
    // since $module_update_1000() may involve a schema change, and we want
    // to install the schema as it was before any updates were added.
    $function = $module . '_schema_0';
    if (function_exists($function)) {
      $schema = $function();
      foreach ($schema as $table => $spec) {
        db_create_table($table, $spec);
      }
    }
    // Change the schema version from SCHEMA_UNINSTALLED to 0, so any module
    // updates since the module's inception are executed in a core upgrade.
    db_update('system')
      ->condition('type', 'module')
      ->condition('name', $module)
      ->fields(array('schema_version' => 0, 'status' => 1))
      ->execute();

    // system_list_reset() is in module.inc but that would only be available
    // once the variable bootstrap is done.
    require_once BACKDROP_ROOT . '/core/includes/module.inc';
    system_list_reset();
    // @todo: figure out what to do about hook_install() and hook_enable().
  }
}