Chris@0: #!/usr/bin/env php Chris@0: getModuleList() as $module => $filename) { Chris@0: $output .= " * - $module\n"; Chris@0: } Chris@0: $output .= " */\n\n"; Chris@0: Chris@0: // Get the current schema, order it by table name. Chris@0: $schema = drupal_get_schema(); Chris@0: ksort($schema); Chris@0: Chris@0: // Export all the tables in the schema. Chris@0: foreach ($schema as $table => $data) { Chris@0: // Remove descriptions to save time and code. Chris@0: unset($data['description']); Chris@0: foreach ($data['fields'] as &$field) { Chris@0: unset($field['description']); Chris@0: } Chris@0: Chris@0: // Dump the table structure. Chris@0: $output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n"; Chris@0: Chris@0: // Don't output values for those tables. Chris@0: if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') { Chris@0: $output .= "\n"; Chris@0: continue; Chris@0: } Chris@0: Chris@0: // Prepare the export of values. Chris@0: $result = db_query('SELECT * FROM {'. $table .'}', array(), array('fetch' => PDO::FETCH_ASSOC)); Chris@0: $insert = ''; Chris@0: foreach ($result as $record) { Chris@0: $insert .= '->values('. drupal_var_export($record) .")\n"; Chris@0: } Chris@0: Chris@0: // Dump the values if there are some. Chris@0: if ($insert) { Chris@0: $output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n"; Chris@0: $output .= $insert; Chris@0: $output .= "->execute();\n"; Chris@0: } Chris@0: Chris@0: $output .= "\n"; Chris@0: } Chris@0: Chris@0: print $output;