Merged in victorsl/processmaker/3.0.1-GA (pull request #2598)

PM-3037 "0017677: The 'processmaker workspace-restore' command..." SOLVED
This commit is contained in:
Julio Cesar Laura Avendaño
2015-08-12 09:34:02 -04:00
3 changed files with 154 additions and 80 deletions

View File

@@ -669,13 +669,10 @@ function run_check_workspace_disabled_code($args, $opts)
function migrate_new_cases_lists($command, $args) { function migrate_new_cases_lists($command, $args) {
$workspaces = get_workspaces_from_args($args); $workspaces = get_workspaces_from_args($args);
$checkOnly = (strcmp($command, "migrate") == 0);
foreach ($workspaces as $workspace) { 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"); print_r("Upgrading database in " . pakeColor::colorize($workspace->name, "INFO") . "\n");
}
try { try {
$ws = $workspace->name; $ws = $workspace->name;
$sContent = file_get_contents (PATH_DB . $ws . PATH_SEP . 'db.php'); $sContent = file_get_contents (PATH_DB . $ws . PATH_SEP . 'db.php');
@@ -684,21 +681,16 @@ function migrate_new_cases_lists($command, $args) {
} else { } else {
$workspace->onedb = true; $workspace->onedb = true;
} }
//check if is the tables List are empty
$changes = $workspace->listFirstExecution('check'); if ($workspace->onedb) {
if ($workspace->onedb && $changes != true) { $workspace->migrateList($workspace->name, true);
$workspace->migrateList($workspace->name);
} }
if ($changes) {
if ($checkOnly) {
echo "-> List tables are done\n";
}
} else {
echo "> List tables are done\n"; echo "> List tables are done\n";
}
} catch (Exception $e) { } catch (Exception $e) {
echo "> Error: ".CLI::error($e->getMessage()) . "\n"; echo "> Error: ".CLI::error($e->getMessage()) . "\n";
} }
} }
} }
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/

View File

