6 * Dumps a Drupal 7 database into a Drupal 7 PHP script to test the upgrade
9 * Run this script at the root of an existing Drupal 7 installation.
11 * The output of this script is a PHP script that can be run inside Drupal 7
12 * and recreates the Drupal 7 database as dumped. Transient data from cache,
13 * session, and watchdog tables are not recorded.
16 // Define default settings.
17 define('DRUPAL_ROOT', getcwd());
19 $_SERVER['HTTP_HOST'] = 'default';
20 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
21 $_SERVER['SERVER_SOFTWARE'] = NULL;
22 $_SERVER['REQUEST_METHOD'] = 'GET';
23 $_SERVER['QUERY_STRING'] = '';
24 $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
25 $_SERVER['HTTP_USER_AGENT'] = 'console';
28 include_once './includes/bootstrap.inc';
29 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
31 // Include the utility drupal_var_export() function.
32 include_once dirname(__FILE__) . '/../includes/utility.inc';
34 // Output the PHP header.
35 $output = <<<ENDOFHEADER
40 * Filled installation of Drupal 7.0, for test purposes.
42 * This file was generated by the dump-database-d7.sh tool, from an
43 * installation of Drupal 7, filled with data using the generate-d7-content.sh
44 * tool. It has the following modules installed:
48 foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
49 $output .= " * - $module\n";
53 // Get the current schema, order it by table name.
54 $schema = drupal_get_schema();
57 // Export all the tables in the schema.
58 foreach ($schema as $table => $data) {
59 // Remove descriptions to save time and code.
60 unset($data['description']);
61 foreach ($data['fields'] as &$field) {
62 unset($field['description']);
65 // Dump the table structure.
66 $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
68 // Don't output values for those tables.
69 if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
74 // Prepare the export of values.
75 $result = db_query('SELECT * FROM {'. $table .'}', array(), array('fetch' => PDO::FETCH_ASSOC));
77 foreach ($result as $record) {
78 $insert .= '->values('. drupal_var_export($record) .")\n";
81 // Dump the values if there are some.
83 $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
85 $output .= "->execute();\n";