dump-database-d6.sh

Filled installation of Drupal 6.17, for test purposes.

This file was generated by the dump-database-d6.sh tool, from an installation of Drupal 6, filled with data using the generate-d6-content.sh tool. It has the following modules installed:

ENDOFHEADER;

foreach (module_list() as $module) { $output .= " * - $module\n"; } $output .= "

File

drupal/scripts/dump-database-d6.sh
View source
  1. #!/usr/bin/env php
  2. /**
  3. * Dump a Drupal 6 database into a Drupal 7 PHP script to test the upgrade
  4. * process.
  5. *
  6. * Run this script at the root of an existing Drupal 6 installation.
  7. *
  8. * The output of this script is a PHP script that can be ran inside Drupal 7
  9. * and recreates the Drupal 6 database as dumped. Transient data from cache
  10. * session and watchdog tables are not recorded.
  11. */
  12. // Define default settings.
  13. $cmd = 'index.php';
  14. $_SERVER['HTTP_HOST'] = 'default';
  15. $_SERVER['PHP_SELF'] = '/index.php';
  16. $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  17. $_SERVER['SERVER_SOFTWARE'] = NULL;
  18. $_SERVER['REQUEST_METHOD'] = 'GET';
  19. $_SERVER['QUERY_STRING'] = '';
  20. $_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
  21. $_SERVER['HTTP_USER_AGENT'] = 'console';
  22. // Bootstrap Drupal.
  23. include_once './includes/bootstrap.inc';
  24. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  25. // Include the utility drupal_var_export() function.
  26. include_once dirname(__FILE__) . '/../includes/utility.inc';
  27. // Output the PHP header.
  28. $output = <<
  29. /**
  30. * @file
  31. * Filled installation of Drupal 6.17, for test purposes.
  32. *
  33. * This file was generated by the dump-database-d6.sh tool, from an
  34. * installation of Drupal 6, filled with data using the generate-d6-content.sh
  35. * tool. It has the following modules installed:
  36. ENDOFHEADER;
  37. foreach (module_list() as $module) {
  38. $output .= " * - $module\n";
  39. }
  40. $output .= " */\n\n";
  41. // Get the current schema, order it by table name.
  42. $schema = drupal_get_schema();
  43. ksort($schema);
  44. // Export all the tables in the schema.
  45. foreach ($schema as $table => $data) {
  46. // Remove descriptions to save time and code.
  47. unset($data['description']);
  48. foreach ($data['fields'] as &$field) {
  49. unset($field['description']);
  50. }
  51. // Dump the table structure.
  52. $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
  53. // Don't output values for those tables.
  54. if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
  55. $output .= "\n";
  56. continue;
  57. }
  58. // Prepare the export of values.
  59. $result = db_query('SELECT * FROM {'. $table .'}');
  60. $insert = '';
  61. while ($record = db_fetch_array($result)) {
  62. // users.uid is a serial and inserting 0 into a serial can break MySQL.
  63. // So record uid + 1 instead of uid for every uid and once all records
  64. // are in place, fix them up.
  65. if ($table == 'users') {
  66. $record['uid']++;
  67. }
  68. $insert .= '->values('. drupal_var_export($record) .")\n";
  69. }
  70. // Dump the values if there are some.
  71. if ($insert) {
  72. $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
  73. $output .= $insert;
  74. $output .= "->execute();\n";
  75. }
  76. // Add the statement fixing the serial in the user table.
  77. if ($table == 'users') {
  78. $output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";
  79. }
  80. $output .= "\n";
  81. }
  82. print $output;