@@ -62,19 +62,17 @@ class workspaceTools
*/ */
public function upgrade($first = false, $buildCacheView = false, $workSpace = SYS_SYS, $onedb = false, $lang = 'en') public function upgrade($first = false, $buildCacheView = false, $workSpace = SYS_SYS, $onedb = false, $lang = 'en')
{ {
$start = microtime(true);
CLI::logging("> Verify enterprise old...\n");
$this->verifyFilesOldEnterprise($workSpace);
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Verify took $final seconds.\n");
$start = microtime(true); $start = microtime(true);
CLI::logging("> Updating database...\n"); CLI::logging("> Updating database...\n");
$this->upgradeDatabase($onedb); $this->upgradeDatabase($onedb);
$stop = microtime(true); $stop = microtime(true);
$final = $stop - $start; CLI::logging("<*> Database Upgrade Process took " . ($stop - $start) . " seconds.\n");
CLI::logging("<*> Database Upgrade Process took $final seconds.\n");
$start = microtime(true);
CLI::logging("> Verify enterprise old...\n");
$this->verifyFilesOldEnterprise($workSpace);
$stop = microtime(true);
CLI::logging("<*> Verify took " . ($stop - $start) . " seconds.\n");
$start = microtime(true); $start = microtime(true);
CLI::logging("> Updating translations...\n"); CLI::logging("> Updating translations...\n");
@@ -91,7 +89,7 @@ class workspaceTools
CLI::logging("<*> Updating Content Process took $final seconds.\n"); CLI::logging("<*> Updating Content Process took $final seconds.\n");
$start = microtime(true); $start = microtime(true);
CLI::logging("> check Mafe Requirements...\n"); CLI::logging("> Check Mafe Requirements...\n");
$this->checkMafeRequirements($workSpace, $lang); $this->checkMafeRequirements($workSpace, $lang);
$stop = microtime(true); $stop = microtime(true);
$final = $stop - $start; $final = $stop - $start;
@@ -490,15 +488,40 @@ class workspaceTools
return $aOldSchema; return $aOldSchema;
} }
/**
* Upgrade triggers of tables (Database)
*
* @param bool $flagRecreate Recreate
* @param string $language Language
*
* return void
*/
private function upgradeTriggersOfTables($flagRecreate, $language)
{
try {
$appCacheView = new AppCacheView();
$appCacheView->setPathToAppCacheFiles(PATH_METHODS . "setup" . PATH_SEP . "setupSchemas" . PATH_SEP);
$result = $appCacheView->triggerAppDelegationInsert($language, $flagRecreate);
$result = $appCacheView->triggerAppDelegationUpdate($language, $flagRecreate);
$result = $appCacheView->triggerApplicationUpdate($language, $flagRecreate);
$result = $appCacheView->triggerApplicationDelete($language, $flagRecreate);
$result = $appCacheView->triggerSubApplicationInsert($language, $flagRecreate);
$result = $appCacheView->triggerContentUpdate($language, $flagRecreate);
} catch (Exception $e) {
throw $e;
}
}
/** /**
* Upgrade the AppCacheView table to the latest system version. * Upgrade the AppCacheView table to the latest system version.
* *
* This recreates the table and populates with data. * This recreates the table and populates with data.
* *
* @param bool $checkOnly only check if the upgrade is needed if true * @param bool $flagRecreate only check if the upgrade is needed if true
* @param string $lang not currently used * @param string $lang not currently used
*/ */
public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en") public function upgradeCacheView($fill = true, $flagRecreate = false, $lang = "en")
{ {
$this->initPropel(true); $this->initPropel(true);
@@ -532,7 +555,7 @@ class workspaceTools
CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table \n"); CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table \n");
//Update APP_DELEGATION.DEL_LAST_INDEX data //Update APP_DELEGATION.DEL_LAST_INDEX data
$res = $appCache->updateAppDelegationDelLastIndex($lang, $checkOnly); $res = $appCache->updateAppDelegationDelLastIndex($lang, $flagRecreate);
CLI::logging("-> Verifying roles permissions in RBAC \n"); CLI::logging("-> Verifying roles permissions in RBAC \n");
//Update table RBAC permissions //Update table RBAC permissions
@@ -549,14 +572,9 @@ class workspaceTools
} }
CLI::logging("-> Creating triggers\n"); CLI::logging("-> Creating triggers\n");
//now check if we have the triggers installed //now check if we have the triggers installed
$triggers = array(); $this->upgradeTriggersOfTables($flagRecreate, $lang);
$triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly);
$triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly);
$triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly);
$triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly);
$triggers[] = $appCache->triggerSubApplicationInsert($lang, $checkOnly);
$triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly);
if ($fill) { if ($fill) {
CLI::logging("-> Rebuild Cache View with language $lang...\n"); CLI::logging("-> Rebuild Cache View with language $lang...\n");
@@ -1303,11 +1321,15 @@ class workspaceTools
$flagFunction = shell_exec('mysql --version'); $flagFunction = shell_exec('mysql --version');
} }
$arrayRegExpEngineSearch = array("/\)\s*TYPE\s*=\s*(InnoDB)/i", "/\)\s*TYPE\s*=\s*(MyISAM)/i");
$arrayRegExpEngineReplace = array(") ENGINE=\\1 DEFAULT CHARSET=utf8", ") ENGINE=\\1");
if ( !$flag && !is_null($flagFunction) ) { if ( !$flag && !is_null($flagFunction) ) {
//Replace TYPE by ENGINE //Replace TYPE by ENGINE
$script = file_get_contents($filename); $script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
$script = preg_replace('/\)TYPE\=InnoDB|\)\sTYPE\=InnoDB/', ')ENGINE=InnoDB DEFAULT CHARSET=utf8', $script);
file_put_contents($filename,$script); file_put_contents($filename,$script);
$aHost = explode(':',$parameters['dbHost']); $aHost = explode(':',$parameters['dbHost']);
$dbHost = $aHost[0]; $dbHost = $aHost[0];
if(isset($aHost[1])){ if(isset($aHost[1])){
@@ -1334,10 +1356,10 @@ class workspaceTools
//If the safe mode of the server is actived //If the safe mode of the server is actived
try { try {
mysql_select_db($database); mysql_select_db($database);
$script = file_get_contents($filename);
//Replace TYPE by ENGINE //Replace TYPE by ENGINE
$script = preg_replace('/\)TYPE\=InnoDB|\)\sTYPE\=InnoDB/', ')ENGINE=InnoDB DEFAULT CHARSET=utf8', $script); $script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
$lines = explode("\n", $script); $lines = explode("\n", $script);
$previous = null; $previous = null;
$insert = false; $insert = false;
@@ -1436,15 +1458,13 @@ class workspaceTools
static public function dirPerms($filename, $owner, $group, $perms) static public function dirPerms($filename, $owner, $group, $perms)
{ {
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$filename = $filter->xssFilterHard($filename, 'path');
$chown = @chown($filename, $owner); $chown = @chown($filename, $owner);
$chgrp = @chgrp($filename, $group); $chgrp = @chgrp($filename, $group);
$chmod = @chmod($filename, $perms); $chmod = @chmod($filename, $perms);
if ($chgrp === false || $chmod === false || $chown === false) { if ($chgrp === false || $chmod === false || $chown === false) {
if (strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN') { if (strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN') {
exec( 'icacls ' . $filename . ' /grant Administrador:(D,WDAC) /T', $res ); exec("icacls \"" . $filename . "\" /grant Administrador:(D,WDAC) /T", $res);
} else { } else {
CLI::logging(CLI::error("Failed to set permissions for $filename") . "\n"); CLI::logging(CLI::error("Failed to set permissions for $filename") . "\n");
} }
@@ -1509,14 +1529,13 @@ class workspaceTools
} }
$version = System::getVersion(); $version = System::getVersion();
$version = explode('-', $version); $pmVersion = (preg_match("/^([\d\.]+).*$/", $version, $arrayMatch))? $arrayMatch[1] : ""; //Otherwise: Branch master
$versionPresent = ( isset($version[0])) ? $version[0] : '';
CLI::logging(CLI::warning(" CLI::logging(CLI::warning("
Warning: A workspace from a newer version of ProcessMaker can NOT be restored in an older version of Warning: A workspace from a newer version of ProcessMaker can NOT be restored in an older version of
ProcessMaker. For example, restoring from v.3.0 to v.2.5 will not work. However, it may be possible ProcessMaker. For example, restoring from v.3.0 to v.2.5 will not work. However, it may be possible
to restore a workspace from an older version to an newer version of ProcessMaker, although error to restore a workspace from an older version to an newer version of ProcessMaker, although error
messages may be displayed during the restore process. Make sure to run the \"processmaker cacheview-repair\" messages may be displayed during the restore process.") . "\n");
and \"processmaker migrate-new-cases-lists\" commands after restoring a workspace.") . "\n");
foreach ($metaFiles as $metaFile) { foreach ($metaFiles as $metaFile) {
$metadata = G::json_decode(file_get_contents($metaFile)); $metadata = G::json_decode(file_get_contents($metaFile));
@@ -1549,7 +1568,6 @@ class workspaceTools
$workspace = new workspaceTools($workspaceName); $workspace = new workspaceTools($workspaceName);
if ($workspace->workspaceExists()) { if ($workspace->workspaceExists()) {
if ($overwrite) { if ($overwrite) {
if ($workspace->dbInfo['DB_NAME'] == $workspace->dbInfo['DB_RBAC_NAME']) { if ($workspace->dbInfo['DB_NAME'] == $workspace->dbInfo['DB_RBAC_NAME']) {
$newDatabases = 1; $newDatabases = 1;
@@ -1584,6 +1602,7 @@ class workspaceTools
CLI::logging("> Changing file permissions\n"); CLI::logging("> Changing file permissions\n");
$shared_stat = stat(PATH_DATA); $shared_stat = stat(PATH_DATA);
if ($shared_stat !== false) { if ($shared_stat !== false) {
workspaceTools::dirPerms($workspace->path, $shared_stat['uid'], $shared_stat['gid'], $shared_stat['mode']); workspaceTools::dirPerms($workspace->path, $shared_stat['uid'], $shared_stat['gid'], $shared_stat['mode']);
} else { } else {
@@ -1594,10 +1613,24 @@ class workspaceTools
$dbHost = $dbHost.$port; //127.0.0.1:3306 $dbHost = $dbHost.$port; //127.0.0.1:3306
} }
$aParameters = array('dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass); $aParameters = array('dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass);
//Restore
if (!defined("SYS_SYS")) {
define("SYS_SYS", $workspaceName);
}
if (!defined("PATH_DATA_SITE")) {
define("PATH_DATA_SITE", PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP);
}
$pmVersionWorkspaceToRestore = (preg_match("/^([\d\.]+).*$/", $metadata->PM_VERSION, $arrayMatch))? $arrayMatch[1] : "";
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);
@mysql_query("SET NAMES 'utf8';"); @mysql_query("SET NAMES 'utf8';");
@mysql_query("SET FOREIGN_KEY_CHECKS=0;"); @mysql_query("SET FOREIGN_KEY_CHECKS=0;");
@mysql_query("SET GLOBAL log_bin_trust_routine_creators = 1;");
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());
} }
@@ -1622,41 +1655,52 @@ class workspaceTools
} }
} }
$version = explode('-', $metadata->PM_VERSION); //CLI::logging(CLI::info("$pmVersionWorkspaceToRestore < $pmVersion") . "\n");
$versionOld = ( isset($version[0])) ? $version[0] : '';
CLI::logging(CLI::info("$versionOld < $versionPresent") . "\n"); if (version_compare($pmVersionWorkspaceToRestore . "", $pmVersion . "", "<") || $pmVersion == "") {
$start = microtime(true);
CLI::logging("> Updating database...\n");
$workspace->upgradeDatabase($onedb);
$stop = microtime(true);
CLI::logging("<*> Database Upgrade Process took " . ($stop - $start) . " seconds.\n");
}
$start = microtime(true); $start = microtime(true);
CLI::logging("> Verify files enterprise old...\n"); CLI::logging("> Verify files enterprise old...\n");
$workspace->verifyFilesOldEnterprise($workspaceName); $workspace->verifyFilesOldEnterprise($workspaceName);
$stop = microtime(true); $stop = microtime(true);
$final = $stop - $start; CLI::logging("<*> Verify took " . ($stop - $start) . " seconds.\n");
CLI::logging("<*> Verify took $final seconds.\n");
if ( $versionOld < $versionPresent || strpos($versionPresent, "Branch")) {
$start = microtime(true);
CLI::logging("> Updating database...\n");
$workspace->upgradeDatabase($onedb);
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Database Upgrade Process took $final seconds.\n");
}
$start = microtime(true); $start = microtime(true);
CLI::logging("> Verify License Enterprise...\n"); CLI::logging("> Verify License Enterprise...\n");
$workspace->verifyLicenseEnterprise($workspaceName); $workspace->verifyLicenseEnterprise($workspaceName);
$stop = microtime(true); $stop = microtime(true);
$final = $stop - $start; CLI::logging("<*> Verify took " . ($stop - $start) . " seconds.\n");
CLI::logging("<*> Verify took $final seconds.\n");
$start = microtime(true);
CLI::logging("> Check Mafe Requirements...\n");
$workspace->checkMafeRequirements($workspaceName, $lang); $workspace->checkMafeRequirements($workspaceName, $lang);
$stop = microtime(true);
CLI::logging("<*> Check Mafe Requirements Process took " . ($stop - $start) . " seconds.\n");
if (version_compare($pmVersionWorkspaceToRestore . "", $pmVersion . "", "<") || $pmVersion == "") {
$start = microtime(true);
CLI::logging("> Updating cache view...\n");
$workspace->upgradeCacheView(true, true, $lang);
$stop = microtime(true);
CLI::logging("<*> Updating cache view Process took " . ($stop - $start) . " seconds.\n");
} else {
$workspace->upgradeTriggersOfTables(true, $lang);
}
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
if (version_compare($pmVersionWorkspaceToRestore . "", "2.9", "<") || $pmVersion == "") {
$start = microtime(true); $start = microtime(true);
CLI::logging("> Updating List tables...\n"); CLI::logging("> Updating List tables...\n");
$workspace->migrateList($workspace->name); $workspace->migrateList($workspace->name);
$stop = microtime(true); $stop = microtime(true);
$final = $stop - $start; CLI::logging("<*> Updating List Process took " . ($stop - $start) . " seconds.\n");
CLI::logging("<*> Updating List Process took $final seconds.\n"); }
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
mysql_close($link); mysql_close($link);
@@ -1914,17 +1958,50 @@ class workspaceTools
/** /**
* Migrate all cases to New list * Migrate all cases to New list
* *
* @param string $workSpace Workspace
* @param bool $flagReinsert Flag that specifies the re-insertion
*
* return all LIST TABLES with data * return all LIST TABLES with data
*/ */
public function migrateList ($workSpace) public function migrateList($workSpace, $flagReinsert = false)
{ {
if ($this->listFirstExecution('check')) { $this->initPropel(true);
G::LoadClass("case");
if (!$flagReinsert && $this->listFirstExecution("check")) {
return 1; return 1;
} }
$this->initPropel(true);
if ($flagReinsert) {
//Delete all records
$arrayTable = array("ListInbox", "ListMyInbox", "ListCanceled", "ListParticipatedLast", "ListParticipatedHistory", "ListPaused", "ListCompleted", "ListUnassigned", "ListUnassignedGroup");
foreach ($arrayTable as $value) {
$tableName = $value . "Peer";
$list = new $tableName();
$list->doDeleteAll();
}
//Update //User
$criteriaSet = new Criteria("workflow");
$criteriaSet->add(UsersPeer::USR_TOTAL_INBOX, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_DRAFT, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_CANCELLED, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_PARTICIPATED, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_PAUSED, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_COMPLETED, 0);
$criteriaSet->add(UsersPeer::USR_TOTAL_UNASSIGNED, 0);
$criteriaWhere = new Criteria("workflow");
$criteriaWhere->add(UsersPeer::USR_UID, null, Criteria::ISNOTNULL);
BasePeer::doUpdate($criteriaWhere, $criteriaSet, Propel::getConnection("workflow"));
}
$appCache = new AppCacheView(); $appCache = new AppCacheView();
$users = new Users(); $users = new Users();
G::LoadClass("case");
$case = new Cases(); $case = new Cases();
//Select data CANCELLED //Select data CANCELLED
@@ -2106,7 +2183,12 @@ class workspaceTools
); );
$users->update($newData); $users->update($newData);
} }
$this->listFirstExecution('insert');
if (!$flagReinsert) {
$this->listFirstExecution("insert");
}
//Return
return true; return true;
} }

View File

@@ -1417,7 +1417,7 @@ class AppCacheView extends BaseAppCacheView
} }
if (!$found) { if (!$found) {
$filenameSql = $this->pathToAppCacheFiles . '/triggerAppDelegationUpdate.sql'; $filenameSql = $this->pathToAppCacheFiles . "triggerAppDelegationUpdate.sql";
if (!file_exists($filenameSql)) { if (!file_exists($filenameSql)) {
throw (new Exception("file triggerAppDelegationUpdate.sql does not exist ")); throw (new Exception("file triggerAppDelegationUpdate.sql does not exist "));
@@ -1462,7 +1462,7 @@ class AppCacheView extends BaseAppCacheView
} }
if (!$found) { if (!$found) {
$filenameSql = $this->pathToAppCacheFiles . '/triggerApplicationUpdate.sql'; $filenameSql = $this->pathToAppCacheFiles . "triggerApplicationUpdate.sql";
if (!file_exists($filenameSql)) { if (!file_exists($filenameSql)) {
throw (new Exception("file triggerApplicationUpdate.sql doesn't exist ")); throw (new Exception("file triggerApplicationUpdate.sql doesn't exist "));
@@ -1507,7 +1507,7 @@ class AppCacheView extends BaseAppCacheView
} }
if (!$found) { if (!$found) {
$filenameSql = $this->pathToAppCacheFiles . '/triggerApplicationDelete.sql'; $filenameSql = $this->pathToAppCacheFiles . "triggerApplicationDelete.sql";
if (!file_exists($filenameSql)) { if (!file_exists($filenameSql)) {
throw (new Exception("file triggerApplicationDelete.sql doesn't exist")); throw (new Exception("file triggerApplicationDelete.sql doesn't exist"));
@@ -1545,7 +1545,7 @@ class AppCacheView extends BaseAppCacheView
} }
if (!$found) { if (!$found) {
$filenameSql = $this->pathToAppCacheFiles . PATH_SEP . "triggerContentUpdate.sql"; $filenameSql = $this->pathToAppCacheFiles . "triggerContentUpdate.sql";
if (!file_exists($filenameSql)) { if (!file_exists($filenameSql)) {
throw (new Exception("file triggerContentUpdate.sql doesn't exist")); throw (new Exception("file triggerContentUpdate.sql doesn't exist"));
@@ -1621,7 +1621,7 @@ class AppCacheView extends BaseAppCacheView
$triggers = array(); $triggers = array();
foreach ($triggerFiles as $triggerFile) { foreach ($triggerFiles as $triggerFile) {
$trigger = file_get_contents("{$this->pathToAppCacheFiles}/$triggerFile"); $trigger = file_get_contents($this->pathToAppCacheFiles . $triggerFile);
if ($trigger === false) { if ($trigger === false) {
throw new Exception("Could not read trigger contents in $triggerFile"); throw new Exception("Could not read trigger contents in $triggerFile");