$schema) { $sources[$name] = Database::getConnection()->prefixTables('{' . $name . '}'); } // Retrieve the default database name $default_connection = Database::getConnectionInfo('default'); $source_db_name = $default_connection['default']['database']; // Retrieve the static prefix parameter stored in the fixture db info in settings.php $fixturedb_connection = Database::getConnectionInfo('fixture'); $fixturedb_prefix = $fixturedb_connection['default']['simpletest_prefix']; // Switch to fixture database Database::renameConnection('default', 'simpletest_original_default'); Database::addConnectionInfo('default', 'default', $fixturedb_connection['default']); // TODO Check if we're really connected to fixtures db // Remove old fixtures tables $res = db_query("SHOW TABLES"); $dropped_tables_count = 0; foreach ($res as $table) { $table = array_shift(array_values((array)$table)); // Only drop fixture tables if (strpos($table, $fixturedb_prefix) !== FALSE) { db_drop_table($table); $dropped_tables_count++; } // Also drop drupal tables in mode "full" else if ($mode == 'full') { // Keep table 'watchdog' so dblog_watchdog() doesn't complain if ($table == 'watchdog') { continue; } db_drop_table($table); $dropped_tables_count++; } // The drupal tables are already there else { $skip_drupal_db = TRUE; } } // Clone tables from source into fixtures database $cloned_tables_count = 0; $excludeTables = array( 'cache', 'cache_block', 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form', 'cache_image', 'cache_menu', 'cache_page', 'cache_path', 'cache_update', 'watchdog', // @todo CM 20120424 - added table file_managed for debugging because of error on integra environment 'file_managed', // 'locales_target', // 'menu_custom' ); // Clone drupal tables if (!isset($skip_drupal_db)) { foreach ($schemas as $table => $schema) { // Create 'watchdog' only if the entire db gets populated from the first time if ($dropped_tables_count > 0 && $table == 'watchdog') { continue; } $target = Database::getConnection()->prefixTables('{' . $table . '}'); db_create_table($target, $schema); if (!in_array($table, $excludeTables)) { $source = $source_db_name .'.'. $sources[$table]; db_query('INSERT INTO ' . $target . ' SELECT * FROM ' . $source); } $cloned_tables_count++; } } // Create fixture tables foreach ($schemas as $table => $schema) { $target_prefixed = Database::getConnection()->prefixTables('{' . $fixturedb_prefix . $table . '}'); db_create_table($target_prefixed, $schema); } // update the database schemas and schema alters drush_core_updatedb(); // copy content into fixtures tables foreach ($schemas as $table => $schema) { $target_prefixed = Database::getConnection()->prefixTables('{' . $fixturedb_prefix . $table . '}'); if (!in_array($table, $excludeTables)) { $source = $source_db_name .'.'. $sources[$table]; db_query('INSERT INTO ' . $target_prefixed . ' SELECT * FROM ' . $source); } $cloned_tables_count++; } // Get back to the original connection. Database::removeConnection('default'); Database::renameConnection('simpletest_original_default', 'default'); return array( 'dropped_tables_count' => $dropped_tables_count, 'cloned_tables_count' => $cloned_tables_count, ); }