. * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. * * @author Alexandre Rosenfeld * @package workflow-engine-bin-tasks */ CLI::taskName('info'); CLI::taskDescription(<<printMetadata(false); } } function run_workspace_upgrade($args, $opts) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $opts = $filter->xssFilterHard($opts); $args = $filter->xssFilterHard($args); $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, $lang); $first = false; } catch (Exception $e) { echo "Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"; } } } function run_translation_upgrade($args, $opts) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $opts = $filter->xssFilterHard($opts); $args = $filter->xssFilterHard($args); $workspaces = get_workspaces_from_args($args); $first = true; foreach ($workspaces as $workspace) { try { echo "Upgrading translation for " . pakeColor::colorize($workspace->name, "INFO") . "\n"; $workspace->upgradeTranslation($first); $first = false; } catch (Exception $e) { echo "Errors upgrading translation of workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"; } } } function run_cacheview_upgrade($args, $opts) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $opts = $filter->xssFilterHard($opts); $args = $filter->xssFilterHard($args); $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(true, false, $lang); } catch (Exception $e) { echo "Errors upgrading cache view of workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"; } } } function run_plugins_database_upgrade($args, $opts) { $workspaces = get_workspaces_from_args($args); foreach ($workspaces as $workspace) { try { CLI::logging("Upgrading plugins database for " . CLI::info($workspace->name) . "\n"); $workspace->upgradePluginsDatabase(); } catch (Exception $e) { CLI::logging("Errors upgrading plugins database: " . CLI::error($e->getMessage())); } } } function run_database_export($args, $opts) { if (count($args) < 2) throw new Exception ("Please provide a workspace name and a directory for export"); $workspace = new workspaceTools($args[0]); $workspace->exportDatabase($args[1]); } function run_database_import($args, $opts) { throw new Exception("Not implemented"); } function run_database_upgrade($args, $opts) { database_upgrade("upgrade", $args); } 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) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $command = $filter->xssFilterHard($command); $args = $filter->xssFilterHard($args); $workspaces = get_workspaces_from_args($args); $checkOnly = (strcmp($command, "check") == 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 { $changes = $workspace->upgradeDatabase($checkOnly); if ($changes != false) { if ($checkOnly) { echo "> ".pakeColor::colorize("Run upgrade", "INFO")."\n"; echo " Tables (add = " . count($changes['tablesToAdd']); echo ", alter = " . count($changes['tablesToAlter']) . ") "; echo "- Indexes (add = " . count($changes['tablesWithNewIndex']).""; echo ", alter = " . count($changes['tablesToAlterIndex']).")\n"; } else { echo "-> Schema fixed\n"; } } else { echo "> OK\n"; } } catch (Exception $e) { echo "> Error: ".CLI::error($e->getMessage()) . "\n"; } } } function delete_app_from_table($con, $tableName, $appUid, $col="APP_UID") { $stmt = $con->createStatement(); $sql = "DELETE FROM " . $tableName . " WHERE " . $col . "='" . $appUid . "'"; $rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM); } function run_drafts_clean($args, $opts) { echo "Cleaning drafts\n"; if (count($args) < 1) throw new Exception ("Please specify a workspace name"); $workspace = $args[0]; if (!file_exists(PATH_DB . $workspace . '/db.php')) { throw new Exception('Could not find workspace ' . $workspace); } $allDrafts = false; if (count($args) < 2) { echo "Cases older them this much days will be deleted (ENTER for all): "; $days = rtrim( fgets( STDIN ), "\n" ); if ($days == "") { $allDrafts = true; } } else { $days = $args[1]; if (strcmp($days, "all") == 0) { $allDrafts = true; } } if (!$allDrafts && (!is_numeric($days) || intval($days) <= 0)) { throw new Exception("Days value is not valid: " . $days); } if ($allDrafts) echo "Removing all drafts\n"; else echo "Removing drafts older than " . $days . " days\n"; /* Load the configuration from the workspace */ require_once( PATH_DB . $workspace . '/db.php' ); require_once( PATH_THIRDPARTY . 'propel/Propel.php'); PROPEL::Init ( PATH_METHODS.'dbConnections/rootDbConnections.php' ); $con = Propel::getConnection("root"); $stmt = $con->createStatement(); if (!$allDrafts) $dateSql = "AND DATE_SUB(CURDATE(),INTERVAL " . $days . " DAY) >= APP_CREATE_DATE"; else $dateSql = ""; /* Search for all the draft cases */ $sql = "SELECT APP_UID FROM APPLICATION WHERE APP_STATUS='DRAFT'" . $dateSql; $appRows = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); /* Tables to remove the cases from */ $tables = array( "APPLICATION", "APP_DELEGATION", "APP_CACHE_VIEW", "APP_THREAD", "APP_DOCUMENT", "APP_EVENT", "APP_HISTORY", "APP_MESSAGE" ); echo "Found " . $appRows->getRecordCount() . " cases to remove"; foreach ($appRows as $row) { echo "."; $appUid = $row['APP_UID']; foreach ($tables as $table) { delete_app_from_table($con, $table, $appUid); } delete_app_from_table($con, "CONTENT", $appUid, "CON_ID"); if (file_exists(PATH_DB . $workspace . '/files/'. $appUid)) { echo "\nRemoving files from " . $appUid . "\n"; G::rm_dir(PATH_DB . $workspace . '/files/'. $appUid); } } echo "\n"; } function run_workspace_backup($args, $opts) { $workspaces = array(); if (sizeof($args) > 2) { $filename = array_pop($args); foreach ($args as $arg) { $workspaces[] = new workspaceTools($arg); } } else if (sizeof($args) > 0) { $workspace = new workspaceTools($args[0]); $workspaces[] = $workspace; if (sizeof($args) == 2) { $filename = $args[1]; } else { $filename = "{$workspace->name}.tar"; } } else { throw new Exception("No workspace specified for backup"); } foreach ($workspaces as $workspace) { if (!$workspace->workspaceExists()) { throw new Exception("Workspace '{$workspace->name}' not found"); } } //If this is a relative path, put the file in the backups directory if (strpos($filename, "/") === false && strpos($filename, '\\') === false){ $filename = PATH_DATA . "backups/$filename"; } CLI::logging("Backing up to $filename\n"); $filesize = array_key_exists("filesize", $opts) ? $opts['filesize'] : -1; if ($filesize >= 0) { if (!Bootstrap::isLinuxOs()) { CLI::error("This is not a Linux enviroment, cannot use this filesize [-s] feature.\n"); return; } $multipleBackup = new multipleFilesBackup ($filename,$filesize);//if filesize is 0 the default size will be took //using new method foreach ($workspaces as $workspace) { $multipleBackup->addToBackup($workspace); } $multipleBackup->letsBackup(); } else { //ansient method to backup into one large file $backup = workspaceTools::createBackup($filename); foreach ($workspaces as $workspace) { $workspace->backup($backup); } } CLI::logging("\n"); workspaceTools::printSysInfo(); foreach ($workspaces as $workspace) { CLI::logging("\n"); $workspace->printMetadata(false); } } function run_workspace_restore($args, $opts) { $filename = $args[0]; G::verifyPath(PATH_DATA . 'upgrade', true); if (strpos($filename, "/") === false && strpos($filename, '\\') === false) { $filename = PATH_DATA . "backups/$filename"; if (!file_exists($filename) && substr_compare($filename, ".tar", -4, 4, true) != 0) $filename .= ".tar"; } $info = array_key_exists("info", $opts); $lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en'; if ($info) { workspaceTools::getBackupInfo($filename); } else { CLI::logging("Restoring from $filename\n"); $workspace = array_key_exists("workspace", $opts) ? $opts['workspace'] : NULL; $overwrite = array_key_exists("overwrite", $opts); $multiple = array_key_exists("multiple", $opts); $dstWorkspace = isset($args[1]) ? $args[1] : null; if(!empty($multiple)){ if(!Bootstrap::isLinuxOs()){ CLI::error("This is not a Linux enviroment, cannot use this multiple [-m] feature.\n"); return; } multipleFilesBackup::letsRestore ($filename,$workspace,$dstWorkspace,$overwrite); } else{ $anotherExtention = ".*"; //if there are files with and extra extention: e.g. .tar.number $multiplefiles = glob($filename . $anotherExtention);// example: //shared/workflow_data/backups/myWorkspace.tar.* if(count($multiplefiles) > 0) { CLI::error("Processmaker found these files: .\n"); foreach($multiplefiles as $index => $value){ CLI::logging($value . "\n"); } CLI::error("Please, you should use -m parameter to restore them.\n"); return; } workspaceTools::restore($filename, $workspace, $dstWorkspace, $overwrite, $lang); } } } function runStructureDirectories($command, $args) { $workspaces = get_workspaces_from_args($command); $count = count($workspaces); $errors = false; $countWorkspace = 0; foreach ($workspaces as $index => $workspace) { try { $countWorkspace++; CLI::logging("Updating workspaces ($countWorkspace/$count): " . CLI::info($workspace->name) . "\n"); $workspace->updateStructureDirectories($workspace->name); $workspace->close(); } catch (Exception $e) { CLI::logging("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"); $errors = true; } } } function run_database_generate_self_service_by_value($args, $opts) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $opts = $filter->xssFilterHard($opts); $args = $filter->xssFilterHard($args); try { $arrayWorkspace = get_workspaces_from_args($args); foreach ($arrayWorkspace as $value) { $workspace = $value; try { echo "Generating the table \"self-service by value\" for " . pakeColor::colorize($workspace->name, "INFO") . "\n"; $workspace->appAssignSelfServiceValueTableGenerateData(); } catch (Exception $e) { echo "Errors generating the table \"self-service by value\" of workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"; } echo "\n"; } echo "Done!\n"; } catch (Exception $e) { echo CLI::error($e->getMessage()) . "\n"; } } /*----------------------------------********---------------------------------*/ function run_check_workspace_disabled_code($args, $opts) { try { $arrayWorkspace = get_workspaces_from_args($args); foreach ($arrayWorkspace as $value) { $workspace = $value; echo "> Workspace: " . $workspace->name . "\n"; try { $arrayFoundDisabledCode = $workspace->getDisabledCode(); if (count($arrayFoundDisabledCode) > 0) { $strFoundDisabledCode = ""; foreach ($arrayFoundDisabledCode as $value2) { $arrayProcessData = $value2; $strFoundDisabledCode .= ($strFoundDisabledCode != "")? "\n" : ""; $strFoundDisabledCode .= " Process: " . $arrayProcessData["processTitle"] . "\n"; $strFoundDisabledCode .= " Triggers:\n"; foreach ($arrayProcessData["triggers"] as $value3) { $arrayTriggerData = $value3; $strCodeAndLine = ""; foreach ($arrayTriggerData["disabledCode"] as $key4 => $value4) { $strCodeAndLine .= (($strCodeAndLine != "")? ", " : "") . $key4 . " (Lines " . implode(", ", $value4) . ")"; } $strFoundDisabledCode .= " - " . $arrayTriggerData["triggerTitle"] . ": " . $strCodeAndLine . "\n"; } } echo $strFoundDisabledCode . "\n"; } else { echo "The workspace it's OK\n\n"; } } catch (Exception $e) { echo "Errors to check disabled code: " . CLI::error($e->getMessage()) . "\n\n"; } } echo "Done!\n"; } catch (Exception $e) { 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 "-> List tables are done\n"; } } else { echo "> List tables are done\n"; } } catch (Exception $e) { echo "> Error: ".CLI::error($e->getMessage()) . "\n"; } } } /*----------------------------------********---------------------------------*/