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] 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"); + } + } }