diff -r 07239de796bb -r e756a8c72c3d cms/drupal/scripts/dump-database-d6.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/drupal/scripts/dump-database-d6.sh Fri Sep 08 12:04:06 2017 +0200 @@ -0,0 +1,101 @@ +#!/usr/bin/env php + $data) { + // Remove descriptions to save time and code. + unset($data['description']); + foreach ($data['fields'] as &$field) { + unset($field['description']); + } + + // Dump the table structure. + $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n"; + + // Don't output values for those tables. + if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') { + $output .= "\n"; + continue; + } + + // Prepare the export of values. + $result = db_query('SELECT * FROM {'. $table .'}'); + $insert = ''; + while ($record = db_fetch_array($result)) { + // users.uid is a serial and inserting 0 into a serial can break MySQL. + // So record uid + 1 instead of uid for every uid and once all records + // are in place, fix them up. + if ($table == 'users') { + $record['uid']++; + } + $insert .= '->values('. drupal_var_export($record) .")\n"; + } + + // Dump the values if there are some. + if ($insert) { + $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n"; + $output .= $insert; + $output .= "->execute();\n"; + } + + // Add the statement fixing the serial in the user table. + if ($table == 'users') { + $output .= "db_query('UPDATE {users} SET uid = uid - 1');\n"; + } + + $output .= "\n"; +} + +print $output;