This commit is contained in:
Roly Rudy Gutierrez Pinto
2017-02-14 15:09:57 -04:00
parent 9d10a02fab
commit 254155289d

View File

@@ -278,6 +278,9 @@ class workspaceTools
$this->resetDBDiff['DB_USER'] = $dbName; $this->resetDBDiff['DB_USER'] = $dbName;
$value = $dbName; $value = $dbName;
} }
if (array_search($key, array('DB_PASS', 'DB_RBAC_PASS', 'DB_REPORT_PASS')) !== false && !empty($this->dbGrantUserPassword)) {
$value = $this->dbGrantUserPassword;
}
return $matches[1] . $value . $matches[4]; return $matches[1] . $value . $matches[4];
} }
@@ -306,6 +309,7 @@ class workspaceTools
$this->unify = $unify; $this->unify = $unify;
if ($resetDBNames) { if ($resetDBNames) {
$this->dbGrantUser = uniqid('wf_'); $this->dbGrantUser = uniqid('wf_');
$this->dbGrantUserPassword = G::generate_password(12, "luns", ".");
} }
@@ -947,7 +951,7 @@ class workspaceTools
} }
} }
} }
$workspaceSchema = $this->getSchema($rbac);
$changes = System::compareSchema($workspaceSchema, $schema); $changes = System::compareSchema($workspaceSchema, $schema);
$changed = (count($changes['tablesToAdd']) > 0 || count($changes['tablesToAlter']) > 0 || count($changes['tablesWithNewIndex']) > 0 || count($changes['tablesToAlterIndex']) > 0); $changed = (count($changes['tablesToAdd']) > 0 || count($changes['tablesToAlter']) > 0 || count($changes['tablesWithNewIndex']) > 0 || count($changes['tablesToAlterIndex']) > 0);
@@ -1350,16 +1354,12 @@ class workspaceTools
throw new Exception("Unable to retrieve users: " . mysql_error()); throw new Exception("Unable to retrieve users: " . mysql_error());
} }
$users = mysql_num_rows($result); $users = mysql_num_rows($result);
if ($users != 0) { if ($users === 0) {
$result = mysql_query("DROP USER '$username'@'$hostname'");
if ($result === false) {
throw new Exception("Unable to drop user: " . mysql_error());
}
}
CLI::logging("Creating user $username for $hostname\n"); CLI::logging("Creating user $username for $hostname\n");
$result = mysql_query("CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'"); $result = mysql_query("CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'");
if ($result === false) { if ($result === false) {
throw new Exception("Unable to create user $username: " . mysql_error()); throw new Exception("Unable to create user $username: " . mysql_error());
}
} }
$result = mysql_query("GRANT ALL ON $database.* TO '$username'@'$hostname'"); $result = mysql_query("GRANT ALL ON $database.* TO '$username'@'$hostname'");
if ($result === false) { if ($result === false) {
@@ -1753,8 +1753,8 @@ class workspaceTools
CLI::logging("+> Restoring database {$db->name} to $dbName\n"); CLI::logging("+> Restoring database {$db->name} to $dbName\n");
$versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1; $versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1;
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine); $workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine);
$workspace->createDBUser($dbUser, $db->pass, "localhost", $dbName); $workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "localhost", $dbName);
$workspace->createDBUser($dbUser, $db->pass, "%", $dbName); $workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "%", $dbName);
} }
} }