Fix some issues when restoring a workspace.

This commit is contained in:
Alexandre Rosenfeld
2011-03-10 15:18:52 +00:00
parent 4365f2065b
commit e29dfb6ca9

View File

@@ -702,11 +702,15 @@ class workspaceTools {
*/ */
private function addToBackup($backup, $filename, $pathRoot, $archiveRoot = "") { private function addToBackup($backup, $filename, $pathRoot, $archiveRoot = "") {
if (is_file($filename)) { if (is_file($filename)) {
CLI::logging("-> $filename\n");
$backup->addModify($filename, $archiveRoot, $pathRoot); $backup->addModify($filename, $archiveRoot, $pathRoot);
} else { } else {
foreach (glob($filename . "/*") as $item) { CLI::logging(" + $filename\n");
$this->addToBackup($backup, $item, $pathRoot, $archiveRoot); $backup->addModify($filename, $archiveRoot, $pathRoot);
} //foreach (glob($filename . "/*") as $item) {
// $this->addToBackup($backup, $item, $pathRoot, $archiveRoot);
//}
} }
} }
@@ -826,6 +830,7 @@ class workspaceTools {
* @param string $database the database to execute this script into * @param string $database the database to execute this script into
*/ */
private function executeSQLScript($database, $filename) { private function executeSQLScript($database, $filename) {
mysql_query("CREATE DATABASE IF NOT EXISTS " . mysql_real_escape_string($database));
mysql_select_db($database); mysql_select_db($database);
$script = file_get_contents($filename); $script = file_get_contents($filename);
$lines = explode("\n", $script); $lines = explode("\n", $script);
@@ -908,26 +913,28 @@ class workspaceTools {
//Search for metafiles in the new standard (the old standard would contain //Search for metafiles in the new standard (the old standard would contain
//txt files). //txt files).
$metaFiles = glob($tempDirectory . "/*.meta"); $metaFiles = glob($tempDirectory . "/*.meta");
print_r($metaFiles);
if (empty($metaFiles)) { if (empty($metaFiles)) {
$metaFiles = glob($tempDirectory . "/*.txt"); $metaFiles = glob($tempDirectory . "/*.txt");
if (!empty($metaFiles)) if (!empty($metaFiles))
return workspaceTools::restoreLegacy($tempDirectory); return workspaceTools::restoreLegacy($tempDirectory);
else else
throw new Exception("No metadata found in backup"); throw new Exception("No metadata found in backup");
} else {
CLI::logging("Found " . count($metaFiles) . " workspaces in backup:\n");
foreach ($metaFiles as $metafile)
CLI::logging("-> " . basename($metafile) . "\n");
} }
if (isset($srcWorkspace) && count($metaFiles) > 0) if (count($metaFiles) > 1 && (!isset($srcWorkspace)))
throw new Exception("Multiple workspaces in backup but no workspace specified to restore"); throw new Exception("Multiple workspaces in backup but no workspace specified to restore");
if (isset($srcWorkspace) && !in_array("$srcWorkspace.meta", $metaFiles)) if (isset($srcWorkspace) && !in_array("$srcWorkspace.meta", $metaFiles))
throw new Exception("Workspace $srcWorkspace not found in backup"); throw new Exception("Workspace $srcWorkspace not found in backup");
foreach ($metaFiles as $metaFile) { foreach ($metaFiles as $metaFile) {
$metadata = G::json_decode(file_get_contents($metaFile)); $metadata = G::json_decode(file_get_contents($metaFile));
print_r($metadata);
if ($metadata->version != 1) if ($metadata->version != 1)
throw new Exception("Backup version {$metadata->version} not supported"); throw new Exception("Backup version {$metadata->version} not supported");
$backupWorkspace = $metadata->WORKSPACE_NAME; $backupWorkspace = $metadata->WORKSPACE_NAME;
if (isset($srcWorkspace)) { if (isset($dstWorkspace)) {
$workspaceName = $srcWorkspace; $workspaceName = $dstWorkspace;
$createWorkspace = true; $createWorkspace = true;
} else { } else {
$workspaceName = $metadata->WORKSPACE_NAME; $workspaceName = $metadata->WORKSPACE_NAME;
@@ -944,7 +951,7 @@ class workspaceTools {
if ($overwrite) if ($overwrite)
CLI::logging("Workspace $workspaceName already exists, overwriting!\n"); CLI::logging("Workspace $workspaceName already exists, overwriting!\n");
else else
throw new Exception("Destination workspace already exists and not overwriting"); throw new Exception("Destination workspace already exists (use -o to overwrite)");
if (file_exists($workspace->path)) if (file_exists($workspace->path))
G::rm_dir($workspace->path); G::rm_dir($workspace->path);
@@ -959,7 +966,7 @@ class workspaceTools {
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH)); list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
CLI::logging("Connecting to system database in $dbHost\n"); CLI::logging("Connecting to system database in '$dbHost'\n");
$link = mysql_connect($dbHost, $dbUser, $dbPass); $link = mysql_connect($dbHost, $dbUser, $dbPass);
if (!$link) if (!$link)
throw new Exception('Could not connect to system database: ' . mysql_error()); throw new Exception('Could not connect to system database: ' . mysql_error());