Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix db name with hypen issue #346

Merged
merged 7 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
\EE::exec( 'docker volume rm ' . $volume );
}

$db_script_path = \EE\Utils\get_temp_dir() . 'db_exec';

if ( $this->fs->exists( $db_script_path ) ) {
try {
$this->fs->remove($db_script_path);
mrrobot47 marked this conversation as resolved.
Show resolved Hide resolved
} catch (\Exception $e) {
\EE::debug($e);
}
}

if ( ! empty( $db_data['db_host'] ) ) {
\EE\Site\Utils\cleanup_db( $db_data['db_host'], $db_data['db_name'] );
\EE\Site\Utils\cleanup_db_user( $db_data['db_host'], $db_data['db_user'] );
Expand Down
4 changes: 2 additions & 2 deletions src/helper/site-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function create_user_in_db( $db_host, $db_name = '', $db_user = '', $db_pass = '
$db_user = empty( $db_user ) ? \EE\Utils\random_password( 5 ) : $db_user;
$db_pass = empty( $db_pass ) ? \EE\Utils\random_password() : $db_pass;

$create_string = sprintf( "CREATE USER '%1\$s'@'%%' IDENTIFIED BY '%2\$s'; CREATE DATABASE %3\$s; GRANT ALL PRIVILEGES ON %3\$s.* TO '%1\$s'@'%%'; FLUSH PRIVILEGES;", $db_user, $db_pass, $db_name );
$create_string = sprintf( 'CREATE USER "%1$s"@"%%" IDENTIFIED BY "%2$s"; CREATE DATABASE `%3$s`; GRANT ALL PRIVILEGES ON `%3$s`.* TO "%1$s"@"%%"; FLUSH PRIVILEGES;', $db_user, $db_pass, $db_name );

if ( GLOBAL_DB === $db_host ) {

Expand All @@ -148,7 +148,7 @@ function create_user_in_db( $db_host, $db_name = '', $db_user = '', $db_pass = '
}

$db_script_path = \EE\Utils\get_temp_dir() . 'db_exec';
file_put_contents( $db_script_path, sprintf( 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e"%s"', $create_string ) );
file_put_contents( $db_script_path, sprintf( 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e\'%s\'', $create_string ) );

EE::exec( sprintf( 'docker cp %s %s:/db_exec', $db_script_path, GLOBAL_DB_CONTAINER ) );
if ( ! EE::exec( sprintf( 'docker exec %s sh db_exec', GLOBAL_DB_CONTAINER ) ) ) {
Expand Down