dump-database-d6.sh

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

END_OF_HEADER;

foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) { $output .= " * - $module\n"; } $output .= "

File

core/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 __DIR__ . '/../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. END_OF_HEADER;
  39. foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
  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. // Override the field type of the filename primary key to bypass the
  47. // InnoDB 191 character limitation.
  48. if (isset($schema['system']['primary key']) && $schema['system']['primary key'] == 'filename' && isset($schema['system']['fields']['filename']['type']) && $schema['system']['fields']['filename']['type'] == 'varchar') {
  49. $schema['system']['fields']['filename']['type'] = 'varchar_ascii';
  50. }
  51. // Export all the tables in the schema.
  52. foreach ($schema as $table => $data) {
  53. // Remove descriptions to save time and code.
  54. unset($data['description']);
  55. foreach ($data['fields'] as &$field) {
  56. unset($field['description']);
  57. }
  58. // Dump the table structure.
  59. $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
  60. // Don't output values for those tables.
  61. if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
  62. $output .= "\n";
  63. continue;
  64. }
  65. // Prepare the export of values.
  66. $result = db_query('SELECT * FROM {'. $table .'}');
  67. $insert = '';
  68. while ($record = db_fetch_array($result)) {
  69. // users.uid is a serial and inserting 0 into a serial can break MySQL.
  70. // So record uid + 1 instead of uid for every uid and once all records
  71. // are in place, fix them up.
  72. if ($table == 'users') {
  73. $record['uid']++;
  74. }
  75. $insert .= '->values('. drupal_var_export($record) .")\n";
  76. }
  77. // Dump the values if there are some.
  78. if ($insert) {
  79. $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
  80. $output .= $insert;
  81. $output .= "->execute();\n";
  82. }
  83. // Add the statement fixing the serial in the user table.
  84. if ($table == 'users') {
  85. $output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";
  86. }
  87. $output .= "\n";
  88. }
  89. print $output;

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