diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 060a0235e..2e7667f8d 100644 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -278,6 +278,9 @@ class workspaceTools $this->resetDBDiff['DB_USER'] = $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]; } @@ -306,6 +309,7 @@ class workspaceTools $this->unify = $unify; if ($resetDBNames) { $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); $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()); } $users = mysql_num_rows($result); - if ($users != 0) { - $result = mysql_query("DROP USER '$username'@'$hostname'"); - if ($result === false) { - throw new Exception("Unable to drop user: " . mysql_error()); - } - } + if ($users === 0) { CLI::logging("Creating user $username for $hostname\n"); - $result = mysql_query("CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'"); - if ($result === false) { - throw new Exception("Unable to create user $username: " . mysql_error()); + $result = mysql_query("CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'"); + if ($result === false) { + throw new Exception("Unable to create user $username: " . mysql_error()); + } } $result = mysql_query("GRANT ALL ON $database.* TO '$username'@'$hostname'"); if ($result === false) { @@ -1753,8 +1753,8 @@ class workspaceTools CLI::logging("+> Restoring database {$db->name} to $dbName\n"); $versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1; $workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine); - $workspace->createDBUser($dbUser, $db->pass, "localhost", $dbName); - $workspace->createDBUser($dbUser, $db->pass, "%", $dbName); + $workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "localhost", $dbName); + $workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "%", $dbName); } }