From 9257e533c2ccc333ebd602cdb69d92cb180463eb Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 27 Apr 2017 12:18:35 -0400 Subject: [PATCH 1/4] HOR-1750 --- framework/src/Maveriks/WebApplication.php | 4 ++ .../Policies/ControlUnderUpdating.php | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php diff --git a/framework/src/Maveriks/WebApplication.php b/framework/src/Maveriks/WebApplication.php index 21c9473e1..4296a8fac 100644 --- a/framework/src/Maveriks/WebApplication.php +++ b/framework/src/Maveriks/WebApplication.php @@ -254,6 +254,8 @@ class WebApplication $authenticationClass = 'ProcessMaker\\Services\\OAuth2\\Server'; // $accessControlClass - contains the class name that validate the Access Control for Restler $accessControlClass = 'ProcessMaker\\Policies\\AccessControl'; + // $controlUnderUpdating - ControlUnderUpdating sends an error signal 503 to report that the application is in update + $controlUnderUpdating = 'ProcessMaker\\Policies\\ControlUnderUpdating'; // $pmOauthClientId - contains PM Local OAuth Id (Web Designer) $pmOauthClientId = 'x-pm-local-client'; @@ -301,6 +303,8 @@ class WebApplication $this->rest->addAuthenticationClass($authenticationClass, ''); // adding $accessControlClass to Restler $this->rest->addAuthenticationClass($accessControlClass); + // adding $controlUnderUpdating to Restler + $this->rest->addAuthenticationClass($controlUnderUpdating); // Setting database connection source list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, ''); diff --git a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php new file mode 100644 index 000000000..c5c37e595 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php @@ -0,0 +1,56 @@ + Date: Fri, 28 Apr 2017 08:11:19 -0400 Subject: [PATCH 2/4] HOR-1750 --- .../engine/src/ProcessMaker/Policies/ControlUnderUpdating.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php index c5c37e595..78e5dacc1 100644 --- a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php +++ b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php @@ -30,11 +30,11 @@ class ControlUnderUpdating implements iAuthenticate $sysTemp = $underUpdating['workspace'] == SYS_TEMP; } if ($underUpdating['workspace'] == "true" || $sysTemp) { - $mesage = 'The server is currently unable to handle the request ' + $message = 'The server is currently unable to handle the request ' . 'due to a temporary overloading or maintenance of the ' . 'server (An application update has probably been ' . 'performed on the server).'; - throw new RestException(503, $mesage); + throw new RestException(503, $message); } } return $response; From feed5454f194ae2615d319ae1afc5284716e1c1b Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 28 Apr 2017 09:28:38 -0400 Subject: [PATCH 3/4] HOR-1750 --- .../src/ProcessMaker/Policies/ControlUnderUpdating.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php index 78e5dacc1..5247f160f 100644 --- a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php +++ b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php @@ -26,14 +26,14 @@ class ControlUnderUpdating implements iAuthenticate $underUpdating = \Bootstrap::isPMUnderUpdating(); if ($underUpdating['action']) { $sysTemp = true; - if (defined("SYS_TEMP")) { + if (defined('SYS_TEMP')) { $sysTemp = $underUpdating['workspace'] == SYS_TEMP; } - if ($underUpdating['workspace'] == "true" || $sysTemp) { + if ($underUpdating['workspace'] == 'true' || $sysTemp) { $message = 'The server is currently unable to handle the request ' - . 'due to a temporary overloading or maintenance of the ' - . 'server (An application update has probably been ' - . 'performed on the server).'; + . 'due to temporary overloading or server maintenance (' + . 'an application update has probably been performed on ' + . 'the server)'; throw new RestException(503, $message); } } From 7a60e17367888664a98ef8896f23e270f0e9a59b Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Mon, 8 May 2017 15:22:46 -0400 Subject: [PATCH 4/4] HOR-1750 --- .../Policies/ControlUnderUpdating.php | 38 ++++++++++++------- .../ProcessMaker/Services/OAuth2/Server.php | 2 + 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php index 5247f160f..c40363912 100644 --- a/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php +++ b/workflow/engine/src/ProcessMaker/Policies/ControlUnderUpdating.php @@ -23,20 +23,7 @@ class ControlUnderUpdating implements iAuthenticate public function __isAllowed() { $response = true; - $underUpdating = \Bootstrap::isPMUnderUpdating(); - if ($underUpdating['action']) { - $sysTemp = true; - if (defined('SYS_TEMP')) { - $sysTemp = $underUpdating['workspace'] == SYS_TEMP; - } - if ($underUpdating['workspace'] == 'true' || $sysTemp) { - $message = 'The server is currently unable to handle the request ' - . 'due to temporary overloading or server maintenance (' - . 'an application update has probably been performed on ' - . 'the server)'; - throw new RestException(503, $message); - } - } + self::verifyUnderUpgrading(); return $response; } @@ -53,4 +40,27 @@ class ControlUnderUpdating implements iAuthenticate return ''; } + /** + * Verify under upgrading, if the state is under update an exception is + * thrown of type RestException. + * @throws RestException + */ + public static function verifyUnderUpgrading() + { + $underUpdating = \Bootstrap::isPMUnderUpdating(); + if ($underUpdating['action']) { + $sysTemp = true; + if (defined('SYS_TEMP')) { + $sysTemp = $underUpdating['workspace'] == SYS_TEMP; + } + if ($underUpdating['workspace'] == 'true' || $sysTemp) { + $message = 'The server is currently unable to handle the request ' + . 'due to temporary overloading or server maintenance (' + . 'an application update has probably been performed on ' + . 'the server)'; + throw new RestException(503, $message); + } + } + } + } diff --git a/workflow/engine/src/ProcessMaker/Services/OAuth2/Server.php b/workflow/engine/src/ProcessMaker/Services/OAuth2/Server.php index 4e1563fc9..1e7c77f8c 100644 --- a/workflow/engine/src/ProcessMaker/Services/OAuth2/Server.php +++ b/workflow/engine/src/ProcessMaker/Services/OAuth2/Server.php @@ -284,6 +284,8 @@ class Server implements iAuthenticate */ public function postToken($request = null, $returnResponse = false) { + \ProcessMaker\Policies\ControlUnderUpdating::verifyUnderUpgrading(); + // Handle a request for an OAuth2.0 Access Token and send the response to the client if ($request == null) { $request = \OAuth2\Request::createFromGlobals();