From b928436008c227dddf1d4abd46f839e7c7486214 Mon Sep 17 00:00:00 2001 From: norahmollo Date: Fri, 10 Oct 2014 15:09:26 -0400 Subject: [PATCH] PM-401 Backup workspace modified Backup database modified --- workflow/engine/bin/tasks/cliWorkspaces.php | 100 ++++++++++---------- workflow/engine/classes/class.wsTools.php | 13 ++- 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 165afd35c..ef4f93176 100755 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -372,60 +372,64 @@ function run_drafts_clean($args, $opts) { } function run_workspace_backup($args, $opts) { - $workspaces = array(); - if (sizeof($args) > 2) { - $filename = array_pop($args); - foreach ($args as $arg) { - $workspaces[] = new workspaceTools($arg); + $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; + if (sizeof($args) == 2) { + $filename = $args[1]; + } else { + $filename = "{$workspace->name}.tar"; + } + } else { + throw new Exception("No workspace specified for backup"); } - } else if (sizeof($args) > 0) { - $workspace = new workspaceTools($args[0]); - $workspaces[] = $workspace; - if (sizeof($args) == 2) - $filename = $args[1]; - else - $filename = "{$workspace->name}.tar"; - } else { - throw new Exception("No workspace specified for backup"); - } - foreach ($workspaces as $workspace) - if (!$workspace->workspaceExists()) - throw new Exception("Workspace '{$workspace->name}' not found"); - //If this is a relative path, put the file in the backups directory - if (strpos($filename, "/") === false && strpos($filename, '\\') === false){ - $filename = PATH_DATA . "backups/$filename"; - } - CLI::logging("Backing up to $filename\n"); - $filesize = array_key_exists("filesize", $opts) ? $opts['filesize'] : -1; - if($filesize >= 0) - { - if(!Bootstrap::isLinuxOs()){ + + foreach ($workspaces as $workspace) { + if (!$workspace->workspaceExists()) { + throw new Exception("Workspace '{$workspace->name}' not found"); + } + } + + //If this is a relative path, put the file in the backups directory + if (strpos($filename, "/") === false && strpos($filename, '\\') === false){ + $filename = PATH_DATA . "backups/$filename"; + } + CLI::logging("Backing up to $filename\n"); + + $filesize = array_key_exists("filesize", $opts) ? $opts['filesize'] : -1; + + if ($filesize >= 0) { + if (!Bootstrap::isLinuxOs()) { CLI::error("This is not a Linux enviroment, cannot use this filesize [-s] feature.\n"); return; - } - $multipleBackup = new multipleFilesBackup ($filename,$filesize);//if filesize is 0 the default size will be took - //using new method - foreach ($workspaces as $workspace){ - $multipleBackup->addToBackup($workspace); - } - $multipleBackup->letsBackup(); - } - else - { - //ansient method to backup into one large file - $backup = workspaceTools::createBackup($filename); + } + $multipleBackup = new multipleFilesBackup ($filename,$filesize);//if filesize is 0 the default size will be took + //using new method + foreach ($workspaces as $workspace) { + $multipleBackup->addToBackup($workspace); + } + $multipleBackup->letsBackup(); + } else { + //ansient method to backup into one large file + $backup = workspaceTools::createBackup($filename); - foreach ($workspaces as $workspace) - $workspace->backup($backup); - } - CLI::logging("\n"); - workspaceTools::printSysInfo(); - foreach ($workspaces as $workspace) { + foreach ($workspaces as $workspace) { + $workspace->backup($backup); + } + } CLI::logging("\n"); - $workspace->printMetadata(false); - } - + workspaceTools::printSysInfo(); + foreach ($workspaces as $workspace) { + CLI::logging("\n"); + $workspace->printMetadata(false); + } } function run_workspace_restore($args, $opts) { diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 3554854d7..458bd6134 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -1032,10 +1032,14 @@ class workspaceTools $wfDsn = $fields['DB_ADAPTER'] . '://' . $fields['DB_USER'] . ':' . $fields['DB_PASS'] . '@' . $fields['DB_HOST'] . '/' . $fields['DB_NAME']; + if ($fields['DB_NAME'] == $fields['DB_RBAC_NAME']) { + $info = array('Workspace Name' => $fields['WORKSPACE_NAME'], 'Workflow Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_USER'], $fields['DB_PASS'], $fields['DB_HOST'], $fields['DB_NAME']), 'MySql Version' => $fields['DATABASE']); + } else { $info = array('Workspace Name' => $fields['WORKSPACE_NAME'], //'Available Databases' => $fields['AVAILABLE_DB'], 'Workflow Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_USER'], $fields['DB_PASS'], $fields['DB_HOST'], $fields['DB_NAME']), 'RBAC Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_RBAC_USER'], $fields['DB_RBAC_PASS'], $fields['DB_RBAC_HOST'], $fields['DB_RBAC_NAME']), 'Report Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_REPORT_USER'], $fields['DB_REPORT_PASS'], $fields['DB_REPORT_HOST'], $fields['DB_REPORT_NAME']), 'MySql Version' => $fields['DATABASE'] ); + } foreach ($info as $k => $v) { if (is_numeric($k)) { @@ -1070,15 +1074,18 @@ class workspaceTools public function exportDatabase($path, $onedb = false) { $dbInfo = $this->getDBInfo(); - + if ($onedb) { $databases = array("rb", "rp"); + } else if ($dbInfo['DB_NAME'] == $dbInfo['DB_RBAC_NAME']) { + $databases = array("wf"); } else { $databases = array("wf", "rp", "rb"); } $dbNames = array(); - foreach ($databases as $db) { + + foreach ($databases as $db) { $dbInfo = $this->getDBCredentials($db); $oDbMaintainer = new DataBaseMaintenance($dbInfo["host"], $dbInfo["user"], $dbInfo["pass"]); CLI::logging("Saving database {$dbInfo["name"]}\n"); @@ -1139,7 +1146,7 @@ class workspaceTools * @param bool $compress specifies wheter the backup is compressed or not */ public function backup($backupFile, $compress = true) - { + { /* $filename can be a string, in which case it's used as the filename of * the backup, or it can be a previously created tar, which allows for * multiple workspaces in one backup.