5 * Dump a Drupal 6 database into a Drupal 7 PHP script to test the upgrade
8 * Run this script at the root of an existing Drupal 6 installation.
10 * The output of this script is a PHP script that can be ran inside Drupal 7
11 * and recreates the Drupal 6 database as dumped. Transient data from cache
12 * session and watchdog tables are not recorded.
15 // Define default settings.
17 $_SERVER['HTTP_HOST'] = 'default';
18 $_SERVER['PHP_SELF'] = '/index.php';
19 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
20 $_SERVER['SERVER_SOFTWARE'] = NULL;
21 $_SERVER['REQUEST_METHOD'] = 'GET';
22 $_SERVER['QUERY_STRING'] = '';
23 $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
24 $_SERVER['HTTP_USER_AGENT'] = 'console';
27 include_once './includes/bootstrap.inc';
28 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
30 // Include the utility drupal_var_export() function.
31 include_once __DIR__ . '/../includes/utility.inc';
33 // Output the PHP header.
34 $output = <<<ENDOFHEADER
39 * Filled installation of Drupal 6.17, for test purposes.
41 * This file was generated by the dump-database-d6.sh tool, from an
42 * installation of Drupal 6, filled with data using the generate-d6-content.sh
43 * tool. It has the following modules installed:
47 foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
48 $output .= " * - $module\n";
52 // Get the current schema, order it by table name.
53 $schema = drupal_get_schema();
56 // Override the field type of the filename primary key to bypass the
57 // InnoDB 191 character limitation.
58 if (isset($schema['system']['primary key']) && $schema['system']['primary key'] == 'filename' && isset($schema['system']['fields']['filename']['type']) && $schema['system']['fields']['filename']['type'] == 'varchar') {
59 $schema['system']['fields']['filename']['type'] = 'varchar_ascii';
61 // Export all the tables in the schema.
62 foreach ($schema as $table => $data) {
63 // Remove descriptions to save time and code.
64 unset($data['description']);
65 foreach ($data['fields'] as &$field) {
66 unset($field['description']);
69 // Dump the table structure.
70 $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
72 // Don't output values for those tables.
73 if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
78 // Prepare the export of values.
79 $result = db_query('SELECT * FROM {'. $table .'}');
81 while ($record = db_fetch_array($result)) {
82 // users.uid is a serial and inserting 0 into a serial can break MySQL.
83 // So record uid + 1 instead of uid for every uid and once all records
84 // are in place, fix them up.
85 if ($table == 'users') {
88 $insert .= '->values('. drupal_var_export($record) .")\n";
91 // Dump the values if there are some.
93 $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
95 $output .= "->execute();\n";
98 // Add the statement fixing the serial in the user table.
99 if ($table == 'users') {
100 $output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";