HOR-3260 improvement

This commit is contained in:
Roly Rudy Gutierrez Pinto
2017-05-24 15:29:26 -04:00
parent 8a68563f83
commit 68b32a35f0
2 changed files with 43 additions and 29 deletions

View File

@@ -36,14 +36,45 @@ EOT
CLI::taskArg('workspace', true, true);
CLI::taskRun('run_flush_cache');
/**
* Flush the cache files for the specified workspace.
* If no workspace is specified, then the cache will be flushed in all available
* workspaces.
*
* @param array $args
* @param array $opts
*/
function run_flush_cache($args, $opts)
{
if (!defined("PATH_C")) {
die("ERROR: seems processmaker is not properly installed (System constants are missing)." . PHP_EOL);
}
$workspaces = get_workspaces_from_args($args);
if (count($args) === 1) {
\ProcessMaker\Util\System::flushCache($args, $opts);
flush_cache($workspaces[0]);
} else {
$workspaces = get_workspaces_from_args($args);
foreach ($workspaces as $workspace) {
passthru("./processmaker flush-cache " . $workspace->name);
}
}
}
/**
* Flush the cache files for the specified workspace.
*
* @param object $workspace
*/
function flush_cache($workspace)
{
try {
CLI::logging("Flush " . pakeColor::colorize("system", "INFO") . " cache ... ");
echo PHP_EOL;
echo " Update singleton in workspace " . $workspace->name . " ... ";
echo PHP_EOL;
echo " Flush workspace " . pakeColor::colorize($workspace->name, "INFO") . " cache ... " . PHP_EOL;
$status = \ProcessMaker\Util\System::flushCache($workspace);
echo "DONE" . PHP_EOL;
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}

View File

@@ -21,24 +21,14 @@ class System
}
/**
* Flush the cache files for the specified workspace(s).
* If no workspace is specified, then the cache will be flushed in all available
* workspaces.
* Flush the cache files for the specified workspace.
*
* @param array $args
* @param array $opts
* @param object $workspace
*/
public static function flushCache($args, $opts)
public static function flushCache($workspace)
{
$workspaces = get_workspaces_from_args($args);
if (!defined("PATH_C")) {
die("ERROR: seems processmaker is not properly installed (System constants are missing)." . PHP_EOL);
}
//Update singleton file by workspace
foreach ($workspaces as $workspace) {
eprint("Update singleton in workspace " . $workspace->name . " ... ");
try {
//Update singleton file by workspace
\Bootstrap::setConstantsRelatedWs($workspace->name);
$pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace->name . PATH_SEP . "plugin.singleton";
$oPluginRegistry = \PMPluginRegistry::loadSingleton($pathSingleton);
@@ -62,18 +52,10 @@ class System
}
}
}
eprintln("DONE");
}
//flush the cache files
\CLI::logging("Flush " . \pakeColor::colorize("system", "INFO") . " cache ... ");
\G::rm_dir(PATH_C);
\G::mk_dir(PATH_C, 0777);
echo "DONE" . PHP_EOL;
foreach ($workspaces as $workspace) {
echo "Flush workspace " . \pakeColor::colorize($workspace->name, "INFO") . " cache ... ";
//flush the cache files
\G::rm_dir(PATH_C);
\G::mk_dir(PATH_C, 0777);
\G::rm_dir($workspace->path . "/cache");
\G::mk_dir($workspace->path . "/cache", 0777);
\G::rm_dir($workspace->path . "/cachefiles");
@@ -81,7 +63,8 @@ class System
if (file_exists($workspace->path . '/routes.php')) {
unlink($workspace->path . '/routes.php');
}
echo "DONE" . PHP_EOL;
} catch (\Exception $e) {
throw new \Exception("Error: cannot perform this task. " . $e->getMessage());
}
}