diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index be075e47b..53a8be931 100755 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -51,7 +51,7 @@ EOT ); CLI::taskArg('workspace', false); CLI::taskArg('backup-file', true); -CLI::taskOpt("filesize", "Split the backup file in multiple files which are compressed. The maximum size of these files is set to MAX-SIZE in megabytes. If MAX-SIZE is not set, then it is 1000 megabytes by default. It may be necessary to use this option if using a 32 bit Linux/UNIX system which limits its maximum file size to 2GB. This option does not work on Windows systems.", "sMAX-SIZE","filesize=MAX-SIZE"); +CLI::taskOpt("filesize", "Split the backup file in multiple files which are compressed. The maximum size of these files is set to MAX-SIZE in megabytes. If MAX-SIZE is not set, then it is 1000 megabytes by default. It may be necessary to use this option if using a 32 bit Linux/UNIX system which limits its maximum file size to 2GB. This option does not work on Windows systems.", "s:","filesize="); CLI::taskRun("run_workspace_backup"); CLI::taskName('workspace-restore'); @@ -73,9 +73,9 @@ CLI::taskOpt("info", "Show information about backup file, but do not restore any CLI::taskOpt("multiple", "Restore from multiple compressed backup files which are numbered.", "m"); CLI::taskOpt("workspace", "Specify which workspace to restore if multiple workspaces are present in the backup file. Ex: -wworkflow.", - "wWORKSPACE", "workspace=WORKSPACE"); -CLI::taskOpt("lang", "Specify the language which will be used to rebuild the case cache list. If this option isn't included, then 'en' (English) will be used by default.", "lLANG","lang=LANG"); -CLI::taskOpt("port", "Specify the port number used by MySQL. If not specified, then the port 3306 will be used by default.", "pPORT"); + "w:", "workspace="); +CLI::taskOpt("lang", "Specify the language which will be used to rebuild the case cache list. If this option isn't included, then 'en' (English) will be used by default.", "l:","lang="); +CLI::taskOpt("port", "Specify the port number used by MySQL. If not specified, then the port 3306 will be used by default.", "p:"); CLI::taskRun("run_workspace_restore"); CLI::taskName('cacheview-repair'); @@ -93,7 +93,7 @@ CLI::taskDescription(<<getMetadata(); CLI::logging( "Creating temporary files on database...\n" ); $metadata["databases"] = $workspace->exportDatabase( $tempDirectory ); - $metadata["directories"] = array ("{$workspace->name}.files"); + $metadata["directories"] = array ("{$workspace->name}"); $metadata["version"] = 1; $metaFilename = "$tempDirectory/{$workspace->name}.meta"; if (! file_put_contents( $metaFilename, str_replace( array (",","{","}"), array (",\n ","{\n ","\n}\n"), G::json_encode( $metadata ) ) )) { @@ -110,6 +110,8 @@ class multipleFilesBackup $DecommpressCommand .= " | tar xzv"; $tempDirectory = PATH_DATA . "upgrade/" . basename( tempnam( __FILE__, '' ) ); + $tempDirectoryHelp = $tempDirectory; + $parentDirectory = PATH_DATA . "upgrade"; if (is_writable( $parentDirectory )) { mkdir( $tempDirectory ); @@ -123,6 +125,9 @@ class multipleFilesBackup CLI::logging( "\nUncompressed into: " . $tempDirectory . "\n" ); //Search for metafiles in the new standard (the old standard would contain meta files. + $decommpressedfile = scandir($tempDirectoryHelp.dirname($tempDirectoryHelp), 1); + $tempDirectory = $tempDirectoryHelp.dirname($tempDirectoryHelp)."/".$decommpressedfile[0]; + $metaFiles = glob( $tempDirectory . "/*.meta" ); if (empty( $metaFiles )) { $metaFiles = glob( $tempDirectory . "/*.txt" ); @@ -173,9 +178,12 @@ class multipleFilesBackup if (file_exists( $workspace->path )) { G::rm_dir( $workspace->path ); } + + $tempDirectorySite = $tempDirectoryHelp.dirname($workspace->path); + foreach ($metadata->directories as $dir) { CLI::logging( "+> Restoring directory '$dir'\n" ); - if (! rename( "$tempDirectory/$dir", $workspace->path )) { + if (! rename( "$tempDirectorySite/$dir", $workspace->path )) { throw new Exception( "There was an error copying the backup files ($tempDirectory/$dir) to the workspace directory {$workspace->path}." ); } } @@ -197,13 +205,20 @@ class multipleFilesBackup if (! $link) { throw new Exception( 'Could not connect to system database: ' . mysql_error() ); } + + if (strpos($metadata->DB_RBAC_NAME, 'rb_') === false) { + $onedb = true; + } else { + $onedb = false; + } - $newDBNames = $workspace->resetDBInfo( $dbHost, $createWorkspace ); + $newDBNames = $workspace->resetDBInfo( $dbHost, $createWorkspace, $onedb ); + $aParameters = array('dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass); 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" ); + $workspace->executeSQLScript( $dbName, "$tempDirectory/{$db->name}.sql", $aParameters ); $workspace->createDBUser( $dbName, $db->pass, "localhost", $dbName ); $workspace->createDBUser( $dbName, $db->pass, "%", $dbName ); } diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index cd699f6ef..17397321c 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -1244,7 +1244,7 @@ class workspaceTools * @param string $hostname the hostname the user will be connecting from * @param string $database the database to grant permissions */ - private function createDBUser($username, $password, $hostname, $database) + public function createDBUser($username, $password, $hostname, $database) { mysql_select_db("mysql"); $hostname = array_shift(explode(":", $hostname)); @@ -1282,7 +1282,7 @@ class workspaceTools * @param string $filename the script filename * @param string $database the database to execute this script into */ - private function executeSQLScript($database, $filename, $parameters) + public function executeSQLScript($database, $filename, $parameters) { mysql_query("CREATE DATABASE IF NOT EXISTS " . mysql_real_escape_string($database));