#838438 by Damien Tournoud, chx: Added basic tests for D6 => D7 upgrade path, and framework for further extending upgrade test coverage. W00t! :D
parent
8ef7c6fb8d
commit
029e7b8828
|
@ -0,0 +1,59 @@
|
|||
<?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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,347 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Perform end-to-end tests of the upgrade path.
|
||||
*/
|
||||
abstract class UpgradePathTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* The file path to the dumped database to load into the child site.
|
||||
*/
|
||||
var $databaseDumpFile = NULL;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether the child site has been upgraded.
|
||||
*/
|
||||
var $upgradedSite = FALSE;
|
||||
|
||||
/**
|
||||
* Array of errors triggered during the upgrade process.
|
||||
*/
|
||||
var $upgradeErrors = array();
|
||||
|
||||
/**
|
||||
* Override of DrupalWebTestCase::setUp() specialized for upgrade testing.
|
||||
*/
|
||||
protected function setUp() {
|
||||
global $db_prefix, $user, $language, $conf, $databases;
|
||||
|
||||
// Reset flags.
|
||||
$this->upgradedSite = FALSE;
|
||||
$this->upgradeErrors = array();
|
||||
|
||||
// Store necessary current values before switching to prefixed database.
|
||||
$this->originalLanguage = $language;
|
||||
$this->originalLanguageDefault = variable_get('language_default');
|
||||
$this->originalPrefix = $db_prefix;
|
||||
$this->originalFileDirectory = file_directory_path();
|
||||
$this->originalProfile = drupal_get_profile();
|
||||
$clean_url_original = variable_get('clean_url', 0);
|
||||
|
||||
// Generate temporary prefixed database to ensure that tests have a clean starting point.
|
||||
$db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
|
||||
db_update('simpletest_test_id')
|
||||
->fields(array('last_prefix' => $db_prefix_new))
|
||||
->condition('test_id', $this->testId)
|
||||
->execute();
|
||||
$db_prefix = $db_prefix_new;
|
||||
|
||||
// Unregister the registry.
|
||||
// This is required to make sure that the database layer works properly.
|
||||
spl_autoload_unregister('drupal_autoload_class');
|
||||
spl_autoload_unregister('drupal_autoload_interface');
|
||||
|
||||
// Create test directories ahead of installation so fatal errors and debug
|
||||
// information can be logged during installation process.
|
||||
// Use mock files directories with the same prefix as the database.
|
||||
$public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10);
|
||||
$private_files_directory = $public_files_directory . '/private';
|
||||
$temp_files_directory = $private_files_directory . '/temp';
|
||||
|
||||
// Create the directories.
|
||||
file_prepare_directory($public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
||||
file_prepare_directory($private_files_directory, FILE_CREATE_DIRECTORY);
|
||||
file_prepare_directory($temp_files_directory, FILE_CREATE_DIRECTORY);
|
||||
$this->generatedTestFiles = FALSE;
|
||||
|
||||
// Log fatal errors.
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_log', $public_files_directory . '/error.log');
|
||||
|
||||
// Reset all statics and variables to perform tests in a clean environment.
|
||||
$conf = array();
|
||||
|
||||
// Load the database from the portable PHP dump.
|
||||
require $this->databaseDumpFile;
|
||||
|
||||
// Set path variables.
|
||||
$this->variable_set('file_public_path', $public_files_directory);
|
||||
$this->variable_set('file_private_path', $private_files_directory);
|
||||
$this->variable_set('file_temporary_path', $temp_files_directory);
|
||||
|
||||
$this->pass('Finished loading the dump.');
|
||||
|
||||
// Load user 1.
|
||||
$this->originalUser = $user;
|
||||
drupal_save_session(FALSE);
|
||||
$user = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => 1))->fetchObject();
|
||||
|
||||
// Generate and set a session cookie.
|
||||
$this->curlInitialize();
|
||||
$sid = drupal_hash_base64(uniqid(mt_rand(), TRUE) . drupal_random_bytes(55));
|
||||
curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode($this->session_name) . '=' . rawurlencode($sid));
|
||||
|
||||
// Force our way into the session of the child site.
|
||||
drupal_save_session(TRUE);
|
||||
_drupal_session_write($sid, '');
|
||||
drupal_save_session(FALSE);
|
||||
|
||||
// Restore necessary variables.
|
||||
$this->variable_set('clean_url', $clean_url_original);
|
||||
$this->variable_set('site_mail', 'simpletest@example.com');
|
||||
|
||||
drupal_set_time_limit($this->timeLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of DrupalWebTestCase::tearDown() specialized for upgrade testing.
|
||||
*/
|
||||
protected function tearDown() {
|
||||
global $db_prefix, $user, $language;
|
||||
|
||||
// In case a fatal error occured that was not in the test process read the
|
||||
// log to pick up any fatal errors.
|
||||
$db_prefix_temp = $db_prefix;
|
||||
$db_prefix = $this->originalPrefix;
|
||||
simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE);
|
||||
$db_prefix = $db_prefix_temp;
|
||||
|
||||
if (preg_match('/simpletest\d+/', $db_prefix)) {
|
||||
// Delete temporary files directory.
|
||||
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10));
|
||||
|
||||
// Remove all prefixed tables (all the tables in the schema).
|
||||
$tables = db_find_tables($this->originalPrefix . '%');
|
||||
foreach ($tables as $table) {
|
||||
db_drop_table($table);
|
||||
}
|
||||
|
||||
// Return the database prefix to the original.
|
||||
$db_prefix = $this->originalPrefix;
|
||||
|
||||
// Return the user to the original one.
|
||||
$user = $this->originalUser;
|
||||
drupal_save_session(TRUE);
|
||||
|
||||
// Ensure that internal logged in variable and cURL options are reset.
|
||||
$this->loggedInUser = FALSE;
|
||||
$this->additionalCurlOptions = array();
|
||||
|
||||
// Reload module list and implementations to ensure that test module hooks
|
||||
// aren't called after tests.
|
||||
module_list(TRUE);
|
||||
module_implements('', FALSE, TRUE);
|
||||
|
||||
// Reset the Field API.
|
||||
field_cache_clear();
|
||||
|
||||
// Rebuild caches.
|
||||
parent::refreshVariables();
|
||||
|
||||
// Reset language.
|
||||
$language = $this->originalLanguage;
|
||||
if ($this->originalLanguageDefault) {
|
||||
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
|
||||
}
|
||||
|
||||
// Close the CURL handler.
|
||||
$this->curlClose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialized variable_set() that works even if the child site is not upgraded.
|
||||
*
|
||||
* @param $name
|
||||
* The name of the variable to set.
|
||||
* @param $value
|
||||
* The value to set. This can be any PHP data type; these functions take care
|
||||
* of serialization as necessary.
|
||||
*/
|
||||
protected function variable_set($name, $value) {
|
||||
db_delete('variable')
|
||||
->condition('name', $name)
|
||||
->execute();
|
||||
db_insert('variable')
|
||||
->fields(array(
|
||||
'name' => $name,
|
||||
'value' => serialize($value),
|
||||
))
|
||||
->execute();
|
||||
|
||||
try {
|
||||
cache_clear_all('variables', 'cache');
|
||||
cache_clear_all('variables', 'cache_bootstrap');
|
||||
}
|
||||
// Since cache_bootstrap won't exist in a Drupal 6 site, ignore the
|
||||
// exception if the above fails.
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialized refreshVariables().
|
||||
*/
|
||||
protected function refreshVariables() {
|
||||
// No operation if the child has not been upgraded yet.
|
||||
if (!$this->upgradedSite) {
|
||||
return parent::refreshVariables();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the upgrade.
|
||||
*
|
||||
* @param $register_errors
|
||||
* Register the errors during the upgrade process as failures.
|
||||
* @return
|
||||
* TRUE if the upgrade succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function performUpgrade($register_errors = TRUE) {
|
||||
$update_url = $GLOBALS['base_url'] . '/update.php';
|
||||
|
||||
// Load the first update screen.
|
||||
$this->drupalGet($update_url, array('external' => TRUE));
|
||||
if (!$this->assertResponse(200)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Continue.
|
||||
$this->drupalPost(NULL, array(), t('Continue'));
|
||||
if (!$this->assertResponse(200)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Go!
|
||||
$this->drupalPost(NULL, array(), t('Apply pending updates'));
|
||||
if (!$this->assertResponse(200)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Check for errors during the update process.
|
||||
foreach ($this->xpath('//li[@class=:class]', array(':class' => 'failure')) as $element) {
|
||||
$message = strip_tags($element->asXML());
|
||||
$this->upgradeErrors[] = $message;
|
||||
if ($register_errors) {
|
||||
$this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->upgradeErrors)) {
|
||||
// Upgrade failed, the installation might be in an inconsistent state,
|
||||
// don't process.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Check if there still are pending updates.
|
||||
$this->drupalGet($update_url, array('external' => TRUE));
|
||||
$this->drupalPost(NULL, array(), t('Continue'));
|
||||
if (!$this->assertText(t('No pending updates.'), t('No pending updates at the end of the update process.'))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Upgrade succeed, rebuild the environment so that we can call the API
|
||||
// of the child site directly from this request.
|
||||
$this->upgradedSite = TRUE;
|
||||
|
||||
// Reload module list and implementations.
|
||||
module_list(TRUE);
|
||||
module_implements('', FALSE, TRUE);
|
||||
|
||||
// Rebuild caches.
|
||||
drupal_static_reset();
|
||||
drupal_flush_all_caches();
|
||||
|
||||
// Register actions declared by any modules.
|
||||
actions_synchronize();
|
||||
|
||||
// Reload global $conf array and permissions.
|
||||
$this->refreshVariables();
|
||||
$this->checkPermissions(array(), TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform basic upgrade tests.
|
||||
*
|
||||
* Load a bare installation of Drupal 6 and run the upgrade process on it.
|
||||
*
|
||||
* The install only contains dblog (although it's optional, it's only so that
|
||||
* another hook_watchdog module can take its place, the site is not functional
|
||||
* without watchdog) and update.
|
||||
*/
|
||||
class BasicUpgradePath extends UpgradePathTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Basic upgrade path',
|
||||
'description' => 'Basic upgrade path tests.',
|
||||
'group' => 'Upgrade path',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
// Path to the database dump.
|
||||
$this->databaseDumpFile = drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.bare.database.php';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a failed upgrade, and verify that the failure is reported.
|
||||
*/
|
||||
public function testFailedUpgrade() {
|
||||
// Destroy a table that the upgrade process needs.
|
||||
db_drop_table('access');
|
||||
// Assert that the upgrade fails.
|
||||
$this->assertFalse($this->performUpgrade(FALSE), t('A failed upgrade should return messages.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a successful upgrade.
|
||||
*/
|
||||
public function testBasicUpgrade() {
|
||||
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
|
||||
|
||||
// Hit the frontpage.
|
||||
$this->drupalGet('');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Verify that we are still logged in.
|
||||
$this->drupalGet('user');
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertEqual($this->getUrl(), url('user/1/edit', array('absolute' => TRUE)), t('We are still logged in as admin at the end of the upgrade.'));
|
||||
|
||||
// Logout and verify that we can login back in with our initial password.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin((object) array(
|
||||
'uid' => 1,
|
||||
'name' => 'admin',
|
||||
'pass_raw' => 'admin',
|
||||
));
|
||||
|
||||
// Test that the site name is correctly displayed.
|
||||
$this->assertText('Drupal 6', t('The site name is correctly displayed.'));
|
||||
|
||||
// Verify that the main admin sections are available.
|
||||
$this->drupalGet('admin');
|
||||
$this->assertText(t('Content'));
|
||||
$this->assertText(t('Appearance'));
|
||||
$this->assertText(t('People'));
|
||||
$this->assertText(t('Configuration'));
|
||||
$this->assertText(t('Reports'));
|
||||
$this->assertText(t('Structure'));
|
||||
$this->assertText(t('Modules'));
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
#!/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;
|
Loading…
Reference in New Issue