diff --git a/includes/update.inc b/includes/update.inc index cbee34e..e219116 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -121,6 +121,35 @@ function update_fix_d8_requirements() { } /** + * Helper function to install a new module in Drupal 8 via hook_update_N(). + */ +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 8000 here would be inconsistent + // since $module_update_8000() 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)) + ->execute(); + + system_list_reset(); + // @todo: figure out what to do about hook_install() and hook_enable(). + } +} + +/** * Perform one update and store the results for display on finished page. * * If an update function completes successfully, it should return a message