BUG-11707 Al realizar workspace-restore de un backup creado... SOLVED

- Not update the schema.
- add validation to restore.
This commit is contained in:
Marco Antonio Nina
2013-05-17 10:39:48 -04:00
parent 7cb1f081c9
commit 4375be498d
2 changed files with 48 additions and 12 deletions

View File

@@ -74,6 +74,7 @@ CLI::taskOpt("info", "Only shows information about a backup archive.", "i");
CLI::taskOpt("multiple", "Restore from multiple compresed enumerated files.", "m");
CLI::taskOpt("workspace", "Select which workspace to restore if multiple workspaces are present in the archive.",
"w:", "workspace=");
CLI::taskOpt("lang", "Set the language for upgrade cacheView, by default en.", "l:","lang=");
CLI::taskRun(run_workspace_restore);
CLI::taskName('cacheview-repair');
@@ -91,6 +92,7 @@ CLI::taskDescription(<<<EOT
EOT
);
CLI::taskArg('workspace', true, true);
CLI::taskOpt("lang", "Set the language for upgrade cacheView, by default en.", "l:","lang=");
CLI::taskRun(run_cacheview_upgrade);
CLI::taskName('database-upgrade');
@@ -174,9 +176,10 @@ function run_info($args, $opts) {
function run_workspace_upgrade($args, $opts) {
$workspaces = get_workspaces_from_args($args);
$first = true;
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en';
foreach ($workspaces as $workspace) {
try {
$workspace->upgrade($first, false, $workspace->name);
$workspace->upgrade($first, false, $workspace->name, $lang);
$first = false;
} catch (Exception $e) {
echo "Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n";
@@ -200,10 +203,11 @@ function run_translation_upgrade($args, $opts) {
function run_cacheview_upgrade($args, $opts) {
$workspaces = get_workspaces_from_args($args);
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en';
foreach ($workspaces as $workspace) {
try {
echo "Upgrading cache view for " . pakeColor::colorize($workspace->name, "INFO") . "\n";
$workspace->upgradeCacheView();
$workspace->upgradeCacheView(true, false, $lang);
} catch (Exception $e) {
echo "Errors upgrading translation of workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n";
}
@@ -423,6 +427,7 @@ function run_workspace_restore($args, $opts) {
$filename .= ".tar";
}
$info = array_key_exists("info", $opts);
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en';
if ($info) {
workspaceTools::getBackupInfo($filename);
} else {
@@ -450,7 +455,7 @@ function run_workspace_restore($args, $opts) {
CLI::error("Please, you should use -m parameter to restore them.\n");
return;
}
workspaceTools::restore($filename, $workspace, $dstWorkspace, $overwrite);
workspaceTools::restore($filename, $workspace, $dstWorkspace, $overwrite, $lang);
}
}
}

View File

@@ -60,7 +60,7 @@ class workspaceTools
*
* @param bool $first true if this is the first workspace to be upgrade
*/
public function upgrade($first = false, $buildCacheView = false, $workSpace = SYS_SYS)
public function upgrade($first = false, $buildCacheView = false, $workSpace = SYS_SYS, $lang = 'en')
{
$start = microtime(true);
CLI::logging("> Updating database...\n");
@@ -85,7 +85,7 @@ class workspaceTools
$start = microtime(true);
CLI::logging("> Updating cache view...\n");
$this->upgradeCacheView($buildCacheView, true);
$this->upgradeCacheView($buildCacheView, true, $lang);
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Process Updating cache view carried out in $final seconds.\n");
@@ -424,12 +424,10 @@ class workspaceTools
* @param bool $checkOnly only check if the upgrade is needed if true
* @param string $lang not currently used
*/
public function upgradeCacheView($fill = true, $checkOnly = false)
public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en")
{
$this->initPropel(true);
$lang = "en";
//require_once ('classes/model/AppCacheView.php');
//check the language, if no info in config about language, the default is 'en'
G::LoadClass("configuration");
@@ -472,7 +470,7 @@ class workspaceTools
$triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly);
if ($fill) {
CLI::logging("-> Rebuild Cache View\n");
CLI::logging("-> Rebuild Cache View with language $lang...\n");
//build using the method in AppCacheView Class
$res = $appCache->fillAppCacheView($lang);
//set status in config table
@@ -1126,7 +1124,7 @@ class workspaceTools
* @param string $newWorkspaceName if defined, supplies the name for the
* workspace to restore to
*/
static public function restore($filename, $srcWorkspace, $dstWorkspace = null, $overwrite = true)
static public function restore($filename, $srcWorkspace, $dstWorkspace = null, $overwrite = true, $lang = 'en')
{
G::LoadThirdParty('pear/Archive', 'Tar');
$backup = new Archive_Tar($filename);
@@ -1164,6 +1162,15 @@ class workspaceTools
if (isset($srcWorkspace) && !in_array("$srcWorkspace.meta", array_map(BASENAME, $metaFiles))) {
throw new Exception("Workspace $srcWorkspace not found in backup");
}
$version = System::getVersion();
$version = explode('-', $version);
$versionPresent = ( isset($version[0])) ? $version[0] : '';
CLI::logging(CLI::warning("
Note.- If you try to execute a restore from a generated backup on a recent version of Processmaker
than version you are using currently to restore it, it may be occur errors on the restore process,
it shouldn't be restaured generated backups on later versions than version when the restore is executed") . "\n");
foreach ($metaFiles as $metaFile) {
$metadata = G::json_decode(file_get_contents($metaFile));
if ($metadata->version != 1) {
@@ -1235,7 +1242,31 @@ class workspaceTools
$workspace->createDBUser($dbName, $db->pass, "%", $dbName);
}
$workspace->upgradeCacheView(false);
$version = explode('-', $metadata->PM_VERSION);
$versionOld = ( isset($version[0])) ? $version[0] : '';
CLI::logging(CLI::info("$versionOld < $versionPresent") . "\n");
if ( $versionOld < $versionPresent) {
$start = microtime(true);
CLI::logging("> Updating database...\n");
$workspace->upgradeDatabase();
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Process Updating database carried out in $final seconds.\n");
$start = microtime(true);
CLI::logging("> Updating cases directories structure...\n");
$workspace->upgradeCasesDirectoryStructure($workspaceName);
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Process Updating directories structure carried out in $final seconds.\n");
}
$start = microtime(true);
CLI::logging("> Updating cache view...\n");
$workspace->upgradeCacheView(true, false, $lang);
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Process Updating cache view carried out in $final seconds.\n");
mysql_close($link);
}