From f879964e92ea58a0301a51f7cf292b36d9418611 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 19 Apr 2017 16:35:56 -0400 Subject: [PATCH 1/7] HOR-2967 --- workflow/engine/classes/class.plugin.php | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index 675963b6e..c34016d05 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -514,6 +514,95 @@ class PMPlugin } } } + + /** + * This function is an analog of the command: '$ ./processmaker flush-cache', + * only its use is recommended only when enabling the plugin (inside the + * enable function). + * IMPORTANT! Inappropriate use may render the 'API/REST' unusable. + * Example: + * sFriendlyName = "myPlugin Plugin"; + * $this->sDescription = "Autogenerated plugin for class myPlugin"; + * $this->sPluginFolder = "myPlugin"; + * $this->sSetupPage = "setup"; + * $this->iVersion = 1; + * $this->aWorkspaces = null; + * return $res; + * } + * public function setup() { + * + * } + * + * public function install() { + * + * } + * + * public function enable() { + * $this->enableRestService(true); + * $this->flushCache(); + * } + * + * public function disable() { + * + * } + * + * } + * + * $oPluginRegistry = &PMPluginRegistry::getSingleton(); + * $oPluginRegistry->registerPlugin("ejemplo3", __FILE__); + * + * @param string $workspaceName + * @throws Exception + */ + public function flushCache($workspaceName = "") + { + try { + $workspaces = System::listWorkspaces(); + if (!empty($workspaceName)) { + $itWasFound = false; + foreach ($workspaces as $workspace) { + if ($workspace->name === $workspaceName) { + $itWasFound = true; + $workspaces = [$workspace]; + break; + } + } + if ($itWasFound === false) { + $workspaces = []; + throw new Exception('Error: The workspace "' . $workspaceName . '" does not exist'); + } + } + foreach ($workspaces as $workspace) { + $path = $workspace->path . "/cache"; + if (file_exists($path)) { + G::rm_dir($path); + } + G::mk_dir($path, 0777); + $path = $workspace->path . "/cachefiles"; + if (file_exists($path)) { + G::rm_dir($path); + } + G::mk_dir($path, 0777); + $path = $workspace->path . "/routes.php"; + if (file_exists($path)) { + unlink($path); + } + } + } catch (Exception $exception) { + $sysSys = (defined("SYS_SYS")) ? SYS_SYS : "Undefined"; + $context = \Bootstrap::getDefaultContextLog(); + $context["exception"] = (array) $exception; + \Bootstrap::initVendors(); + \Bootstrap::LoadSystem('monologProvider'); + \Bootstrap::registerMonolog("flush-cache", 400, "flush-cache", $context, $sysSys, "processmaker.log"); + } + } } From c235f15a29c1d82ffde72ce6ef303fcafaf41d9a Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Mon, 15 May 2017 14:49:15 -0400 Subject: [PATCH 2/7] HOR-2967 --- workflow/engine/bin/cron_single.php | 33 +++++ workflow/engine/bin/tasks/cliFlushCache.php | 28 +++- workflow/engine/classes/class.plugin.php | 133 +++++++----------- workflow/engine/methods/setup/pluginsList.php | 98 +------------ workflow/public_html/ee | 1 + 5 files changed, 114 insertions(+), 179 deletions(-) create mode 100644 workflow/public_html/ee diff --git a/workflow/engine/bin/cron_single.php b/workflow/engine/bin/cron_single.php index 83c25f284..fe420ca23 100644 --- a/workflow/engine/bin/cron_single.php +++ b/workflow/engine/bin/cron_single.php @@ -324,6 +324,9 @@ try { case 'sendnotificationscron': sendNotifications(); break; + case 'updateSingleton': + updateSingleton($workspace); + break; } } catch (Exception $e) { $token = strtotime("now"); @@ -1132,3 +1135,33 @@ function sendNotifications() saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage()); } } + +/** + * Update singleton file in workspace. + * + * @param string $workspace + */ +function updateSingleton($workspace) +{ + eprint("* Update singleton ... "); + G::LoadClass('case'); + $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton"; + $oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton); + $items = \PMPlugin::getlist($workspace); + 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)) { + $oPluginRegistry->enablePlugin($details->sNamespace); + $oPluginRegistry->setupPlugins(); + file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance()); + G::auditLog("EnablePlugin", "Plugin Name: " . $details->sNamespace); + } + } + } + eprint("DONE"); +} diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 2b427e1d5..e9cbb27bf 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -38,17 +38,33 @@ CLI::taskRun('run_flush_cache'); function run_flush_cache($args, $opts) { - $rootDir = realpath(__DIR__."/../../../../"); + $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 + $dateSystem = date('Y-m-d H:i:s'); + $date = $dateSystem; + foreach ($workspaces as $workspace) { + $cmd = 'php -f ' + . '"' . PATH_CORE . 'bin' . PATH_SEP . 'cron_single.php' . '" ' + . '"' . base64_encode(PATH_HOME) . '" ' + . '"' . base64_encode(PATH_TRUNK) . '" ' + . '"' . base64_encode(PATH_OUTTRUNK) . '" ' + . '"updateSingleton" ' + . '"' . $workspace->name . '" ' + . '"' . $dateSystem . '" ' + . '"' . $date . '" '; + passthru($cmd); + } + + 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 +76,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; } diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index c34016d05..5888222aa 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -516,92 +516,65 @@ class PMPlugin } /** - * This function is an analog of the command: '$ ./processmaker flush-cache', - * only its use is recommended only when enabling the plugin (inside the - * enable function). - * IMPORTANT! Inappropriate use may render the 'API/REST' unusable. - * Example: - * sFriendlyName = "myPlugin Plugin"; - * $this->sDescription = "Autogenerated plugin for class myPlugin"; - * $this->sPluginFolder = "myPlugin"; - * $this->sSetupPage = "setup"; - * $this->iVersion = 1; - * $this->aWorkspaces = null; - * return $res; - * } - * public function setup() { - * - * } - * - * public function install() { - * - * } - * - * public function enable() { - * $this->enableRestService(true); - * $this->flushCache(); - * } - * - * public function disable() { - * - * } - * - * } - * - * $oPluginRegistry = &PMPluginRegistry::getSingleton(); - * $oPluginRegistry->registerPlugin("ejemplo3", __FILE__); - * - * @param string $workspaceName - * @throws Exception + * Gets an array of plugins that are in the processmaker plugin directory. + * @param string $workspace + * @return array */ - public function flushCache($workspaceName = "") + public static function getList($workspace) { - try { - $workspaces = System::listWorkspaces(); - if (!empty($workspaceName)) { - $itWasFound = false; - foreach ($workspaces as $workspace) { - if ($workspace->name === $workspaceName) { - $itWasFound = true; - $workspaces = [$workspace]; - break; + $items = Array(); + $aPluginsPP = array(); + if (is_file(PATH_PLUGINS . 'enterprise/data/data')) { + $aPlugins = unserialize(trim(file_get_contents(PATH_PLUGINS . 'enterprise/data/data'))); + foreach ($aPlugins as $aPlugin) { + $aPluginsPP[] = substr($aPlugin['sFilename'], 0, strpos($aPlugin['sFilename'], '-')) . '.php'; + } + } + $oPluginRegistry = PMPluginRegistry::getSingleton(); + if ($handle = opendir(PATH_PLUGINS)) { + while (false !== ($file = readdir($handle))) { + if (in_array($file, $aPluginsPP)) { + continue; + } + if (strpos($file, '.php', 1) && is_file(PATH_PLUGINS . $file)) { + include_once (PATH_PLUGINS . $file); + $pluginDetail = $oPluginRegistry->getPluginDetails($file); + if ($pluginDetail === null) { + continue; + } + $status_label = $pluginDetail->enabled ? G::LoadTranslation('ID_ENABLED') : G::LoadTranslation('ID_DISABLED'); + $status = $pluginDetail->enabled ? 1 : 0; + if (isset($pluginDetail->aWorkspaces)) { + if (!is_array($pluginDetail->aWorkspaces)) { + $pluginDetail->aWorkspaces = array(); + } + if (!in_array($workspace, $pluginDetail->aWorkspaces)) { + continue; + } + } + $setup = $pluginDetail->sSetupPage != '' && $pluginDetail->enabled ? '1' : '0'; + + if (isset($pluginDetail) && !$pluginDetail->bPrivate) { + $items[] = [ + 'id' => (count($items) + 1), + 'namespace' => $pluginDetail->sNamespace, + 'title' => $pluginDetail->sFriendlyName . "\n(" . $pluginDetail->sNamespace . '.php)', + 'className' => $pluginDetail->sNamespace, + 'description' => $pluginDetail->sDescription, + 'version' => $pluginDetail->iVersion, + 'setupPage' => $pluginDetail->sSetupPage, + 'status_label' => $status_label, + 'status' => $status, + 'setup' => $setup, + 'sFile' => $file, + 'sStatusFile' => $pluginDetail->enabled + ]; } } - if ($itWasFound === false) { - $workspaces = []; - throw new Exception('Error: The workspace "' . $workspaceName . '" does not exist'); - } } - foreach ($workspaces as $workspace) { - $path = $workspace->path . "/cache"; - if (file_exists($path)) { - G::rm_dir($path); - } - G::mk_dir($path, 0777); - $path = $workspace->path . "/cachefiles"; - if (file_exists($path)) { - G::rm_dir($path); - } - G::mk_dir($path, 0777); - $path = $workspace->path . "/routes.php"; - if (file_exists($path)) { - unlink($path); - } - } - } catch (Exception $exception) { - $sysSys = (defined("SYS_SYS")) ? SYS_SYS : "Undefined"; - $context = \Bootstrap::getDefaultContextLog(); - $context["exception"] = (array) $exception; - \Bootstrap::initVendors(); - \Bootstrap::LoadSystem('monologProvider'); - \Bootstrap::registerMonolog("flush-cache", 400, "flush-cache", $context, $sysSys, "processmaker.log"); + closedir($handle); } + return $items; } } diff --git a/workflow/engine/methods/setup/pluginsList.php b/workflow/engine/methods/setup/pluginsList.php index 663256c06..edfa49a2b 100644 --- a/workflow/engine/methods/setup/pluginsList.php +++ b/workflow/engine/methods/setup/pluginsList.php @@ -1,4 +1,5 @@ requirePermissions('PM_SETUP_ADVANCE'); -$RBAC->requirePermissions( 'PM_SETUP_ADVANCE' ); - -// lets display the items -//$items = array ( 'id' => 'char', 'title' => 'char', 'type' => 'char', 'creator' => 'char' , 'modifiedBy' => 'char', 'filename' => 'char', 'size' => 'char', 'mime' => 'char'); - - -$items = Array (); -//***************** Plugins ************************** -G::LoadClass( 'plugin' ); -//here we are loading all plugins registered -//krumo ($items); die; -$aPluginsPP = array (); -if (is_file( PATH_PLUGINS . 'enterprise/data/data' )) { - $aPlugins = unserialize( trim( file_get_contents( PATH_PLUGINS . 'enterprise/data/data' ) ) ); - foreach ($aPlugins as $aPlugin) { - $aPluginsPP[] = substr( $aPlugin['sFilename'], 0, strpos( $aPlugin['sFilename'], '-' ) ) . '.php'; - } -} -$oPluginRegistry = & PMPluginRegistry::getSingleton(); -if ($handle = opendir( PATH_PLUGINS )) { - while (false !== ($file = readdir( $handle ))) { - - if (in_array( $file, $aPluginsPP )) { - continue; - } - if (strpos( $file, '.php', 1 ) && is_file( PATH_PLUGINS . $file )) { - include_once (PATH_PLUGINS . $file); - $pluginDetail = $oPluginRegistry->getPluginDetails( $file ); - //print_R ($pluginDetail ); - //die; - //$status = $pluginDetail->enabled ? 'Enabled' : 'Disabled'; - if ($pluginDetail == null) - continue; //When for some reason we gen NULL plugin - $status_label = $pluginDetail->enabled ? G::LoadTranslation( 'ID_ENABLED' ) : G::LoadTranslation( 'ID_DISABLED' ); - $status = $pluginDetail->enabled ? 1 : 0; - if (isset( $pluginDetail->aWorkspaces )) { - if (!is_array($pluginDetail->aWorkspaces)) { - $pluginDetail->aWorkspaces = array(); - } - if (! in_array( SYS_SYS, $pluginDetail->aWorkspaces )) - continue; - } - $linkEditValue = $pluginDetail->sSetupPage != '' && $pluginDetail->enabled ? G::LoadTranslation( 'ID_SETUP' ) : ' '; - //g::pr($pluginDetail->sSetupPage); - $setup = $pluginDetail->sSetupPage != '' && $pluginDetail->enabled ? '1' : '0'; - - $link = 'pluginsChange?id=' . $file . '&status=' . $pluginDetail->enabled; - $linkEdit = 'pluginsSetup?id=' . $file; - $pluginName = $pluginDetail->sFriendlyName; - $pluginId = $pluginDetail->sNamespace; - $removePluginMsg = str_replace( "\r\n", "
", G::LoadTranslation( 'ID_MSG_REMOVE_PLUGIN' ) ); - $linkRemove = 'javascript:showMessage(\'' . $removePluginMsg . '
' . $pluginName . ' \',\'' . $pluginId . '\')'; - // $linkRemove = 'pluginsRemove?id='.$pluginId.'.php&status=1'; - if (isset( $pluginDetail )) { - if (! $pluginDetail->bPrivate) { - $items[] = array ('id' => (count( $items ) + 1),'namespace' => $pluginDetail->sNamespace,'title' => $pluginDetail->sFriendlyName . "\n(" . $pluginDetail->sNamespace . '.php)','className' => $pluginDetail->sNamespace,'description' => $pluginDetail->sDescription,'version' => $pluginDetail->iVersion,'setupPage' => $pluginDetail->sSetupPage,'status_label' => $status_label,'status' => $status,'setup' => $setup, - - 'sFile' => $file,'sStatusFile' => $pluginDetail->enabled - ); - } - } - - } - } - closedir( $handle ); -} - -$folders['items'] = $items; -//g::pr($items); -echo G::json_encode( $items ); -die(); -$_DBArray['plugins'] = $items; -$_SESSION['_DBArray'] = $_DBArray; - -G::LoadClass( 'ArrayPeer' ); -$c = new Criteria( 'dbarray' ); -$c->setDBArrayTable( 'plugins' ); -//$c->addAscendingOrderByColumn ('id'); - - -$G_MAIN_MENU = 'processmaker'; -$G_ID_MENU_SELECTED = 'SETUP'; -$G_SUB_MENU = 'setup'; -$G_ID_SUB_MENU_SELECTED = 'PLUGINS'; - -$G_PUBLISH = new Publisher(); - -$oHeadPublisher = & headPublisher::getSingleton(); -$oHeadPublisher->addScriptFile( '/jscore/setup/pluginList.js' ); - -$G_PUBLISH->AddContent( 'propeltable', 'paged-table', 'setup/pluginList', $c ); -G::RenderPage( 'publishBlank', 'blank' ); - +G::LoadClass('plugin'); +$items = \PMPlugin::getlist(SYS_SYS); +echo G::json_encode($items); diff --git a/workflow/public_html/ee b/workflow/public_html/ee new file mode 100644 index 000000000..aac5b4494 --- /dev/null +++ b/workflow/public_html/ee @@ -0,0 +1 @@ +a:11:{s:14:"actionsByEmail";a:1:{s:9:"sFilename";s:33:"actionsByEmail-PLUGIN_VERSION.tar";}s:16:"EnterpriseSearch";a:1:{s:9:"sFilename";s:35:"EnterpriseSearch-PLUGIN_VERSION.tar";}s:9:"pmReports";a:1:{s:9:"sFilename";s:28:"pmReports-PLUGIN_VERSION.tar";}s:10:"windowsSSO";a:1:{s:9:"sFilename";s:23:"windowsSSO-HOR-1976.tar";}s:9:"pmPowerUp";a:1:{s:9:"sFilename";s:28:"pmPowerUp-PLUGIN_VERSION.tar";}s:12:"pmConnectors";a:1:{s:9:"sFilename";s:31:"pmConnectors-PLUGIN_VERSION.tar";}s:16:"pmConsolidatedCL";a:1:{s:9:"sFilename";s:35:"pmConsolidatedCL-PLUGIN_VERSION.tar";}s:18:"dataReportingTools";a:1:{s:9:"sFilename";s:30:"dataReportingTools-1.1.0.6.tar";}s:21:"pmWorkspaceManagement";a:1:{s:9:"sFilename";s:40:"pmWorkspaceManagement-PLUGIN_VERSION.tar";}s:5:"pmSLA";a:1:{s:9:"sFilename";s:24:"pmSLA-PLUGIN_VERSION.tar";}s:20:"externalRegistration";a:1:{s:9:"sFilename";s:39:"externalRegistration-PLUGIN_VERSION.tar";}} \ No newline at end of file From 812eb02328ae06533bf2041c368963c8b85d47ea Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Mon, 15 May 2017 15:08:48 -0400 Subject: [PATCH 3/7] HOR-2967 --- workflow/public_html/ee | 1 - 1 file changed, 1 deletion(-) delete mode 100644 workflow/public_html/ee diff --git a/workflow/public_html/ee b/workflow/public_html/ee deleted file mode 100644 index aac5b4494..000000000 --- a/workflow/public_html/ee +++ /dev/null @@ -1 +0,0 @@ -a:11:{s:14:"actionsByEmail";a:1:{s:9:"sFilename";s:33:"actionsByEmail-PLUGIN_VERSION.tar";}s:16:"EnterpriseSearch";a:1:{s:9:"sFilename";s:35:"EnterpriseSearch-PLUGIN_VERSION.tar";}s:9:"pmReports";a:1:{s:9:"sFilename";s:28:"pmReports-PLUGIN_VERSION.tar";}s:10:"windowsSSO";a:1:{s:9:"sFilename";s:23:"windowsSSO-HOR-1976.tar";}s:9:"pmPowerUp";a:1:{s:9:"sFilename";s:28:"pmPowerUp-PLUGIN_VERSION.tar";}s:12:"pmConnectors";a:1:{s:9:"sFilename";s:31:"pmConnectors-PLUGIN_VERSION.tar";}s:16:"pmConsolidatedCL";a:1:{s:9:"sFilename";s:35:"pmConsolidatedCL-PLUGIN_VERSION.tar";}s:18:"dataReportingTools";a:1:{s:9:"sFilename";s:30:"dataReportingTools-1.1.0.6.tar";}s:21:"pmWorkspaceManagement";a:1:{s:9:"sFilename";s:40:"pmWorkspaceManagement-PLUGIN_VERSION.tar";}s:5:"pmSLA";a:1:{s:9:"sFilename";s:24:"pmSLA-PLUGIN_VERSION.tar";}s:20:"externalRegistration";a:1:{s:9:"sFilename";s:39:"externalRegistration-PLUGIN_VERSION.tar";}} \ No newline at end of file From 083960e78c62c3917791009628295b30a6e18ada Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Tue, 16 May 2017 15:27:09 -0400 Subject: [PATCH 4/7] HOR-2967 --- workflow/engine/bin/cron_single.php | 33 ------------ workflow/engine/bin/tasks/cliFlushCache.php | 58 ++++++++++++++++----- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/workflow/engine/bin/cron_single.php b/workflow/engine/bin/cron_single.php index fe420ca23..83c25f284 100644 --- a/workflow/engine/bin/cron_single.php +++ b/workflow/engine/bin/cron_single.php @@ -324,9 +324,6 @@ try { case 'sendnotificationscron': sendNotifications(); break; - case 'updateSingleton': - updateSingleton($workspace); - break; } } catch (Exception $e) { $token = strtotime("now"); @@ -1135,33 +1132,3 @@ function sendNotifications() saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage()); } } - -/** - * Update singleton file in workspace. - * - * @param string $workspace - */ -function updateSingleton($workspace) -{ - eprint("* Update singleton ... "); - G::LoadClass('case'); - $pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton"; - $oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton); - $items = \PMPlugin::getlist($workspace); - 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)) { - $oPluginRegistry->enablePlugin($details->sNamespace); - $oPluginRegistry->setupPlugins(); - file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance()); - G::auditLog("EnablePlugin", "Plugin Name: " . $details->sNamespace); - } - } - } - eprint("DONE"); -} diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index e9cbb27bf..9689e6a25 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -37,6 +37,26 @@ CLI::taskArg('workspace', true, true); CLI::taskRun('run_flush_cache'); function run_flush_cache($args, $opts) +{ + 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(); @@ -49,21 +69,35 @@ function run_flush_cache($args, $opts) } //Update singleton file by workspace - $dateSystem = date('Y-m-d H:i:s'); - $date = $dateSystem; foreach ($workspaces as $workspace) { - $cmd = 'php -f ' - . '"' . PATH_CORE . 'bin' . PATH_SEP . 'cron_single.php' . '" ' - . '"' . base64_encode(PATH_HOME) . '" ' - . '"' . base64_encode(PATH_TRUNK) . '" ' - . '"' . base64_encode(PATH_OUTTRUNK) . '" ' - . '"updateSingleton" ' - . '"' . $workspace->name . '" ' - . '"' . $dateSystem . '" ' - . '"' . $date . '" '; - passthru($cmd); + eprint("Update singleton in workspace " . $workspace->name . " ... "); + if (!defined("SYS_SYS")) { + define("SYS_SYS", $workspace->name); + } + if (!defined("PATH_DATA_SITE")) { + define('PATH_DATA_SITE', PATH_DATA . 'sites/' . $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)) { + $oPluginRegistry->enablePlugin($details->sNamespace); + $oPluginRegistry->setupPlugins(); + 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); From 8520685298e12d287f58f0b7e42ebac0c5b8a9d5 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 17 May 2017 09:16:08 -0400 Subject: [PATCH 5/7] HOR-2967 observations of 'pull Request' --- workflow/engine/bin/tasks/cliFlushCache.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 9689e6a25..7ab47f12b 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -71,12 +71,7 @@ function flush_cache($args, $opts) //Update singleton file by workspace foreach ($workspaces as $workspace) { eprint("Update singleton in workspace " . $workspace->name . " ... "); - if (!defined("SYS_SYS")) { - define("SYS_SYS", $workspace->name); - } - if (!defined("PATH_DATA_SITE")) { - define('PATH_DATA_SITE', PATH_DATA . 'sites/' . $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); From be1a6b31c36c0428837d1a14d7f265453f8fb890 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 17 May 2017 09:38:48 -0400 Subject: [PATCH 6/7] HOR-2967 observations of 'pull Request' --- workflow/engine/bin/tasks/cliFlushCache.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 7ab47f12b..ffcfb441c 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -83,8 +83,10 @@ function flush_cache($args, $opts) //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)) { - $oPluginRegistry->enablePlugin($details->sNamespace); - $oPluginRegistry->setupPlugins(); + if (class_exists($details->sClassName)) { + $oPlugin = new $details->sClassName($details->sNamespace, $details->sFilename); + $oPlugin->setup(); + } file_put_contents($pathSingleton, $oPluginRegistry->serializeInstance()); } } From 0de81bfb46243a9b1828276daf858c6494c1e06c Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 17 May 2017 09:40:12 -0400 Subject: [PATCH 7/7] HOR-2967 improvement --- workflow/engine/bin/tasks/cliFlushCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index ffcfb441c..7e3388148 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -86,8 +86,8 @@ function flush_cache($args, $opts) 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()); } } }