Commit a895a366 authored by webchick's avatar webchick
Browse files

#563106 by quicksketch, scor, andypost, ctmattice1, catch, yched, adrian: Fix...

#563106 by quicksketch, scor, andypost, ctmattice1, catch, yched, adrian: Fix critical upgrade path bugs from Drupal 6 to Drupal 7
parent 20bac50d
......@@ -178,6 +178,7 @@ function update_fix_d7_requirements() {
// Add the cache_path table.
$schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_path']['description'] = 'Cache table used for path alias lookups.';
db_create_table('cache_path', $schema['cache_path']);
// system_update_7042() renames columns, but these are needed to bootstrap.
// Add empty columns for now.
......@@ -250,6 +251,31 @@ function update_fix_d7_requirements() {
);
db_create_table('semaphore', $schema['semaphore']);
// Add registry tables since these are required during an update.
$schema['registry'] = array(
'fields' => array(
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'type' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('name', 'type'),
'indexes' => array(
'hook' => array('type', 'weight', 'module'),
),
);
$schema['registry_file'] = array(
'fields' => array(
'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('filename'),
);
db_create_table('registry', $schema['registry']);
db_create_table('registry_file', $schema['registry_file']);
$schema['date_format_type'] = array(
'description' => 'Stores configured date format types.',
'fields' => array(
......
......@@ -234,7 +234,7 @@ function filter_update_7004() {
// Enable all existing filters ({filter} contained only enabled previously).
db_update('filter')
->fields('status', '1')
->fields(array('status' => '1'))
->execute();
// Move filter settings from system variables into {filter}.settings.
......@@ -262,11 +262,11 @@ function filter_update_7004() {
}
}
if (!empty($settings)) {
db_upddate('filter')
->fields(array('settings' => serialize($settings)))
->condition('format', $filter->format)
->condition('name', $filter->name)
->execute();
db_update('filter')
->fields(array('settings' => serialize($settings)))
->condition('format', $filter->format)
->condition('name', $filter->name)
->execute();
}
}
}
......
......@@ -33,10 +33,9 @@ function locale_install() {
*/
/**
* Add context field and allow longer location.
* Add context field index and allow longer location.
*/
function locale_update_7000() {
db_add_field('locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
db_drop_index('locales_source', 'source');
db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));
db_change_field('locales_source', 'location', 'location', array('type' => 'text', 'size' => 'big', 'not null' => FALSE));
......
......@@ -369,6 +369,9 @@ function node_update_7000() {
->fields(array('module' => 'node_content'))
->condition('module', 'node')
->execute();
// Rename the module column to base.
db_change_field('node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
}
/**
......@@ -434,6 +437,8 @@ function node_update_7005() {
* Convert body and teaser from node properties to fields, and migrate status/comment/promote and sticky columns to the {node_revision} table.
*/
function node_update_7006(&$context) {
taxonomy_update_7002();
$context['#finished'] = 0;
// Get node type info for every invocation.
......@@ -461,6 +466,12 @@ function node_update_7006(&$context) {
else {
// Subsequent invocations.
// Save the field IDs for field_sql_storage_field_storage_write().
$title_field = field_info_field('title');
$title_field_id = $title_field['id'];
$body_field = field_info_field('body');
$body_field_id = $body_field['id'];
$found = FALSE;
if ($context['total']) {
// Operate on every revision of every node (whee!), in batches.
......@@ -507,7 +518,7 @@ function node_update_7006(&$context) {
$node->body[LANGUAGE_NONE][0]['format'] = !empty($revision->format) ? $revision->format : variable_get('filter_default_format', 1);
// This is a core update and no contrib modules are enabled yet, so
// we can assume default field storage for a faster update.
field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array());
field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array($title_field_id, $body_field_id));
}
// Migrate the status columns to the {node_revision} table.
......
......@@ -1853,30 +1853,7 @@ function system_update_7005() {
* longer needed.
*/
function system_update_7006() {
$schema['registry'] = array(
'fields' => array(
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'type' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('name', 'type'),
'indexes' => array(
'hook' => array('type', 'weight', 'module'),
),
);
$schema['registry_file'] = array(
'fields' => array(
'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('filename'),
);
db_create_table('registry', $schema['registry']);
db_create_table('registry_file', $schema['registry_file']);
registry_rebuild();
// Update moved to update_fix_d7_requirements().
}
/**
......
......@@ -208,26 +208,30 @@ function taxonomy_schema() {
}
/**
* Add vocabulary machine_name column.
* Add {vocabulary}.machine_name column.
*/
function taxonomy_update_7002() {
$field = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The vocabulary machine name.',
);
if (!variable_get('taxonomy_update_7002_done', FALSE)) {
$field = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The vocabulary machine name.',
);
db_add_field('taxonomy_vocabulary', 'machine_name', $field);
db_add_field('taxonomy_vocabulary', 'machine_name', $field);
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
$machine_name = 'vocabulary_' . $vid;
db_update('taxonomy_vocabulary')
->fields(array('machine_name' => 'vocabulary_' . $vid))
->condition('vid', $vid)
->execute();
field_attach_create_bundle('taxonomy_term', $machine_name);
}
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
$machine_name = 'vocabulary_' . $vid;
db_update('taxonomy_vocabulary')
->fields(array('machine_name' => 'vocabulary_' . $vid))
->condition('vid', $vid)
->execute();
field_attach_create_bundle('taxonomy_term', $machine_name);
variable_set('taxonomy_update_7002_done', TRUE);
}
}
......@@ -309,7 +313,7 @@ function taxonomy_update_7004() {
$field_name = 'taxonomy_' . $vocabulary->machine_name;
$field = array(
'field_name' => $field_name,
'type' => 'taxonomy_term',
'type' => 'taxonomy_term_reference',
'cardinality' => $vocabulary->multiple || $vocabulary->tags ? FIELD_CARDINALITY_UNLIMITED : 1,
'settings' => array(
'required' => $vocabulary->required ? TRUE : FALSE,
......@@ -410,7 +414,7 @@ function taxonomy_update_7005(&$sandbox) {
}
/**
* Add vocabulary machine_name column.
* Add {taxonomy_term_data}.format column.
*/
function taxonomy_update_7006() {
db_add_field('taxonomy_term_data', 'format', array(
......@@ -423,7 +427,7 @@ function taxonomy_update_7006() {
}
/**
* Add index on taxonomy_term_data.name column to speed up taxonomy_get_term_by_name().
* Add index on {taxonomy_term_data}.name column to speed up taxonomy_get_term_by_name().
*/
function taxonomy_update_7007() {
db_add_index('taxonomy_term_data', 'name', array('name'));
......
......@@ -427,13 +427,13 @@ function user_update_7004(&$sandbox) {
// Initialize batch update information.
$sandbox['progress'] = 0;
$sandbox['last_user_processed'] = -1;
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {user} WHERE picture <> ''")->fetchField();
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField();
}
// As a batch operation move the photos into the {file} table and update the
// {users} records.
$limit = 500;
$result = db_query_range("SELECT uid, picture FROM {user} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed']));
$result = db_query_range("SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed']));
foreach ($result as $user) {
// Don't bother adding files that don't exist.
if (!file_exists($user->picture)) {
......@@ -473,8 +473,8 @@ function user_update_7004(&$sandbox) {
// When we're finished, drop the old picture field and rename the new one to
// replace it.
if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) {
db_drop_field('user', 'picture');
db_change_field('user', 'picture_fid', 'picture', $picture_field);
db_drop_field('users', 'picture');
db_change_field('users', 'picture_fid', 'picture', $picture_field);
}
}
......
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