Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
$WPT_TEST_DIR = getenv( 'WPT_TEST_DIR' );
$WPT_RM_TEST_DIR_CMD = getenv( 'WPT_RM_TEST_DIR_CMD' ) ? : 'rm -r ' . $WPT_TEST_DIR;

// Cleanup the Database.
cleanup_db();

// Clean up the preparation directory.
// Only forcefully delete the .git directory, to prevent disasters otherwise.
perform_operations( array(
Expand Down
50 changes: 50 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,53 @@ function get_env_details() {
$env['system_utils']['openssl'] = str_replace( 'OpenSSL ', '', trim( shell_exec( 'openssl version' ) ) );
return $env;
}

/**
* Cleanup the Database.
*/
function cleanup_db() {
$prefix = getenv( 'WPT_TABLE_PREFIX' ) ? getenv( 'WPT_TABLE_PREFIX' ) : 'wptests_';

$tables = array(
'users',
'usermeta',
'posts',
'comments',
'links',
'options',
'postmeta',
'terms',
'term_taxonomy',
'term_relationships',
'termmeta',
'commentmeta',
'blogs',
'blogmeta',
'signups',
'site',
'sitemeta',
'sitecategories',
'registration_log',
);

$test_db = new mysqli(
getenv( 'WPT_DB_HOST' ),
getenv( 'WPT_DB_USER' ),
getenv( 'WPT_DB_PASSWORD' ),
getenv( 'WPT_DB_NAME' )
);

if ( $test_db->connect_errno ) {
error_message( 'Could not connect to database.' );
}

log_message( 'Clearing database.' );

foreach ( $tables as $table ) {
if ( ! $test_db->query( "DROP TABLE IF EXISTS {$prefix}{$table}" ) ) {
error_message( "Aborting. Could not DROP table {$prefix}{$table}." );
}
}

$test_db->close();
}