I solved the issue PM-1649 ./processmaker migrate-new-cases-lists

This commit is contained in:
Paula V. Quispe
2015-03-04 18:42:47 -04:00
parent f4a65aa184
commit 1f497cc6f6
10 changed files with 500 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php
/**
* cliWorkspaces.php
*
@@ -199,6 +199,19 @@ EOT
);
CLI::taskArg("workspace-name", true, true);
CLI::taskRun("run_check_workspace_disabled_code");
CLI::taskName('migrate-new-cases-lists');
CLI::taskDescription(<<<EOT
Migrating the list cases schema to match the latest version
  Specify the WORKSPACE to migrate from a existing workspace.
If no workspace is specified, then the tables schema will be upgraded or
migrate on all available workspaces.
EOT
);
CLI::taskArg('workspace', true, true);
CLI::taskRun("run_migrate_new_cases_lists");
/*----------------------------------********---------------------------------*/
/**
@@ -286,6 +299,10 @@ function run_database_check($args, $opts) {
database_upgrade("check", $args);
}
function run_migrate_new_cases_lists($args, $opts) {
migrate_new_cases_lists("migrate", $args);
}
function database_upgrade($command, $args) {
$workspaces = get_workspaces_from_args($args);
$checkOnly = (strcmp($command, "check") == 0);
@@ -642,4 +659,39 @@ function run_check_workspace_disabled_code($args, $opts)
echo CLI::error($e->getMessage()) . "\n";
}
}
/*----------------------------------********---------------------------------*/
function migrate_new_cases_lists($command, $args) {
$workspaces = get_workspaces_from_args($args);
$checkOnly = (strcmp($command, "migrate") == 0);
foreach ($workspaces as $workspace) {
if ($checkOnly){
print_r("Checking database in ".pakeColor::colorize($workspace->name, "INFO")."\n");
} else {
print_r("Upgrading database in ".pakeColor::colorize($workspace->name, "INFO")."\n");
}
try {
$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;
}
//check if is the tables List are empty
$changes = $workspace->listFirstExecution('check');
if ($workspace->onedb && $changes != true) {
$workspace->migrateList($workspace->name);
}
if ($changes) {
if ($checkOnly) {
echo "-> Schema fixed\n";
}
} else {
echo "> List tables are done\n";
}
} catch (Exception $e) {
echo "> Error: ".CLI::error($e->getMessage()) . "\n";
}
}
}
/*----------------------------------********---------------------------------*/