From 120f7fce14ae6adeeeaff391d4782176d4bc4bfa Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 20 Apr 2015 15:37:36 -0500 Subject: [PATCH 1/7] main changes to enable register rest api endpoints from plugins 1. Enable rest api registering feature on main plugin file i.e, if I have a plugin named "erik", so we have a file named workflow/engine/plugins/erik.php and a folder workflow/engine/plugins/erik/ - inside of setup method of plugin main class set: $this->enableRestService(true); ---- file: erik.php ---- class erikPlugin extends PMPlugin { ... public function setup() { $this->registerMenu("processmaker", "menuerik.php"); ... $this->enableRestService(true); // <- this line enable Rest Service dispatching feature } ... 2. Create a folder: workflow/engine/plugins/erik/src/Services/Api/ $ mkdir -p workflow/engine/plugins/erik/src/Services/Api/ 3. Create a Restler class inside the folder created above i.e. creating a Hello class. ---- file: workflow/engine/plugins/erik/src/Services/Api/Hello.php ----- 'Hello world' ); return $hello; } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } } } ---------- end file --------- 4. Disable and enable the plugin named "erik" on ProcessMaker Admin Interface 5. Use the Rest Api defined inside the plugin you can access from a url something like that: format: http:///api/1.0//plugin-/hello/world i.e. http://processmaker/api/1.0/workflow/plugin-erik/hello/world Note.- to access this url that has the protected attribute into the class you need provide the access token into request header. --- framework/src/Maveriks/WebApplication.php | 81 +++++++++++-------- .../engine/classes/class.pluginRegistry.php | 9 ++- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/framework/src/Maveriks/WebApplication.php b/framework/src/Maveriks/WebApplication.php index 058645a21..97f33be63 100644 --- a/framework/src/Maveriks/WebApplication.php +++ b/framework/src/Maveriks/WebApplication.php @@ -210,7 +210,7 @@ class WebApplication */ public function dispatchApiRequest($uri, $version = "1.0", $multipart = false, $inputExecute = '') { - $this->initRest($uri, "1.0", $multipart); + $uri = $this->initRest($uri, "1.0", $multipart); // to handle a request with "OPTIONS" method if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { @@ -328,50 +328,60 @@ class WebApplication // Override $_SERVER['REQUEST_URI'] to Restler handles the modified url - if (! $isPluginRequest) { // if it is not a request for a plugin endpoint - // scan all api directory to find api classes - $classesList = Util\Common::rglob($apiDir . "/*"); + // scan all api directory to find api classes + $classesList = Util\Common::rglob($apiDir . "/*"); - foreach ($classesList as $classFile) { - if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') { - $relClassPath = str_replace('.php', '', str_replace($servicesDir, '', $classFile)); - $namespace = '\\ProcessMaker\\Services\\' . str_replace(DS, '\\', $relClassPath); - $namespace = strpos($namespace, "//") === false? $namespace: str_replace("//", '', $namespace); + foreach ($classesList as $classFile) { + if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') { + $relClassPath = str_replace('.php', '', str_replace($servicesDir, '', $classFile)); + $namespace = '\\ProcessMaker\\Services\\' . str_replace(DS, '\\', $relClassPath); + $namespace = strpos($namespace, "//") === false? $namespace: str_replace("//", '', $namespace); - //if (! class_exists($namespace)) { - require_once $classFile; - //} + //if (! class_exists($namespace)) { + require_once $classFile; + //} - $this->rest->addAPIClass($namespace); + $this->rest->addAPIClass($namespace); + } + } + // adding aliases for Restler + if (array_key_exists('alias', $config)) { + foreach ($config['alias'] as $alias => $aliasData) { + if (is_array($aliasData)) { + foreach ($aliasData as $label => $namespace) { + $namespace = '\\' . ltrim($namespace, '\\'); + $this->rest->addAPIClass($namespace, $alias); + } } } - // adding aliases for Restler - if (array_key_exists('alias', $config)) { - foreach ($config['alias'] as $alias => $aliasData) { - if (is_array($aliasData)) { - foreach ($aliasData as $label => $namespace) { - $namespace = '\\' . ltrim($namespace, '\\'); - $this->rest->addAPIClass($namespace, $alias); + } + + //if (! $isPluginRequest) { // if it is not a request for a plugin endpoint + // hook to get rest api classes from plugins + if (class_exists('PMPluginRegistry')) { + $pluginRegistry = \PMPluginRegistry::loadSingleton(PATH_DATA_SITE . 'plugin.singleton'); + $plugins = $pluginRegistry->getRegisteredRestServices(); + + if (! empty($plugins)) { + $pluginSourceDir = PATH_PLUGINS . $pluginName . DIRECTORY_SEPARATOR . 'src'; + + $loader = \Maveriks\Util\ClassLoader::getInstance(); + $loader->add($pluginSourceDir); + + if (is_array($plugins) && array_key_exists($pluginName, $plugins)) { + foreach ($plugins[$pluginName] as $class) { + if (class_exists($class['namespace'])) { + $this->rest->addAPIClass($class['namespace']); } } } } - } else { - // hook to get rest api classes from plugins -// if (class_exists('PMPluginRegistry')) { -// $pluginRegistry = & PMPluginRegistry::getSingleton(); -// $plugins = $pluginRegistry->getRegisteredRestServices(); -// -// if (is_array($plugins) && array_key_exists($pluginName, $plugins)) { -// foreach ($plugins[$pluginName] as $class) { -// $rest->addAPIClass($class['namespace']); -// } -// } -// } } Services\OAuth2\Server::setWorkspace(SYS_SYS); $this->rest->addAPIClass('\ProcessMaker\\Services\\OAuth2\\Server', 'oauth2'); + + return $uri; } public function parseApiRequestUri() @@ -580,5 +590,10 @@ class WebApplication throw $e; } } -} + public static function purgeRestApiCache($workspace) + { + @unlink(PATH_DATA . 'compiled' . DS . 'routes.php'); + @unlink(PATH_DATA . 'sites' . DS . $workspace . DS . 'api-config.php'); + } +} diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index 611ae1ed5..e6a24a476 100755 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -277,12 +277,15 @@ class PMPluginRegistry $pluginSrcDir = PATH_PLUGINS . $detail->sNamespace . PATH_SEP . 'src'; if (is_dir($pluginSrcDir)) { - Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir); + //Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir); + $loader = \Maveriks\Util\ClassLoader::getInstance(); + $loader->add($pluginSrcDir); } if (array_key_exists($detail->sNamespace, $this->_restServiceEnabled) && $this->_restServiceEnabled[$detail->sNamespace] == true ) { + $oPlugin->registerRestService(); } @@ -1400,7 +1403,6 @@ class PMPluginRegistry foreach ($classesList as $classFile) { if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') { - $ns = str_replace( DIRECTORY_SEPARATOR, '\\', @@ -1413,6 +1415,8 @@ class PMPluginRegistry "filepath" => $classFile, "namespace" => $ns ); + + \Maveriks\WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); } } } @@ -1601,4 +1605,3 @@ class PMPluginRegistry } } } - From 253432540588464bb873615257dacef828e49828 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 24 Apr 2015 22:25:36 -0500 Subject: [PATCH 2/7] last fix to avoid warnings on the core endpoints --- framework/src/Maveriks/WebApplication.php | 44 +++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/framework/src/Maveriks/WebApplication.php b/framework/src/Maveriks/WebApplication.php index 76ce55e3e..4ef98c212 100644 --- a/framework/src/Maveriks/WebApplication.php +++ b/framework/src/Maveriks/WebApplication.php @@ -315,19 +315,6 @@ class WebApplication $this->rest->setOverridingFormats('JsonFormat', 'UploadFormat'); - $isPluginRequest = strpos($uri, '/plugin-') !== false ? true : false; - - if ($isPluginRequest) { - $tmp = explode('/', $uri); - array_shift($tmp); - $tmp = array_shift($tmp); - $tmp = explode('-', $tmp); - $pluginName = $tmp[1]; - $uri = str_replace('/plugin-'.$pluginName, '', $uri); - } - - // Override $_SERVER['REQUEST_URI'] to Restler handles the modified url - // scan all api directory to find api classes $classesList = Util\Common::rglob($apiDir . "/*"); @@ -356,24 +343,36 @@ class WebApplication } } - //if (! $isPluginRequest) { // if it is not a request for a plugin endpoint + // + // Register API Plugins classes + $isPluginRequest = strpos($uri, '/plugin-') !== false ? true : false; + + if ($isPluginRequest) { + $tmp = explode('/', $uri); + array_shift($tmp); + $tmp = array_shift($tmp); + $tmp = explode('-', $tmp); + $pluginName = $tmp[1]; + $uri = str_replace('/plugin-'.$pluginName, '', $uri); + } + // hook to get rest api classes from plugins if (class_exists('PMPluginRegistry') && file_exists(PATH_DATA_SITE . 'plugin.singleton')) { $pluginRegistry = \PMPluginRegistry::loadSingleton(PATH_DATA_SITE . 'plugin.singleton'); $plugins = $pluginRegistry->getRegisteredRestServices(); if (! empty($plugins)) { - $pluginSourceDir = PATH_PLUGINS . $pluginName . DIRECTORY_SEPARATOR . 'src'; + foreach ($plugins as $pluginName => $plugin) { + $pluginSourceDir = PATH_PLUGINS . $pluginName . DIRECTORY_SEPARATOR . 'src'; - $loader = \Maveriks\Util\ClassLoader::getInstance(); - $loader->add($pluginSourceDir); - - if (is_array($plugins) && array_key_exists($pluginName, $plugins)) { - foreach ($plugins[$pluginName] as $class) { + $loader = \Maveriks\Util\ClassLoader::getInstance(); + $loader->add($pluginSourceDir); + + foreach ($plugin as $class) { if (class_exists($class['namespace'])) { $this->rest->addAPIClass($class['namespace']); - } - } + } + } } } } @@ -597,3 +596,4 @@ class WebApplication @unlink(PATH_DATA . 'sites' . DS . $workspace . DS . 'api-config.php'); } } + From 2a4b59f71fe82bb062e54bb4c3fb3f52b30d0a95 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 28 Apr 2015 08:12:04 -0500 Subject: [PATCH 3/7] Some fixes to avoid status error 500 when it should return 404 - Another thing to consider, the right enabling/disabling feature must be placed as following: ----- class erikPlugin extends PMPlugin { ... public function enable() { $this->enableRestService(true); } public function disable() { $this->enableRestService(false); } } --- workflow/engine/classes/class.pluginRegistry.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index e6a24a476..936d9eac4 100755 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -1415,12 +1415,12 @@ class PMPluginRegistry "filepath" => $classFile, "namespace" => $ns ); - - \Maveriks\WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); } } } + \Maveriks\WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); + return true; } @@ -1432,6 +1432,7 @@ class PMPluginRegistry public function unregisterRestService ($sNamespace) { unset($this->_restServices[$sNamespace]); + \Maveriks\WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); } public function getRegisteredRestServices() From 467a241887437d07bd7bc32ae69e25cb4549c0ca Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 29 Apr 2015 16:15:57 -0500 Subject: [PATCH 4/7] Fixing rest api dispatching for plugins with camelcase names - plugin camelcase names are supported now - fix for bug when a requests like GET /plugin-erik/hello/world GET /plugin-nonExistsPlugin/hello/world was resolving and dispatching the same resource --- framework/src/Maveriks/WebApplication.php | 4 ++-- workflow/engine/classes/class.pluginRegistry.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/Maveriks/WebApplication.php b/framework/src/Maveriks/WebApplication.php index 4ef98c212..8128618af 100644 --- a/framework/src/Maveriks/WebApplication.php +++ b/framework/src/Maveriks/WebApplication.php @@ -353,7 +353,7 @@ class WebApplication $tmp = array_shift($tmp); $tmp = explode('-', $tmp); $pluginName = $tmp[1]; - $uri = str_replace('/plugin-'.$pluginName, '', $uri); + $uri = str_replace('plugin-'.$pluginName, strtolower($pluginName), $uri); } // hook to get rest api classes from plugins @@ -370,7 +370,7 @@ class WebApplication foreach ($plugin as $class) { if (class_exists($class['namespace'])) { - $this->rest->addAPIClass($class['namespace']); + $this->rest->addAPIClass($class['namespace'], strtolower($pluginName)); } } } diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index f5b500953..e6f77843f 100755 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -1408,7 +1408,7 @@ class PMPluginRegistry // Ensure that is registering only existent classes. if (class_exists($ns)) { - $this->_restServices[strtolower($sNamespace)][] = array( + $this->_restServices[$sNamespace][] = array( "filepath" => $classFile, "namespace" => $ns ); From 62e65acc0a5509506465787487b01c5e7f4c52ce Mon Sep 17 00:00:00 2001 From: "Paula V. Quispe" Date: Thu, 30 Apr 2015 08:55:47 -0400 Subject: [PATCH 5/7] PM-2543: Error al adicionar triggers a los steps --- workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php b/workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php index cc63a642c..e939a6633 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Step/Trigger.php @@ -411,6 +411,8 @@ class Trigger } $range = range($iniPos, $finPos); + $stepChangeIds = array(); + $stepChangePos = array(); foreach ($aStepTriggers as $dataStep) { if (($dataStep['st_type'] == $typeCompare) && (in_array($dataStep['st_position'], $range)) && ($dataStep['tri_uid'] != $triUid)) { $stepChangeIds[] = $dataStep['tri_uid']; From f34b941e5fe143cf4a5c4571c95be1e6b26301bd Mon Sep 17 00:00:00 2001 From: dheeyi Date: Thu, 30 Apr 2015 12:24:26 -0400 Subject: [PATCH 6/7] Se arreglo la razon el por que se volvio a abrir este card --- workflow/engine/templates/admin/calendarEdit.js | 1 - 1 file changed, 1 deletion(-) diff --git a/workflow/engine/templates/admin/calendarEdit.js b/workflow/engine/templates/admin/calendarEdit.js index 3664dfcb1..2ff625e5a 100644 --- a/workflow/engine/templates/admin/calendarEdit.js +++ b/workflow/engine/templates/admin/calendarEdit.js @@ -751,7 +751,6 @@ Ext.onReady( function() { width : 200 , fieldLabel : _('ID_NAME') , name : 'name' , - allowBlank : false, msgTarget: 'side', enableKeyEvents: true, listeners: { From 9995cb8062b3f77dcba7726ff6737ca99913f371 Mon Sep 17 00:00:00 2001 From: "Paula V. Quispe" Date: Thu, 30 Apr 2015 13:55:56 -0400 Subject: [PATCH 7/7] PM-2347: I solved a notice --- workflow/engine/classes/model/AppDelegation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 90d2873e4..af7022d8c 100755 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -89,7 +89,7 @@ class AppDelegation extends BaseAppDelegation $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $delIndex = 1; - $delPreviusUsrUid = ''; + $delPreviusUsrUid = $sUsrUid; if ($rs->next()) { $row = $rs->getRow();