Commit c54234d7 authored by Dries's avatar Dries
Browse files

- 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.
parent 7b5a8d93
......@@ -656,7 +656,7 @@ CREATE TABLE system (
status int(2) NOT NULL default '0',
throttle tinyint(1) DEFAULT '0' NOT NULL,
bootstrap int(2) NOT NULL default '0',
schema_version smallint(2) unsigned NOT NULL,
schema_version smallint(2) unsigned NOT NULL default 0,
PRIMARY KEY (filename)
) TYPE=MyISAM;
......@@ -818,20 +818,20 @@ CREATE TABLE watchdog (
-- Insert some default values
--
INSERT INTO system VALUES ('modules/block.module','block','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/filter.module','filter','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/help.module','help','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/menu.module','menu','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/system.module','system','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/user.module','user','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/watchdog.module','watchdog','module','',1,0,0,1);
INSERT INTO system VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine','', 1,0,0,1);
INSERT INTO system VALUES ('themes/bluemarine/page.tpl.php', 'bluemarine', 'theme', 'themes/engines/phptemplate/phptemplate.engine', 1,0,0,1);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/block.module', 'block', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/comment.module', 'comment', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/filter.module', 'filter', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/help.module', 'help', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/menu.module', 'menu', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/node.module', 'node', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/page.module', 'page', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/story.module', 'story', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/system.module', 'system', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/taxonomy.module', 'taxonomy', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/user.module', 'user', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/watchdog.module', 'watchdog', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/bluemarine/page.tpl.php', 'bluemarine', 'theme', 'themes/engines/phptemplate/phptemplate.engine', 1, 0, 0, 0);
INSERT INTO users (uid, name, mail) VALUES ('0', '', '');
INSERT INTO users_roles (uid, rid) VALUES (0, 1);
......@@ -841,8 +841,6 @@ INSERT INTO permission VALUES (1,'access content',0);
INSERT INTO role (rid, name) VALUES (2, 'authenticated user');
INSERT INTO permission VALUES (2,'access comments, access content, post comments, post comments without approval',0);
REPLACE variable SET name='update_start', value='s:10:"2005-03-21";';
REPLACE variable SET name='theme_default', value='s:10:"bluemarine";';
REPLACE blocks SET module = 'user', delta = '0', theme = 'bluemarine', status = '1';
......
......@@ -650,7 +650,7 @@ CREATE TABLE system (
status integer NOT NULL default '0',
throttle smallint NOT NULL default '0',
bootstrap integer NOT NULL default '0',
schema_version smallint NOT NULL default 1,
schema_version smallint NOT NULL default 0,
PRIMARY KEY (filename)
);
......@@ -814,22 +814,21 @@ CREATE TABLE watchdog (
-- Insert some default values
--
INSERT INTO system VALUES ('modules/block.module','block','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/filter.module','filter','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/help.module','help','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/menu.module','menu','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/system.module','system','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/user.module','user','module','',1,0,0,1);
INSERT INTO system VALUES ('modules/watchdog.module','watchdog','module','',1,0,0,1);
INSERT INTO system VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine','',1,0,0,1);
INSERT INTO system VALUES ('themes/bluemarine/page.tpl.php', 'bluemarine', 'theme', 'themes/engines/phptemplate/phptemplate.engine',1,0,0,1);
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2005-03-21";');
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/block.module', 'block', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/comment.module', 'comment', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/filter.module', 'filter', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/help.module', 'help', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/menu.module', 'menu', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/node.module', 'node', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/page.module', 'page', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/story.module', 'story', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/system.module', 'system', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/taxonomy.module', 'taxonomy', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/user.module', 'user', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('modules/watchdog.module', 'watchdog', 'module', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine', '', 1, 0, 0, 0);
INSERT INTO system (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/bluemarine/page.tpl.php', 'bluemarine', 'theme', 'themes/engines/phptemplate/phptemplate.engine', 1, 0, 0, 0);
INSERT INTO variable(name,value) VALUES('theme_default','s:10:"bluemarine";');
INSERT INTO users(uid,name,mail) VALUES(0,'','');
INSERT INTO users_roles(uid,rid) VALUES(0, 1);
......
<?php
// $Id$
define('SCHEMA', 0);
define('SCHEMA_MIN', 1);
// The system module (Drupal core) is currently a special case
include_once './database/updates.inc';
// Include install files for each module
foreach (module_list() as $module) {
$install_file = './'. drupal_get_path('module', $module) .'/'. $module .'.install';
if (is_file($install_file)) {
include_once $install_file;
}
}
/**
* 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 drupal_get_schema_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 drupal_get_installed_schema_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 drupal_set_installed_schema_version($module, $version) {
db_query("UPDATE {system} SET schema_version = %d WHERE name = '%s'", $version, $module);
}
......@@ -484,7 +484,7 @@ function system_check_directory($form_element) {
*/
function system_get_files_database(&$files, $type) {
// Extract current files from database.
$result = db_query("SELECT name, type, status, throttle FROM {system} WHERE type = '%s'", $type);
$result = db_query("SELECT name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
while ($file = db_fetch_object($result)) {
if (isset($files[$file->name]) && is_object($files[$file->name])) {
foreach ($file as $key => $value) {
......@@ -892,7 +892,7 @@ function system_modules() {
// Update the contents of the system table:
db_query("DELETE FROM {system} WHERE name = '%s' AND type = '%s'", $file->name, 'module');
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap, schema_version) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap, $file->schema_version);
}
......@@ -947,9 +947,13 @@ function theme_system_modules($form) {
function system_modules_submit($form_id, $edit) {
db_query("UPDATE {system} SET status = 0, throttle = 0 WHERE type = 'module'");
$new_modules = array();
foreach ($edit['status'] as $key => $choice) {
if ($choice) {
db_query("UPDATE {system} SET status = 1 WHERE type = 'module' AND name = '%s'", $key);
if (!module_exist($key)) {
$new_modules[] = $key;
}
}
}
......@@ -961,7 +965,18 @@ function system_modules_submit($form_id, $edit) {
}
}
module_list(TRUE, FALSE);
menu_rebuild();
include './includes/install.inc';
foreach ($new_modules as $module) {
// Set the installed schema version for newly-enabled modules
$versions = drupal_get_schema_versions($module);
if ($versions !== FALSE && drupal_get_installed_schema_version($module) == 0) {
drupal_set_installed_schema_version($module, max($versions));
}
}
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/modules');
}
......
......@@ -484,7 +484,7 @@ function system_check_directory($form_element) {
*/
function system_get_files_database(&$files, $type) {
// Extract current files from database.
$result = db_query("SELECT name, type, status, throttle FROM {system} WHERE type = '%s'", $type);
$result = db_query("SELECT name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
while ($file = db_fetch_object($result)) {
if (isset($files[$file->name]) && is_object($files[$file->name])) {
foreach ($file as $key => $value) {
......@@ -892,7 +892,7 @@ function system_modules() {
// Update the contents of the system table:
db_query("DELETE FROM {system} WHERE name = '%s' AND type = '%s'", $file->name, 'module');
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap, schema_version) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap, $file->schema_version);
}
......@@ -947,9 +947,13 @@ function theme_system_modules($form) {
function system_modules_submit($form_id, $edit) {
db_query("UPDATE {system} SET status = 0, throttle = 0 WHERE type = 'module'");
$new_modules = array();
foreach ($edit['status'] as $key => $choice) {
if ($choice) {
db_query("UPDATE {system} SET status = 1 WHERE type = 'module' AND name = '%s'", $key);
if (!module_exist($key)) {
$new_modules[] = $key;
}
}
}
......@@ -961,7 +965,18 @@ function system_modules_submit($form_id, $edit) {
}
}
module_list(TRUE, FALSE);
menu_rebuild();
include './includes/install.inc';
foreach ($new_modules as $module) {
// Set the installed schema version for newly-enabled modules
$versions = drupal_get_schema_versions($module);
if ($versions !== FALSE && drupal_get_installed_schema_version($module) == 0) {
drupal_set_installed_schema_version($module, max($versions));
}
}
drupal_set_message(t('The configuration options have been saved.'));
drupal_goto('admin/modules');
}
......
......@@ -1123,6 +1123,11 @@ function user_register_submit($form_id, $form_values) {
user_mail($mail, t('drupal user account details for %s', array('%s' => $name)), strtr(t("%username,\n\nYou may now login to %uri using the following username and password:\n\n username: %username\n password: %password\n\n%edit_uri\n\n--drupal"), $variables), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please make sure your website e-mail address is set properly under the general settings on the <a href="%settings">settings page</a>.</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass, '%settings' => url('admin/settings'))));
user_authenticate($account->name, trim($pass));
// Set the installed schema version of the system module to the most recent version.
include_once './includes/install.inc';
drupal_set_installed_schema_version('system', max(drupal_get_schema_versions('system')));
drupal_goto('user/1/edit');
}
else {
......
......@@ -1123,6 +1123,11 @@ function user_register_submit($form_id, $form_values) {
user_mail($mail, t('drupal user account details for %s', array('%s' => $name)), strtr(t("%username,\n\nYou may now login to %uri using the following username and password:\n\n username: %username\n password: %password\n\n%edit_uri\n\n--drupal"), $variables), "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
drupal_set_message(t('<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please make sure your website e-mail address is set properly under the general settings on the <a href="%settings">settings page</a>.</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass, '%settings' => url('admin/settings'))));
user_authenticate($account->name, trim($pass));
// Set the installed schema version of the system module to the most recent version.
include_once './includes/install.inc';
drupal_set_installed_schema_version('system', max(drupal_get_schema_versions('system')));
drupal_goto('user/1/edit');
}
else {
......
......@@ -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 @@ function update_access_denied_page() {
// 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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment