diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-12-08 08:40:10 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-12-08 08:40:10 +0000 |
commit | c54234d71a6f1a6857e74ffd1e76e5e0604833de (patch) | |
tree | 05bc03c2079a8760734982ef765677f8c9b9847f /update.php | |
parent | 7b5a8d936cbc856020318928d50e73078ee4c679 (diff) | |
download | brdo-c54234d71a6f1a6857e74ffd1e76e5e0604833de.tar.gz brdo-c54234d71a6f1a6857e74ffd1e76e5e0604833de.tar.bz2 |
- Patch #40341 by Neil: fixed problems with database schema versions.
- When user #1 creates an account (we can assume this happens only once), system.module's schema version is set to the latest availiable.
- system_get_files_database() now includes a 'schema_version' child of each file object.
- That new information is re-saved when Drupal re-populates the system table.
- An array of newly-enabled modules is built, module_list() is reloaded, and the schema versions of each newly-enabled module are set to the most recent availiable. If the schema version is already set (presumably from a previous installation) it is not changed.
Diffstat (limited to 'update.php')
-rw-r--r-- | update.php | 93 |
1 files changed, 9 insertions, 84 deletions
diff --git a/update.php b/update.php index b3a79a844..fb8730718 100644 --- a/update.php +++ b/update.php @@ -18,24 +18,6 @@ $access_check = TRUE; -define('SCHEMA', 0); -define('SCHEMA_MIN', 1); - -/** - * Includes install files. - */ -function update_include_install_files() { - // The system module (Drupal core) is currently a special case - include_once './database/updates.inc'; - - foreach (module_list() as $module) { - $install_file = './'. drupal_get_path('module', $module) .'/'. $module .'.install'; - if (is_file($install_file)) { - include_once $install_file; - } - } -} - function update_sql($sql) { $result = db_query($sql); return array('success' => $result !== FALSE, 'query' => check_plain($sql)); @@ -204,7 +186,7 @@ function update_fix_schema_version() { break; } - update_set_installed_version('system', $sql_updates[$update_start]); + drupal_set_installed_schema_version('system', $sql_updates[$update_start]); variable_del('update_start'); } } @@ -220,7 +202,7 @@ function update_fix_schema_version() { function update_fix_sessions() { $ret = array(); - if (update_get_installed_version('system') < 130 && !variable_get('update_sessions_fixed', FALSE)) { + if (drupal_get_installed_schema_version('system') < 130 && !variable_get('update_sessions_fixed', FALSE)) { if ($GLOBALS['db_type'] == 'mysql') { db_query("ALTER TABLE {sessions} ADD cache int(11) NOT NULL default '0' AFTER timestamp"); } @@ -240,7 +222,7 @@ function update_fix_sessions() { * when update 142 is removed. It is part of the Drupal 4.6 to 4.7 migration. */ function update_fix_watchdog() { - if (update_get_installed_version('system') < 142 && !variable_get('update_watchdog_fixed', FALSE)) { + if (drupal_get_installed_schema_version('system') < 142 && !variable_get('update_watchdog_fixed', FALSE)) { switch ($GLOBALS['db_type']) { case 'pgsql': $ret = array(); @@ -269,64 +251,7 @@ function update_data($module, $number) { $_SESSION['update_results'][$module][$number] = $ret; // Update the installed version - update_set_installed_version($module, $number); -} - -/** - * Returns an array of availiable schema versions for a module. - * - * @param $module - * A module name. - * @return - * If the module has updates, an array of available updates. Otherwise, - * FALSE. - */ -function update_get_versions($module) { - if (!($max = module_invoke($module, 'version', SCHEMA))) { - return FALSE; - } - if (!($min = module_invoke($module, 'version', SCHEMA_MIN))) { - $min = 1; - } - return range($min, $max); -} - -/** - * Returns the currently installed schema version for a module. - * - * @param $module - * A module name. - * @return - * The currently installed schema version. - */ -function update_get_installed_version($module, $reset = FALSE) { - static $versions; - - if ($reset) { - unset($versions); - } - - if (!$versions) { - $versions = array(); - $result = db_query("SELECT name, schema_version FROM {system} WHERE type = 'module'"); - while ($row = db_fetch_object($result)) { - $versions[$row->name] = $row->schema_version; - } - } - - return $versions[$module]; -} - -/** - * Update the installed version information for a module. - * - * @param $module - * A module name. - * @param $version - * The new schema version. - */ -function update_set_installed_version($module, $version) { - db_query("UPDATE {system} SET schema_version = %d WHERE name = '%s'", $version, $module); + drupal_set_installed_schema_version($module, $number); } function update_selection_page() { @@ -343,13 +268,13 @@ function update_selection_page() { ); foreach (module_list() as $module) { if (module_hook($module, 'version')) { - $updates = drupal_map_assoc(update_get_versions($module)); + $updates = drupal_map_assoc(drupal_get_schema_versions($module)); $updates[] = 'No updates available'; $form['start'][$module] = array( '#type' => 'select', '#title' => t('%name module', array('%name' => $module)), - '#default_value' => array_search(update_get_installed_version($module), $updates) + 1, + '#default_value' => array_search(drupal_get_installed_schema_version($module), $updates) + 1, '#options' => $updates, ); } @@ -375,8 +300,8 @@ function update_update_page() { // Set the installed version so updates start at the correct place. $_SESSION['update_remaining'] = array(); foreach ($_POST['edit']['start'] as $module => $version) { - update_set_installed_version($module, $version - 1); - $max_version = max(update_get_versions($module)); + drupal_set_installed_schema_version($module, $version - 1); + $max_version = max(drupal_get_schema_versions($module)); if ($version <= $max_version) { foreach (range($version, $max_version) as $update) { $_SESSION['update_remaining'][] = array('module' => $module, 'version' => $update); @@ -541,7 +466,7 @@ drupal_maintenance_theme(); // Access check: if (($access_check == FALSE) || ($user->uid == 1)) { - update_include_install_files(); + include_once './includes/install.inc'; update_fix_schema_version(); update_fix_sessions(); |