HOR-3275 improvement
This commit is contained in:
@@ -39,7 +39,7 @@ CLI::taskRun('run_flush_cache');
|
|||||||
function run_flush_cache($args, $opts)
|
function run_flush_cache($args, $opts)
|
||||||
{
|
{
|
||||||
if (count($args) === 1) {
|
if (count($args) === 1) {
|
||||||
flush_cache($args, $opts);
|
\ProcessMaker\Util\System::flushCache($args, $opts);
|
||||||
} else {
|
} else {
|
||||||
$workspaces = get_workspaces_from_args($args);
|
$workspaces = get_workspaces_from_args($args);
|
||||||
foreach ($workspaces as $workspace) {
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -585,6 +585,7 @@ class PMPlugin
|
|||||||
*/
|
*/
|
||||||
public static function getListAllPlugins($workspace)
|
public static function getListAllPlugins($workspace)
|
||||||
{
|
{
|
||||||
|
PMPluginRegistry::saveState();
|
||||||
$pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton";
|
$pathSingleton = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "plugin.singleton";
|
||||||
$oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton);
|
$oPluginRegistry = PMPluginRegistry::loadSingleton($pathSingleton);
|
||||||
$items = [];
|
$items = [];
|
||||||
@@ -600,6 +601,7 @@ class PMPlugin
|
|||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
PMPluginRegistry::restoreState();
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class PMPluginRegistry
|
|||||||
private $_restServiceEnabled = array();
|
private $_restServiceEnabled = array();
|
||||||
|
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
private static $stateSaved = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is the constructor of the PMPluginRegistry class
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,70 @@ class System
|
|||||||
throw $e;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user