Index: update.php =================================================================== RCS file: /cvs/drupal/drupal/update.php,v retrieving revision 1.316 diff -u -p -r1.316 update.php --- update.php 3 Feb 2010 18:16:22 -0000 1.316 +++ update.php 5 Feb 2010 19:48:14 -0000 @@ -323,7 +323,7 @@ function update_check_requirements() { // Some unavoidable errors happen because the database is not yet up-to-date. // Our custom error handler is not yet installed, so we just suppress them. -ini_set('display_errors', FALSE); +#ini_set('display_errors', FALSE); // We prepare a minimal bootstrap for the update requirements check to avoid // reaching the PHP memory limit. Index: includes/update.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/update.inc,v retrieving revision 1.34 diff -u -p -r1.34 update.inc --- includes/update.inc 4 Feb 2010 17:03:19 -0000 1.34 +++ includes/update.inc 5 Feb 2010 20:31:16 -0000 @@ -274,25 +274,23 @@ function update_fix_d7_requirements() { 'not null' => TRUE, 'default' => -1) ); - db_change_field('system', 'status', 'status', array( - 'type' => 'int', 'not null' => TRUE, 'default' => 0)); - db_change_field('system', 'weight', 'weight', array( - 'type' => 'int', 'not null' => TRUE, 'default' => 0)); - db_change_field('system', 'bootstrap', 'bootstrap', array( - 'type' => 'int', 'not null' => TRUE, 'default' => 0)); + db_change_field('system', 'status', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); + db_change_field('system', 'weight', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); + db_change_field('system', 'bootstrap', 'bootstrap', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); // Drop and recreate 6.x indexes. db_drop_index('system', 'bootstrap'); - db_add_index('system', 'bootstrap', array( - 'status', 'bootstrap', array('type', 12), 'weight', 'name')); + db_add_index('system', 'bootstrap', array('status', 'bootstrap', array('type', 12), 'weight', 'name')); db_drop_index('system' ,'modules'); - db_add_index('system', 'modules', array(array( - 'type', 12), 'status', 'weight', 'name')); + db_add_index('system', 'modules', array(array('type', 12), 'status', 'weight', 'name')); db_drop_index('system', 'type_name'); db_add_index('system', 'type_name', array(array('type', 12), 'name')); + // Add 7.x indexes. - db_add_index('system', 'system_list', array('weight', 'name')); + if (!db_index_exists('system', 'system_list')) { + db_add_index('system', 'system_list', array('weight', 'name')); + } // Add the cache_path table. $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache'); @@ -301,21 +299,33 @@ function update_fix_d7_requirements() { // system_update_7042() renames columns, but these are needed to bootstrap. // Add empty columns for now. - db_add_field('url_alias', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); - db_add_field('url_alias', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + if (!db_column_exists('url_alias', 'source')) { + db_add_field('url_alias', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } + if (!db_column_exists('url_alias', 'alias')) { + db_add_field('url_alias', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } // Add new columns to {menu_router}. - db_add_field('menu_router', 'delivery_callback', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); - db_add_field('menu_router', 'context', array( - 'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - )); + if (!db_column_exists('menu_router', 'delivery_callback')) { + db_add_field('menu_router', 'delivery_callback', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } + if (!db_column_exists('menu_router', 'context')) { + db_add_field('menu_router', 'context', array( + 'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + )); + } db_drop_index('menu_router', 'tab_parent'); db_add_index('menu_router', 'tab_parent', array(array('tab_parent', 64), 'weight', 'title')); - db_add_field('menu_router', 'theme_callback', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); - db_add_field('menu_router', 'theme_arguments', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + if (!db_column_exists('menu_router', 'theme_callback')) { + db_add_field('menu_router', 'theme_callback', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } + if (!db_column_exists('menu_router', 'theme_arguments')) { + db_add_field('menu_router', 'theme_arguments', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } // Add the role_permission table. $schema['role_permission'] = array( @@ -384,6 +394,8 @@ function update_fix_d7_requirements() { 'hook' => array('type', 'weight', 'module'), ), ); + db_create_table('registry', $schema['registry']); + $schema['registry_file'] = array( 'fields' => array( 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE), @@ -392,7 +404,6 @@ function update_fix_d7_requirements() { ), 'primary key' => array('filename'), ); - db_create_table('registry', $schema['registry']); db_create_table('registry_file', $schema['registry_file']); $schema['date_format_type'] = array( @@ -420,6 +431,7 @@ function update_fix_d7_requirements() { ), 'primary key' => array('type'), ); + db_create_table('date_format_type', $schema['date_format_type']); $schema['date_formats'] = array( 'description' => 'Stores configured date formats.', @@ -453,6 +465,7 @@ function update_fix_d7_requirements() { 'primary key' => array('dfid'), 'unique keys' => array('formats' => array('format', 'type')), ); + db_create_table('date_formats', $schema['date_formats']); $schema['date_format_locale'] = array( 'description' => 'Stores configured date formats for each locale.', @@ -478,9 +491,6 @@ function update_fix_d7_requirements() { ), 'primary key' => array('type', 'language'), ); - - db_create_table('date_format_type', $schema['date_format_type']); - db_create_table('date_formats', $schema['date_formats']); db_create_table('date_format_locale', $schema['date_format_locale']); // Add the queue table. @@ -528,6 +538,10 @@ function update_fix_d7_requirements() { ); db_create_table('queue', $schema['queue']); + // Rename old sequences table from D5, if it still exists. + if (db_column_exists('sequences', 'name')) { + db_rename_table('sequences', 'sequences_old'); + } // Create the sequences table. $schema['sequences'] = array( 'description' => 'Stores IDs.', @@ -542,12 +556,16 @@ function update_fix_d7_requirements() { 'primary key' => array('value'), ); db_create_table('sequences', $schema['sequences']); + // Initialize the table with the maximum current increment of the tables // that will rely on it for their ids. - $max_aid = db_query('SELECT MAX(aid) FROM {actions_aid}')->fetchField(); - $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField(); - $max_batch_id = db_query('SELECT MAX(bid) FROM {batch}')->fetchField(); - db_insert('sequences')->fields(array('value' => max($max_aid, $max_uid, $max_batch_id)))->execute(); + $count = db_query('SELECT 1 FROM {sequences}'); + if (!$count) { + $max_aid = db_query('SELECT MAX(aid) FROM {actions_aid}')->fetchField(); + $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField(); + $max_batch_id = db_query('SELECT MAX(bid) FROM {batch}')->fetchField(); + db_insert('sequences')->fields(array('value' => max($max_aid, $max_uid, $max_batch_id)))->execute(); + } // Add column for locale context. if (db_table_exists('locales_source')) { Index: includes/database/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/database.inc,v retrieving revision 1.94 diff -u -p -r1.94 database.inc --- includes/database/database.inc 29 Jan 2010 01:59:32 -0000 1.94 +++ includes/database/database.inc 5 Feb 2010 20:32:35 -0000 @@ -2446,13 +2446,15 @@ function db_field_names($fields) { /** * Check if an index exists. * + * @param $table + * The name of a table to check. * @param $name * Index name. * @return * TRUE if the given index exists, otherwise FALSE. */ -function db_index_exists($name) { - return Database::getConnection()->schema()->indexExists($name); +function db_index_exists($table, $name) { + return Database::getConnection()->schema()->indexExists($table, $name); } /**