You are here

dump-database-d6.sh in Drupal 9

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