1 |
85ad3d82
|
Assos Assos
|
#!/usr/bin/env php
|
2 |
|
|
<?php
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* Dump a Drupal 6 database into a Drupal 7 PHP script to test the upgrade
|
6 |
|
|
* process.
|
7 |
|
|
*
|
8 |
|
|
* Run this script at the root of an existing Drupal 6 installation.
|
9 |
|
|
*
|
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.
|
13 |
|
|
*/
|
14 |
|
|
|
15 |
|
|
// Define default settings.
|
16 |
|
|
$cmd = 'index.php';
|
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';
|
25 |
|
|
|
26 |
|
|
// Bootstrap Drupal.
|
27 |
|
|
include_once './includes/bootstrap.inc';
|
28 |
|
|
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
|
29 |
|
|
|
30 |
|
|
// Include the utility drupal_var_export() function.
|
31 |
|
|
include_once dirname(__FILE__) . '/../includes/utility.inc';
|
32 |
|
|
|
33 |
|
|
// Output the PHP header.
|
34 |
|
|
$output = <<<ENDOFHEADER
|
35 |
|
|
<?php
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
|
|
* @file
|
39 |
|
|
* Filled installation of Drupal 6.17, for test purposes.
|
40 |
|
|
*
|
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:
|
44 |
|
|
|
45 |
|
|
ENDOFHEADER;
|
46 |
|
|
|
47 |
|
|
foreach (module_list() as $module) {
|
48 |
|
|
$output .= " * - $module\n";
|
49 |
|
|
}
|
50 |
|
|
$output .= " */\n\n";
|
51 |
|
|
|
52 |
|
|
// Get the current schema, order it by table name.
|
53 |
|
|
$schema = drupal_get_schema();
|
54 |
|
|
ksort($schema);
|
55 |
|
|
|
56 |
|
|
// Export all the tables in the schema.
|
57 |
|
|
foreach ($schema as $table => $data) {
|
58 |
|
|
// Remove descriptions to save time and code.
|
59 |
|
|
unset($data['description']);
|
60 |
|
|
foreach ($data['fields'] as &$field) {
|
61 |
|
|
unset($field['description']);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
// Dump the table structure.
|
65 |
|
|
$output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
|
66 |
|
|
|
67 |
|
|
// Don't output values for those tables.
|
68 |
|
|
if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
|
69 |
|
|
$output .= "\n";
|
70 |
|
|
continue;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
// Prepare the export of values.
|
74 |
|
|
$result = db_query('SELECT * FROM {'. $table .'}');
|
75 |
|
|
$insert = '';
|
76 |
|
|
while ($record = db_fetch_array($result)) {
|
77 |
|
|
// users.uid is a serial and inserting 0 into a serial can break MySQL.
|
78 |
|
|
// So record uid + 1 instead of uid for every uid and once all records
|
79 |
|
|
// are in place, fix them up.
|
80 |
|
|
if ($table == 'users') {
|
81 |
|
|
$record['uid']++;
|
82 |
|
|
}
|
83 |
|
|
$insert .= '->values('. drupal_var_export($record) .")\n";
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
// Dump the values if there are some.
|
87 |
|
|
if ($insert) {
|
88 |
|
|
$output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
|
89 |
|
|
$output .= $insert;
|
90 |
|
|
$output .= "->execute();\n";
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
// Add the statement fixing the serial in the user table.
|
94 |
|
|
if ($table == 'users') {
|
95 |
|
|
$output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
$output .= "\n";
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
print $output; |