PM-401 Unify-Database
Unify Database and Restore changes
This commit is contained in:
@@ -524,8 +524,10 @@ class DataBaseMaintenance
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tablesBpmn as $table) {
|
||||
fwrite( $file, $sqlTablesBpmn[$table] );
|
||||
if (count ($sqlTablesBpmn) > 0) {
|
||||
foreach ($tablesBpmn as $table) {
|
||||
fwrite( $file, $sqlTablesBpmn[$table] );
|
||||
}
|
||||
}
|
||||
|
||||
fclose( $file );
|
||||
|
||||
@@ -197,7 +197,17 @@ function listFiles($dir) {
|
||||
|
||||
function run_unify_database($args)
|
||||
{
|
||||
$workspaces = get_workspaces_from_args($args);
|
||||
$workspaces = array();
|
||||
|
||||
if (sizeof($args) > 2) {
|
||||
$filename = array_pop($args);
|
||||
foreach ($args as $arg) {
|
||||
$workspaces[] = new workspaceTools($arg);
|
||||
}
|
||||
} else if (sizeof($args) > 0) {
|
||||
$workspace = new workspaceTools($args[0]);
|
||||
$workspaces[] = $workspace;
|
||||
}
|
||||
|
||||
CLI::logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
|
||||
CLI::logging("Checking workspaces...\n");
|
||||
@@ -214,23 +224,6 @@ function run_unify_database($args)
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($workspaces as $workspace) {
|
||||
|
||||
if (! $workspace->workspaceExists()) {
|
||||
echo "Workspace {$workspace->name} not found\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$ws = $workspace->name;
|
||||
$sContent = file_get_contents (PATH_DB . $ws . PATH_SEP . 'db.php');
|
||||
|
||||
if (strpos($sContent, 'rb_')) {
|
||||
$workspace->onedb = false;
|
||||
} else {
|
||||
$workspace->onedb = true;
|
||||
}
|
||||
}
|
||||
|
||||
$first = true;
|
||||
$errors = false;
|
||||
$countWorkspace = 0;
|
||||
@@ -240,6 +233,20 @@ function run_unify_database($args)
|
||||
try {
|
||||
$countWorkspace++;
|
||||
|
||||
if (! $workspace->workspaceExists()) {
|
||||
echo "Workspace {$workspace->name} not found\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$ws = $workspace->name;
|
||||
$sContent = file_get_contents (PATH_DB . $ws . PATH_SEP . 'db.php');
|
||||
|
||||
if (strpos($sContent, 'rb_')) {
|
||||
$workspace->onedb = false;
|
||||
} else {
|
||||
$workspace->onedb = true;
|
||||
}
|
||||
|
||||
if ($workspace->onedb) {
|
||||
CLI::logging("Workspace $workspace->name already one Database...\n");
|
||||
} else {
|
||||
@@ -262,23 +269,28 @@ function run_unify_database($args)
|
||||
list ($dbHost, $dbUser, $dbPass) = @explode( SYSTEM_HASH, G::decrypt( HASH_INSTALLATION, SYSTEM_HASH ) );
|
||||
$link = mysql_connect( $dbHost, $dbUser, $dbPass );
|
||||
|
||||
foreach ($metadata->databases as $db) {
|
||||
foreach ($metadata['databases'] as $db) {
|
||||
$dbName = 'wf_'.$workspace->name;
|
||||
CLI::logging( "+> Restoring {$db->name} to $dbName database\n" );
|
||||
$restore = $workspace->executeSQLScript( $dbName, "$tempDirectory/{$db->name}.sql" );
|
||||
CLI::logging( "+> Restoring {$db['name']} to $dbName database\n" );
|
||||
|
||||
CLI::logging( "+> Remove {$db->name} database\n" );
|
||||
$aParameters = array('dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass);
|
||||
|
||||
$sql = "DROP DATABASE IF EXISTS {$db->name};";
|
||||
if (! @mysql_query( $sql )) {
|
||||
throw new Exception( mysql_error() );
|
||||
$restore = $workspace->executeScript( $dbName, "$tempDirectory/{$db['name']}.sql", $aParameters);
|
||||
|
||||
if ($restore) {
|
||||
CLI::logging( "+> Remove {$db['name']} database\n" );
|
||||
|
||||
$sql = "DROP DATABASE IF EXISTS {$db['name']};";
|
||||
if (! @mysql_query( $sql )) {
|
||||
throw new Exception( mysql_error() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CLI::logging( "Removing temporary files\n" );
|
||||
G::rm_dir( $tempDirectory );
|
||||
|
||||
$newDBNames = $workspace->resetDBInfo( $dbHost, true );
|
||||
$newDBNames = $workspace->resetDBInfo( $dbHost, true, true );
|
||||
|
||||
CLI::logging( CLI::info( "Done restoring databases" ) . "\n" );
|
||||
}
|
||||
|
||||
@@ -233,12 +233,13 @@ class workspaceTools
|
||||
$value = isset($matches['value']) ? $matches['value'] : $matches[3];
|
||||
|
||||
if($this->onedb){
|
||||
$dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'wf_', 'DB_RBAC_USER' => 'wf_', 'DB_REPORT_NAME' => 'wf_', 'DB_REPORT_USER' => 'wf_');
|
||||
$dbInfo = $this->getDBInfo();
|
||||
$dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'wf_', 'DB_RBAC_USER' => 'wf_', 'DB_REPORT_NAME' => 'wf_', 'DB_REPORT_USER' => 'wf_');
|
||||
if (array_search($key, array('DB_PASS', 'DB_RBAC_PASS', 'DB_REPORT_PASS'))) {
|
||||
$value = $this->dbInfo['DB_PASS'];
|
||||
$value = $dbInfo['DB_PASS'];
|
||||
}
|
||||
} else{
|
||||
$dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'rb_', 'DB_RBAC_USER' => 'rb_', 'DB_REPORT_NAME' => 'rp_', 'DB_REPORT_USER' => 'rp_');
|
||||
$dbPrefix = array('DB_NAME' => 'wf_', 'DB_USER' => 'wf_', 'DB_RBAC_NAME' => 'rb_', 'DB_RBAC_USER' => 'rb_', 'DB_REPORT_NAME' => 'rp_', 'DB_REPORT_USER' => 'rp_');
|
||||
}
|
||||
|
||||
if (array_search($key, array('DB_HOST', 'DB_RBAC_HOST', 'DB_REPORT_HOST')) !== false) {
|
||||
@@ -272,7 +273,7 @@ class workspaceTools
|
||||
* @param bool $resetDBNames if true, also reset all database names
|
||||
* @return array contains the new database names as values
|
||||
*/
|
||||
public function resetDBInfo($newHost, $resetDBNames = true)
|
||||
public function resetDBInfo($newHost, $resetDBNames = true, $onedb = false)
|
||||
{
|
||||
if (count(explode(":", $newHost)) < 2) {
|
||||
$newHost .= ':3306';
|
||||
@@ -280,7 +281,7 @@ class workspaceTools
|
||||
$this->newHost = $newHost;
|
||||
$this->resetDBNames = $resetDBNames;
|
||||
$this->resetDBDiff = array();
|
||||
$this->onedb = false;
|
||||
$this->onedb = $onedb;
|
||||
|
||||
if (!$this->workspaceExists()) {
|
||||
throw new Exception("Could not find db.php in the workspace");
|
||||
@@ -289,14 +290,7 @@ class workspaceTools
|
||||
|
||||
if ($sDbFile === false) {
|
||||
throw new Exception("Could not read database information from db.php");
|
||||
} else {
|
||||
if (strpos($sDbFile, 'rb_')) {
|
||||
$this->onedb = false;
|
||||
} else {
|
||||
$this->onedb = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Match all defines in the config file. Check updateDBCallback to know what
|
||||
* keys are changed and what groups are matched.
|
||||
* This regular expression will match any "define ('<key>', '<value>');"
|
||||
@@ -847,6 +841,7 @@ class workspaceTools
|
||||
if (!empty($changes['tablesToAdd'])) {
|
||||
CLI::logging("-> " . count($changes['tablesToAdd']) . " tables to add\n");
|
||||
}
|
||||
|
||||
foreach ($changes['tablesToAdd'] as $sTable => $aColumns) {
|
||||
$oDataBase->executeQuery($oDataBase->generateCreateTableSQL($sTable, $aColumns));
|
||||
if (isset($changes['tablesToAdd'][$sTable]['INDEXES'])) {
|
||||
@@ -859,6 +854,7 @@ class workspaceTools
|
||||
if (!empty($changes['tablesToAlter'])) {
|
||||
CLI::logging("-> " . count($changes['tablesToAlter']) . " tables to alter\n");
|
||||
}
|
||||
|
||||
foreach ($changes['tablesToAlter'] as $sTable => $aActions) {
|
||||
foreach ($aActions as $sAction => $aAction) {
|
||||
foreach ($aAction as $sColumn => $vData) {
|
||||
@@ -974,6 +970,9 @@ class workspaceTools
|
||||
$dbNetView = new NET($this->dbHost);
|
||||
$dbNetView->loginDbServer($this->dbUser, $this->dbPass);
|
||||
try {
|
||||
if (!defined('DB_ADAPTER')) {
|
||||
require_once($this->dbPath);
|
||||
}
|
||||
$sMySQLVersion = $dbNetView->getDbServerVersion('mysql');
|
||||
} catch (Exception $oException) {
|
||||
$sMySQLVersion = 'Unknown';
|
||||
@@ -1315,6 +1314,12 @@ class workspaceTools
|
||||
}
|
||||
}
|
||||
|
||||
public function executeScript($database, $filename, $parameters)
|
||||
{
|
||||
$this->executeSQLScript($database, $filename, $parameters);
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function restoreLegacy($directory)
|
||||
{
|
||||
throw new Exception("Use gulliver to restore backups from old versions");
|
||||
@@ -1435,6 +1440,13 @@ class workspaceTools
|
||||
throw new Exception("Backup version {$metadata->version} not supported");
|
||||
}
|
||||
$backupWorkspace = $metadata->WORKSPACE_NAME;
|
||||
|
||||
if (strpos($metadata->DB_RBAC_NAME, 'rb_') === false) {
|
||||
$onedb = true;
|
||||
} else {
|
||||
$onedb = false;
|
||||
}
|
||||
|
||||
if (isset($dstWorkspace)) {
|
||||
$workspaceName = $dstWorkspace;
|
||||
$createWorkspace = true;
|
||||
@@ -1492,14 +1504,17 @@ class workspaceTools
|
||||
throw new Exception('Could not connect to system database: ' . mysql_error());
|
||||
}
|
||||
|
||||
$newDBNames = $workspace->resetDBInfo($dbHost, $createWorkspace);
|
||||
$dbName = '';
|
||||
$newDBNames = $workspace->resetDBInfo($dbHost, $createWorkspace, $onedb);
|
||||
|
||||
foreach ($metadata->databases as $db) {
|
||||
$dbName = $newDBNames[$db->name];
|
||||
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
||||
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql",$aParameters);
|
||||
$workspace->createDBUser($dbName, $db->pass, "localhost", $dbName);
|
||||
$workspace->createDBUser($dbName, $db->pass, "%", $dbName);
|
||||
if ($dbName != $newDBNames[$db->name]) {
|
||||
$dbName = $newDBNames[$db->name];
|
||||
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
||||
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql",$aParameters);
|
||||
$workspace->createDBUser($dbName, $db->pass, "localhost", $dbName);
|
||||
$workspace->createDBUser($dbName, $db->pass, "%", $dbName);
|
||||
}
|
||||
}
|
||||
|
||||
$version = explode('-', $metadata->PM_VERSION);
|
||||
@@ -1516,7 +1531,7 @@ class workspaceTools
|
||||
if ( $versionOld < $versionPresent || strpos($versionPresent, "Branch")) {
|
||||
$start = microtime(true);
|
||||
CLI::logging("> Updating database...\n");
|
||||
$workspace->upgradeDatabase();
|
||||
$workspace->upgradeDatabase($onedb);
|
||||
$stop = microtime(true);
|
||||
$final = $stop - $start;
|
||||
CLI::logging("<*> Database Upgrade Process took $final seconds.\n");
|
||||
|
||||
Reference in New Issue
Block a user