This commit is contained in:
Roly Rudy Gutierrez Pinto
2017-05-15 14:49:15 -04:00
parent f879964e92
commit c235f15a29
5 changed files with 114 additions and 179 deletions

View File

@@ -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:
* <?php
* G::LoadClass("plugin");
* class myPlugin extends PMPlugin {
*
* public function myPlugin($sNamespace, $sFilename = null) {
* $res = parent::PMPlugin($sNamespace, $sFilename);
* $this->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;
}
}