From 23a928c7e00208a3e935dd4faf819f8235055ffe Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 19 May 2017 16:20:44 -0400 Subject: [PATCH 1/5] HOR-3275 --- workflow/engine/bin/tasks/cliFlushCache.php | 13 +++++++---- workflow/engine/classes/class.plugin.php | 23 ++++++++++++++++++- workflow/engine/methods/setup/pluginsList.php | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 7e3388148..89ade189e 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -74,15 +74,18 @@ function flush_cache($args, $opts) 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); + $items = \PMPlugin::getListAllPlugins($workspace->name); foreach ($items as $item) { - if ($item["sStatusFile"] === true) { - $path = PATH_PLUGINS . $item["sFile"]; - require_once($path); - $details = $oPluginRegistry->getPluginDetails($item["sFile"]); + if ($item->enabled === true) { + require_once($item->sFilename); + $details = $oPluginRegistry->getPluginDetails(basename($item->sFilename)); //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)) { + $pluginSrcDir = PATH_PLUGINS . $details->sNamespace . PATH_SEP . 'src'; + $loader = \Maveriks\Util\ClassLoader::getInstance(); + $loader->add($pluginSrcDir); + $oPluginRegistry->registerRestService($details->sNamespace); if (class_exists($details->sClassName)) { $oPlugin = new $details->sClassName($details->sNamespace, $details->sFilename); $oPlugin->setup(); diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index 5888222aa..c8515b015 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -520,7 +520,7 @@ class PMPlugin * @param string $workspace * @return array */ - public static function getList($workspace) + public static function getListPluginsManager($workspace) { $items = Array(); $aPluginsPP = array(); @@ -576,6 +576,27 @@ class PMPlugin } return $items; } + + public static function getListAllPlugins($workspace) + { + $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton"; + $oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton); + //$oPluginRegistry = PMPluginRegistry::getSingleton(); + $items = []; + if ($handle = opendir(PATH_PLUGINS)) { + while (false !== ($file = readdir($handle))) { + if (strpos($file, '.php', 1) && is_file(PATH_PLUGINS . $file)) { + include_once (PATH_PLUGINS . $file); + $detail = $oPluginRegistry->getPluginDetails($file); + if ($detail !== null) { + $items[] = $detail; + } + } + } + closedir($handle); + } + return $items; + } } diff --git a/workflow/engine/methods/setup/pluginsList.php b/workflow/engine/methods/setup/pluginsList.php index edfa49a2b..87e347025 100644 --- a/workflow/engine/methods/setup/pluginsList.php +++ b/workflow/engine/methods/setup/pluginsList.php @@ -25,5 +25,5 @@ $RBAC->requirePermissions('PM_SETUP_ADVANCE'); G::LoadClass('plugin'); -$items = \PMPlugin::getlist(SYS_SYS); +$items = \PMPlugin::getListPluginsManager(SYS_SYS); echo G::json_encode($items); From cf0481a94369ee6ae7b6b93105ecb7fefa3970b1 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 19 May 2017 16:29:32 -0400 Subject: [PATCH 2/5] HOR-3275 improvement --- workflow/engine/classes/class.plugin.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index c8515b015..5f6564e13 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -577,11 +577,16 @@ class PMPlugin return $items; } + /** + * Gets a general list of all plugins within processmaker per workspace. + * + * @param string $workspace + * @return array + */ public static function getListAllPlugins($workspace) { $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton"; $oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton); - //$oPluginRegistry = PMPluginRegistry::getSingleton(); $items = []; if ($handle = opendir(PATH_PLUGINS)) { while (false !== ($file = readdir($handle))) { From 39a18a2d96acd1adcd1095f99edc18bd50a8ed3e Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 24 May 2017 11:26:13 -0400 Subject: [PATCH 3/5] HOR-3275 improvement --- workflow/engine/bin/tasks/cliFlushCache.php | 71 +------------------ workflow/engine/classes/class.plugin.php | 2 + .../engine/classes/class.pluginRegistry.php | 25 +++++++ .../engine/src/ProcessMaker/Util/System.php | 67 ++++++++++++++++- 4 files changed, 94 insertions(+), 71 deletions(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 89ade189e..53058289e 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -39,7 +39,7 @@ CLI::taskRun('run_flush_cache'); function run_flush_cache($args, $opts) { if (count($args) === 1) { - flush_cache($args, $opts); + \ProcessMaker\Util\System::flushCache($args, $opts); } else { $workspaces = get_workspaces_from_args($args); foreach ($workspaces as $workspace) { @@ -47,72 +47,3 @@ function run_flush_cache($args, $opts) } } } - -/** - * 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); - } - - //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::getListAllPlugins($workspace->name); - foreach ($items as $item) { - if ($item->enabled === true) { - require_once($item->sFilename); - $details = $oPluginRegistry->getPluginDetails(basename($item->sFilename)); - //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)) { - $pluginSrcDir = PATH_PLUGINS . $details->sNamespace . PATH_SEP . 'src'; - $loader = \Maveriks\Util\ClassLoader::getInstance(); - $loader->add($pluginSrcDir); - $oPluginRegistry->registerRestService($details->sNamespace); - 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; - - foreach ($workspaces as $workspace) { - echo "Flush workspace " . pakeColor::colorize($workspace->name, "INFO") . " cache ... "; - - G::rm_dir($workspace->path . "/cache"); - 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'); - } - echo "DONE" . PHP_EOL; - } -} diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index 5f6564e13..f044db803 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -585,6 +585,7 @@ class PMPlugin */ public static function getListAllPlugins($workspace) { + PMPluginRegistry::saveState(); $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton"; $oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton); $items = []; @@ -600,6 +601,7 @@ class PMPlugin } closedir($handle); } + PMPluginRegistry::restoreState(); return $items; } diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index 69ac27afa..cd4045de1 100644 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -122,6 +122,7 @@ class PMPluginRegistry private $_restServiceEnabled = array(); private static $instance = null; + private static $stateSaved = null; /** * This function is the constructor of the PMPluginRegistry class @@ -1946,4 +1947,28 @@ class PMPluginRegistry } } + /** + * Saves the state of instance, in the private property 'stateSaved'. + * Use the 'restoreState()' method to put the instance in the saved state. + */ + public static function saveState() + { + $pluginRegistry = PMPluginRegistry::getSingleton(); + self::$stateSaved = $pluginRegistry->serializeInstance(); + } + + /** + * Restores the state of the instance that is in the private variable 'stateSaved'. + * You must save the state of the instacia with the method 'saveState()' + * before being called. + */ + public static function restoreState() + { + if (self::$stateSaved !== null) { + $pluginRegistry = PMPluginRegistry::getSingleton(); + self::$instance = $pluginRegistry->unSerializeInstance(self::$stateSaved); + self::$stateSaved = null; + } + } + } diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index 25ba3c2aa..e5abb6f1e 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -19,5 +19,70 @@ class System throw $e; } } -} + /** + * 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 array $args + * @param array $opts + */ + public static function flushCache($args, $opts) + { + $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 . " ... "); + \Bootstrap::setConstantsRelatedWs($workspace->name); + $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace->name . PATH_SEP . "plugin.singleton"; + $oPluginRegistry = \PMPluginRegistry::loadSingleton($pathSingleton); + $items = \PMPlugin::getListAllPlugins($workspace->name); + foreach ($items as $item) { + if ($item->enabled === true) { + require_once($item->sFilename); + $details = $oPluginRegistry->getPluginDetails(basename($item->sFilename)); + //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)) { + $pluginSrcDir = PATH_PLUGINS . $details->sNamespace . PATH_SEP . 'src'; + $loader = \Maveriks\Util\ClassLoader::getInstance(); + $loader->add($pluginSrcDir); + $oPluginRegistry->registerRestService($details->sNamespace); + 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; + + foreach ($workspaces as $workspace) { + echo "Flush workspace " . \pakeColor::colorize($workspace->name, "INFO") . " cache ... "; + + \G::rm_dir($workspace->path . "/cache"); + \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'); + } + echo "DONE" . PHP_EOL; + } + } + +} From 68b32a35f05140e217dbf825b3b302f99029bec6 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 24 May 2017 15:29:26 -0400 Subject: [PATCH 4/5] HOR-3260 improvement --- workflow/engine/bin/tasks/cliFlushCache.php | 35 +++++++++++++++++- .../engine/src/ProcessMaker/Util/System.php | 37 +++++-------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 53058289e..ff83ae745 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -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; + } +} diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index e5abb6f1e..801835b1d 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -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()); } } From bdf9a25712ddf763c36457ffe3b1666ab2786f73 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 25 May 2017 09:09:09 -0400 Subject: [PATCH 5/5] HOR-3275 improvement validation --- workflow/engine/src/ProcessMaker/Util/System.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/engine/src/ProcessMaker/Util/System.php b/workflow/engine/src/ProcessMaker/Util/System.php index 801835b1d..0424e6303 100644 --- a/workflow/engine/src/ProcessMaker/Util/System.php +++ b/workflow/engine/src/ProcessMaker/Util/System.php @@ -47,8 +47,8 @@ class System if (class_exists($details->sClassName)) { $oPlugin = new $details->sClassName($details->sNamespace, $details->sFilename); $oPlugin->setup(); - file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance()); } + file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance()); } } }