dump-database-d6.sh

Same filename in other branches
  1. 9 core/scripts/dump-database-d6.sh
  2. 8.9.x core/scripts/dump-database-d6.sh
  3. 10 core/scripts/dump-database-d6.sh
  4. 11.x core/scripts/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

scripts/dump-database-d6.sh

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.