Commit 029e7b88 authored by webchick's avatar webchick

#838438 by Damien Tournoud, chx: Added basic tests for D6 => D7 upgrade path,...

#838438 by Damien Tournoud, chx: Added basic tests for D6 => D7 upgrade path, and framework for further extending upgrade test coverage. W00t! :D
parent 8ef7c6fb
<?php
// $Id$
/**
* @file
* Miscellaneous functions.
*/
/**
* Drupal-friendly var_export().
*
* @param $var
* The variable to export.
* @param $prefix
* A prefix that will be added at the begining of every lines of the output.
* @return
* The variable exported in a way compatible to Drupal's coding standards.
*/
function drupal_var_export($var, $prefix = '') {
if (is_array($var)) {
if (empty($var)) {
$output = 'array()';
}
else {
$output = "array(\n";
// Don't export keys if the array is non associative.
$export_keys = array_values($var) != $var;
foreach ($var as $key => $value) {
$output .= ' ' . ($export_keys ? drupal_var_export($key) . ' => ' : '') . drupal_var_export($value, ' ', FALSE) . ",\n";
}
$output .= ')';
}
}
else if (is_bool($var)) {
$output = $var ? 'TRUE' : 'FALSE';
}
else if (is_string($var)) {
$line_safe_var = str_replace("\n", '\n', $var);
if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
// If the string contains a line break or a single quote, use the
// double quote export mode. Encode backslash and double quotes and
// transform some common control characters.
$var = str_replace(array('\\', '"', "\n", "\r", "\t"), array('\\\\', '\"', '\n', '\r', '\t'), $var);
$output = '"' . $var . '"';
}
else {
$output = "'" . $var . "'";
}
}
else {
$output = var_export($var, TRUE);
}
if ($prefix) {
$output = str_replace("\n", "\n$prefix", $output);
}
return $output;
}
......@@ -393,13 +393,27 @@ function block_update_7004() {
system_rebuild_theme_data();
}
/**
* Update the {block_custom}.format column.
*/
function block_update_7005() {
// It was previously possible for a value of "0" to be stored in database
// tables to indicate that a particular piece of text should be filtered
// using the default text format.
$default_format = variable_get('filter_default_format', 1);
db_update('block_custom')
->fields(array('format' => $default_format))
->condition('format', 0)
->execute();
}
/**
* Recreates cache_block table.
*
* Converts fields that hold serialized variables from text to blob.
* Removes 'headers' column.
*/
function block_update_7005() {
function block_update_7006() {
$schema = system_schema_cache_7054();
db_drop_table('cache_block');
......
......@@ -139,19 +139,6 @@ function filter_install() {
variable_set('filter_fallback_format', $plain_text_format->format);
}
/**
* Implements hook_update_dependencies().
*/
function filter_update_dependencies() {
// Filter update 7005 migrates block data and therefore needs to run after
// the {block_custom} table is properly set up.
$dependencies['filter'][7005] = array(
'taxonomy' => 7002,
);
return $dependencies;
}
/**
* @defgroup updates-6.x-to-7.x Filter updates from 6.x to 7.x
* @{
......@@ -321,7 +308,6 @@ function filter_update_7004() {
* in cases that used to rely on a single site-wide default.
*/
function filter_update_7005() {
// Move role data from the filter system to the user permission system.
$all_roles = array_keys(user_roles());
$default_format = variable_get('filter_default_format', 1);
......@@ -380,22 +366,6 @@ function filter_update_7005() {
->condition('format', $default_format)
->execute();
// It was previously possible for a value of "0" to be stored in database
// tables to indicate that a particular piece of text should be filtered
// using the default text format. Therefore, we have to convert all such
// instances (in Drupal core) to explicitly use the appropriate format.
// Note that the update of the node body field is handled separately, in
// node_update_7006(), as is the update of the comment body field, in
// comment_update_7013().
foreach (array('block_custom' => 'format', 'users' => 'signature_format') as $table => $column) {
if (db_table_exists($table)) {
db_update($table)
->fields(array($column => $default_format))
->condition($column, 0)
->execute();
}
}
// We do not delete the 'filter_default_format' variable, since other modules
// may need it in their update functions.
// @todo This variable can be deleted in Drupal 8.
......
......@@ -38,3 +38,4 @@ files[] = tests/theme.test
files[] = tests/unicode.test
files[] = tests/update.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
This diff is collapsed.
This diff is collapsed.
......@@ -323,6 +323,23 @@ function user_install() {
}
}
/**
* Implements hook_update_dependencies().
*/
function user_update_dependencies() {
// Run all the critical user upgrades before everything.
$dependencies['system'][7000] = array(
'user' => 7008,
);
// user_update_7006 relies on filter_update_7002.
// TODO: move user_update_7006 down below in the upgrade process.
$dependencies['user'][7006] = array(
'filter' => 7002,
);
return $dependencies;
}
/**
* @defgroup user-updates-6.x-to-7.x User updates from 6.x to 7.x
* @{
......@@ -639,6 +656,20 @@ function user_update_7009() {
db_change_field('users', 'data', 'data', $spec);
}
/**
* Update the {user}.signature_format column.
*/
function user_update_7010() {
// It was previously possible for a value of "0" to be stored in database
// tables to indicate that a particular piece of text should be filtered
// using the default text format.
$default_format = variable_get('filter_default_format', 1);
db_update('users')
->fields(array('signature_format' => $default_format))
->condition('signature_format', 0)
->execute();
}
/**
* @} End of "defgroup user-updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
#!/usr/bin/env php
<?php
// $Id$
/**
* Dump a Drupal 6 database into a Drupal 7 PHP script to test the upgrade
* process.
*
* Run this script at the root of an existing Drupal 6 installation.
*
* The output of this script is a PHP script that can be ran inside Drupal 7
* and recreates the Drupal 6 database as dumped. Transient data from cache
* session and watchdog tables are not recorded.
*/
// Define default settings.
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Include the utility drupal_var_export() function.
include_once dirname(__FILE__) . '/../includes/variable.inc';
// Output the PHP header.
$output = "<?php\n\n";
// Get the current schema, order it by table name.
$schema = drupal_get_schema();
ksort($schema);
// Export all the tables in the schema.
foreach ($schema as $table => $data) {
// Remove descriptions to save time and code.
unset($data['description']);
foreach ($data['fields'] as &$field) {
unset($field['description']);
}
// Dump the table structure.
$output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
// Don't output values for those tables.
if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
$output .= "\n";
continue;
}
// Prepare the export of values.
$result = db_query('SELECT * FROM {'. $table .'}');
$insert = '';
while ($record = db_fetch_array($result)) {
// users.uid is a serial and inserting 0 into a serial can break MySQL.
// So record uid + 1 instead of uid for every uid and once all records
// are in place, fix them up.
if ($table == 'users') {
$record['uid']++;
}
$insert .= '->values('. drupal_var_export($record) .")\n";
}
// Dump the values if there are some.
if ($insert) {
$output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
$output .= $insert;
$output .= "->execute();\n";
}
// Add the statement fixing the serial in the user table.
if ($table == 'users') {
$output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";
}
$output .= "\n";
}
print $output;
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