diff --git a/workflow/engine/bin/tasks/cliFlushCache.php b/workflow/engine/bin/tasks/cliFlushCache.php index 2b427e1d5..7e3388148 100644 --- a/workflow/engine/bin/tasks/cliFlushCache.php +++ b/workflow/engine/bin/tasks/cliFlushCache.php @@ -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; } diff --git a/workflow/engine/classes/class.plugin.php b/workflow/engine/classes/class.plugin.php index 675963b6e..5888222aa 100644 --- a/workflow/engine/classes/class.plugin.php +++ b/workflow/engine/classes/class.plugin.php @@ -514,6 +514,68 @@ class PMPlugin } } } + + /** + * Gets an array of plugins that are in the processmaker plugin directory. + * @param string $workspace + * @return array + */ + public static function getList($workspace) + { + $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 + ]; + } + } + } + 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);