Merged in bugfix/HOR-2967 (pull request #5628)

HOR-2967

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly
2017-05-17 18:48:16 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 120 additions and 99 deletions

View File

@@ -38,17 +38,64 @@ CLI::taskRun('run_flush_cache');
function run_flush_cache($args, $opts)
{
$rootDir = realpath(__DIR__."/../../../../");
if (count($args) === 1) {
flush_cache($args, $opts);
} 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(s).
* If no workspace is specified, then the cache will be flushed in all available
* workspaces.
*
* @param type $args
* @param type $opts
*/
function flush_cache($args, $opts)
{
$rootDir = realpath(__DIR__ . "/../../../../");
$app = new Maveriks\WebApplication();
$app->setRootDir($rootDir);
$loadConstants = false;
$workspaces = get_workspaces_from_args($args);
if (! defined("PATH_C")) {
die("ERROR: seems processmaker is not properly installed (System constants are missing).".PHP_EOL);
if (!defined("PATH_C")) {
die("ERROR: seems processmaker is not properly installed (System constants are missing)." . PHP_EOL);
}
CLI::logging("Flush ".pakeColor::colorize("system", "INFO")." cache ... ");
//Update singleton file by workspace
foreach ($workspaces as $workspace) {
eprint("Update singleton in workspace " . $workspace->name . " ... ");
Bootstrap::setConstantsRelatedWs($workspace->name);
$pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace->name . PATH_SEP . "plugin.singleton";
$oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton);
$items = \PMPlugin::getlist($workspace->name);
foreach ($items as $item) {
if ($item["sStatusFile"] === true) {
$path = PATH_PLUGINS . $item["sFile"];
require_once($path);
$details = $oPluginRegistry->getPluginDetails($item["sFile"]);
//Only if the API directory structure is defined
$pathApiDirectory = PATH_PLUGINS . $details->sPluginFolder . PATH_SEP . "src" . PATH_SEP . "Services" . PATH_SEP . "Api";
if (is_dir($pathApiDirectory)) {
if (class_exists($details->sClassName)) {
$oPlugin = new $details->sClassName($details->sNamespace, $details->sFilename);
$oPlugin->setup();
file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance());
}
}
}
}
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;
@@ -60,8 +107,8 @@ function run_flush_cache($args, $opts)
G::mk_dir($workspace->path . "/cache", 0777);
G::rm_dir($workspace->path . "/cachefiles");
G::mk_dir($workspace->path . "/cachefiles", 0777);
if (file_exists($workspace->path.'/routes.php')) {
unlink($workspace->path.'/routes.php');
if (file_exists($workspace->path . '/routes.php')) {
unlink($workspace->path . '/routes.php');
}
echo "DONE" . PHP_EOL;
}