HOR-2967
This commit is contained in:
@@ -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:
|
||||
* <?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
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user