Commit e59f845c authored by drumm's avatar drumm Committed by Neil Drumm

New, more-flexible, MySQL grant_host(). No need to check if db verify is on a...

New, more-flexible, MySQL grant_host(). No need to check if db verify is on a server, it always is. Whitespace.
parent 626f5ec9
......@@ -44,14 +44,12 @@ class provisionService_db extends provisionService {
}
function verify() {
if (d()->type === 'server') {
$this->connect();
if ($this->can_create_database()) {
drush_log(dt('Provision can create new databases.'), 'message');
}
else {
drush_set_error('PROVISION_CREATE_DB_FAILED');
}
$this->connect();
if ($this->can_create_database()) {
drush_log(dt('Provision can create new databases.'), 'message');
}
else {
drush_set_error('PROVISION_CREATE_DB_FAILED');
}
}
......@@ -100,7 +98,6 @@ class provisionService_db extends provisionService {
}
/**
* Generate a new mysql database and user account for the specified credentials
*/
......@@ -118,9 +115,11 @@ class provisionService_db extends provisionService {
if (!$this->grant($db_name, $db_user, $db_passwd, $db_grant_host)) {
drush_set_error('PROVISION_CREATE_DB_FAILED', dt("Could not create database user @user", array('@user' => $db_user)));
}
if (d()->platform->web_server->remote_host !== $db_grant_host) {
drush_log(dt("Granting privileges to %user@%client on %database", array('%user' => $db_user, '%client' => d()->platform->web_server->remote_host, '%database' => $db_name)));
if (!$this->grant($db_name, $db_user, $db_passwd, d()->platform->web_server->remote_host)) {
// todo use d()->platform->server once hostmaster sets this to a real value
$local_grant_host = $this->grant_host(d('@server_localhost'));
if ($local_grant_host !== $db_grant_host) {
drush_log(dt("Granting privileges to %user@%client on %database", array('%user' => $db_user, '%client' => $local_grant_host, '%database' => $db_name)));
if (!$this->grant($db_name, $db_user, $db_passwd, $local_grant_host)) {
drush_set_error('PROVISION_CREATE_DB_FAILED', dt("Could not create database user @user", array('@user' => $db_user)));
}
}
......@@ -136,8 +135,6 @@ class provisionService_db extends provisionService {
}
return $status;
}
/**
* Remove the database and user account for the supplied credentials
......@@ -204,7 +201,7 @@ class provisionService_db extends provisionService {
$creds['db_passwd'] = drush_set_option('db_passwd', provision_password(), 'site');
$creds['db_name'] = drush_set_option('db_name', $this->suggest_db_name(), 'site');
$creds['db_user'] = drush_set_option('db_user', $creds['db_name'], 'site');
$creds['db_grant_host'] = $this->grant_host();
$creds['db_grant_host'] = $this->grant_host(d()->service('http')->server());
return $creds;
}
......@@ -217,7 +214,7 @@ class provisionService_db extends provisionService {
$creds[$key] = drush_get_option($key, '', 'site');
}
$creds['db_grant_host'] = $this->grant_host();
$creds['db_grant_host'] = $this->grant_host(d()->service('http')->server());
return $creds;
}
......@@ -253,8 +250,8 @@ class provisionService_db extends provisionService {
return FALSE;
}
function grant_host() {
return 'localhost';
function grant_host(provisionServer $server) {
return $server->remote_host;
}
}
......
......@@ -82,11 +82,14 @@ class provisionService_db_mysql extends provisionService_db_pdo {
}
}
function grant_host() {
$result = $this->query("select current_user()")->fetchColumn(0);
preg_match('/^.*@(.*)$/', $result, $matches);
return $matches[1];
function grant_host(provisionServer $server) {
$server->shell_exec('mysql -u intntnllyInvalid -h ' . escapeshellarg($this->remote_host));
if (preg_match("/Access denied for user 'intntnllyInvalid'@'([^']*)'/", implode('', drush_shell_exec_output()), $match)) {
return $match[1];
}
else {
return drush_set_error('PROVISION_DB_CONNECT_FAIL', dt('Dummy connection failed to fail: %msg', array('%msg' => join("\n", drush_shell_exec_output()))));
}
}
function generate_dump() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment