From 4080654806765f6919c3f9b6a31477b9200f4521 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Fri, 18 Jun 2021 11:09:19 +0200 Subject: [PATCH] chg: [inboxProcessor] Renamed `RequestProcessors` into `InboxProcessors` --- .../BroodRequestProcessor.php | 6 +-- .../GenericRequestProcessor.php | 8 +-- .../LocalToolRequestProcessor.php | 10 ++-- .../ProposalRequestProcessor.php | 6 +-- .../SynchronisationRequestProcessor.php | 6 +-- .../TemplateRequestProcessor.php.template | 6 +-- .../UserRequestProcessor.php | 6 +-- src/Controller/BroodsController.php | 4 +- src/Controller/InboxController.php | 28 +++++----- src/Controller/UsersController.php | 4 +- ...ssorTable.php => InboxProcessorsTable.php} | 54 +++++++++---------- src/View/MonadView.php | 2 +- 12 files changed, 70 insertions(+), 70 deletions(-) rename src/Model/Table/{RequestProcessorTable.php => InboxProcessorsTable.php} (64%) diff --git a/libraries/default/RequestProcessors/BroodRequestProcessor.php b/libraries/default/RequestProcessors/BroodRequestProcessor.php index 0ea01bb..f055c1e 100644 --- a/libraries/default/RequestProcessors/BroodRequestProcessor.php +++ b/libraries/default/RequestProcessors/BroodRequestProcessor.php @@ -1,9 +1,9 @@ Inbox = TableRegistry::getTableLocator()->get('Inbox'); @@ -150,7 +150,7 @@ class GenericRequestProcessor if ($controller->ParamHandler->isRest()) { $response = $controller->RestResponse->viewData($processResult, 'json'); } else if ($controller->ParamHandler->isAjax()) { - $response = $controller->RestResponse->ajaxSuccessResponse('RequestProcessor', "{$scope}.{$action}", $processResult['data'], $message); + $response = $controller->RestResponse->ajaxSuccessResponse('InboxProcessor', "{$scope}.{$action}", $processResult['data'], $message); } else { $controller->Flash->success($message); if (!is_null($redirect)) { @@ -164,7 +164,7 @@ class GenericRequestProcessor if ($controller->ParamHandler->isRest()) { $response = $controller->RestResponse->viewData($processResult, 'json'); } else if ($controller->ParamHandler->isAjax()) { - $response = $controller->RestResponse->ajaxFailResponse('RequestProcessor', "{$scope}.{$action}", $processResult['data'], $message, $processResult['errors']); + $response = $controller->RestResponse->ajaxFailResponse('InboxProcessor', "{$scope}.{$action}", $processResult['data'], $message, $processResult['errors']); } else { $controller->Flash->error($message); if (!is_null($redirect)) { diff --git a/libraries/default/RequestProcessors/LocalToolRequestProcessor.php b/libraries/default/RequestProcessors/LocalToolRequestProcessor.php index 315c574..5bddbb0 100644 --- a/libraries/default/RequestProcessors/LocalToolRequestProcessor.php +++ b/libraries/default/RequestProcessors/LocalToolRequestProcessor.php @@ -3,9 +3,9 @@ use Cake\ORM\TableRegistry; use Cake\Filesystem\File; use Cake\Http\Exception\NotFoundException; -require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php'); +require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php'); -class LocalToolRequestProcessor extends GenericRequestProcessor +class LocalToolInboxProcessor extends GenericInboxProcessor { protected $scope = 'LocalTool'; protected $action = 'not-specified'; //overriden when extending @@ -171,7 +171,7 @@ class LocalToolRequestProcessor extends GenericRequestProcessor } } -class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI { +class IncomingConnectionRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI { public $action = 'IncomingConnectionRequest'; protected $description; @@ -283,7 +283,7 @@ class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor imple } } -class AcceptedRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI { +class AcceptedRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI { public $action = 'AcceptedRequest'; protected $description; @@ -356,7 +356,7 @@ class AcceptedRequestProcessor extends LocalToolRequestProcessor implements Gene } } -class DeclinedRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI { +class DeclinedRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI { public $action = 'DeclinedRequest'; protected $description; diff --git a/libraries/default/RequestProcessors/ProposalRequestProcessor.php b/libraries/default/RequestProcessors/ProposalRequestProcessor.php index 7eab1c8..baec684 100644 --- a/libraries/default/RequestProcessors/ProposalRequestProcessor.php +++ b/libraries/default/RequestProcessors/ProposalRequestProcessor.php @@ -1,9 +1,9 @@ requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); - $processor = $this->requestProcessor->getProcessor('Brood', 'ToolInterconnection'); + $this->InboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); + $processor = $this->InboxProcessors->getProcessor('Brood', 'ToolInterconnection'); $data = [ 'origin' => '127.0.0.1', 'comment' => 'Test comment', diff --git a/src/Controller/InboxController.php b/src/Controller/InboxController.php index f69995c..a393ad3 100644 --- a/src/Controller/InboxController.php +++ b/src/Controller/InboxController.php @@ -61,8 +61,8 @@ class InboxController extends AppController { if ($this->request->is('post')) { $request = $this->Inbox->get($id, ['contain' => ['Users' => ['Individuals' => ['Alignments' => 'Organisations']]]]); - $this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); - $processor = $this->requestProcessor->getProcessor($request->scope, $request->action); + $this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); + $processor = $this->inboxProcessors->getProcessor($request->scope, $request->action); $discardResult = $processor->discard($id, $request); return $processor->genHTTPReply($this, $discardResult); } @@ -81,11 +81,11 @@ class InboxController extends AppController $request = $this->Inbox->get($id, ['contain' => ['Users' => ['Individuals' => ['Alignments' => 'Organisations']]]]); $scope = $request->scope; $action = $request->action; - $this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); + $this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); if ($scope == 'LocalTool') { - $processor = $this->requestProcessor->getLocalToolProcessor($action, $request->local_tool_name); + $processor = $this->inboxProcessors->getLocalToolProcessor($action, $request->local_tool_name); } else { - $processor = $this->requestProcessor->getProcessor($scope, $action); + $processor = $this->inboxProcessors->getProcessor($scope, $action); } if ($this->request->is('post')) { $processResult = $processor->process($id, $this->request->getData(), $request); @@ -98,14 +98,14 @@ class InboxController extends AppController public function listProcessors() { - $this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); - $requestProcessors = $this->requestProcessor->listProcessors(); + $this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); + $processors = $this->inboxProcessors->listProcessors(); if ($this->ParamHandler->isRest()) { - return $this->RestResponse->viewData($requestProcessors, 'json'); + return $this->RestResponse->viewData($processors, 'json'); } $data = []; - foreach ($requestProcessors as $scope => $processors) { - foreach ($processors as $processor) { + foreach ($processors as $scope => $scopedProcessors) { + foreach ($scopedProcessors as $processor) { $data[] = [ 'enabled' => $processor->enabled, 'scope' => $scope, @@ -129,20 +129,20 @@ class InboxController extends AppController 'user_id' => $this->ACL->getUser()['id'], ]; $entryData['data'] = $this->request->getData() ?? []; - $this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); + $this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); if ($scope == 'LocalTool') { $this->validateLocalToolRequestEntry($entryData); $entryData['origin'] = $entryData['data']['cerebrateURL']; - $processor = $this->requestProcessor->getLocalToolProcessor($action, $entryData['data']['connectorName']); + $processor = $this->inboxProcessors->getLocalToolProcessor($action, $entryData['data']['connectorName']); $errors = $this->Inbox->checkUserBelongsToBroodOwnerOrg($this->ACL->getUser(), $entryData); if (!empty($errors)) { $message = __('Could not create inbox message'); return $this->RestResponse->ajaxFailResponse(Inflector::singularize($this->Inbox->getAlias()), 'createInboxEntry', [], $message, $errors); } } else { - $processor = $this->requestProcessor->getProcessor($scope, $action); + $processor = $this->inboxProcessors->getProcessor($scope, $action); } - $creationResult = $this->requestProcessor->createInboxEntry($processor, $entryData); + $creationResult = $this->inboxProcessors->createInboxEntry($processor, $entryData); return $processor->genHTTPReply($this, $creationResult); } diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index 8a40151..9126e87 100644 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -138,8 +138,8 @@ class UsersController extends AppController public function register() { - $this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor'); - $processor = $this->requestProcessor->getProcessor('User', 'Registration'); + $this->InboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors'); + $processor = $this->InboxProcessors->getProcessor('User', 'Registration'); $data = [ 'origin' => '127.0.0.1', 'comment' => 'Hi there!, please create an account', diff --git a/src/Model/Table/RequestProcessorTable.php b/src/Model/Table/InboxProcessorsTable.php similarity index 64% rename from src/Model/Table/RequestProcessorTable.php rename to src/Model/Table/InboxProcessorsTable.php index e18433d..0776f25 100644 --- a/src/Model/Table/RequestProcessorTable.php +++ b/src/Model/Table/InboxProcessorsTable.php @@ -7,15 +7,15 @@ use Cake\Filesystem\Folder; use Cake\Http\Exception\MethodNotAllowedException; use Cake\Core\Exception\Exception; -class MissingRequestProcessorException extends Exception +class MissingInboxProcessorException extends Exception { protected $_defaultCode = 404; } -class RequestProcessorTable extends AppTable +class InboxProcessors extends AppTable { - private $processorsDirectory = ROOT . '/libraries/default/RequestProcessors'; - private $requestProcessors; + private $processorsDirectory = ROOT . '/libraries/default/InboxProcessors'; + private $inboxProcessors; private $enabledProcessors = [ // to be defined in config 'Brood' => [ 'ToolInterconnection' => false, @@ -40,16 +40,16 @@ class RequestProcessorTable extends AppTable public function getProcessor($scope, $action=null) { - if (isset($this->requestProcessors[$scope])) { + if (isset($this->inboxProcessors[$scope])) { if (is_null($action)) { - return $this->requestProcessors[$scope]; - } else if (!empty($this->requestProcessors[$scope]->{$action})) { - return $this->requestProcessors[$scope]->{$action}; + return $this->inboxProcessors[$scope]; + } else if (!empty($this->inboxProcessors[$scope]->{$action})) { + return $this->inboxProcessors[$scope]->{$action}; } else { throw new \Exception(__('Processor {0}.{1} not found', $scope, $action)); } } - throw new MissingRequestProcessorException(__('Processor not found')); + throw new MissingInboxProcessorException(__('Processor not found')); } public function getLocalToolProcessor($action, $connectorName) @@ -58,7 +58,7 @@ class RequestProcessorTable extends AppTable $specificScope = "{$connectorName}LocalTool"; try { // try to get specific processor for module name or fall back to generic local tool processor $processor = $this->getProcessor($specificScope, $action); - } catch (MissingRequestProcessorException $e) { + } catch (MissingInboxProcessorException $e) { $processor = $this->getProcessor($scope, $action); } return $processor; @@ -67,12 +67,12 @@ class RequestProcessorTable extends AppTable public function listProcessors($scope=null) { if (is_null($scope)) { - return $this->requestProcessors; + return $this->inboxProcessors; } else { - if (isset($this->requestProcessors[$scope])) { - return $this->requestProcessors[$scope]; + if (isset($this->inboxProcessors[$scope])) { + return $this->inboxProcessors[$scope]; } else { - throw new MissingRequestProcessorException(__('Processors for {0} not found', $scope)); + throw new MissingInboxProcessorException(__('Processors for {0} not found', $scope)); } } } @@ -80,30 +80,30 @@ class RequestProcessorTable extends AppTable private function loadProcessors() { $processorDir = new Folder($this->processorsDirectory); - $processorFiles = $processorDir->find('.*RequestProcessor\.php', true); + $processorFiles = $processorDir->find('.*InboxProcessor\.php', true); foreach ($processorFiles as $processorFile) { - if ($processorFile == 'GenericRequestProcessor.php') { + if ($processorFile == 'GenericInboxProcessor.php') { continue; } $processorMainClassName = str_replace('.php', '', $processorFile); - $processorMainClassNameShort = str_replace('RequestProcessor.php', '', $processorFile); + $processorMainClassNameShort = str_replace('InboxProcessor.php', '', $processorFile); $processorMainClass = $this->getProcessorClass($processorDir->pwd() . DS . $processorFile, $processorMainClassName); if (is_object($processorMainClass)) { - $this->requestProcessors[$processorMainClassNameShort] = $processorMainClass; - foreach ($this->requestProcessors[$processorMainClassNameShort]->getRegisteredActions() as $registeredAction) { - $scope = $this->requestProcessors[$processorMainClassNameShort]->getScope(); + $this->inboxProcessors[$processorMainClassNameShort] = $processorMainClass; + foreach ($this->inboxProcessors[$processorMainClassNameShort]->getRegisteredActions() as $registeredAction) { + $scope = $this->inboxProcessors[$processorMainClassNameShort]->getScope(); if (!empty($this->enabledProcessors[$scope][$registeredAction])) { - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = true; + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = true; } else { - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false; + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false; } } } else { - $this->requestProcessors[$processorMainClassNameShort] = new \stdClass(); - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction} = new \stdClass(); - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->action = "N/A"; - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false; - $this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->error = $processorMainClass; + $this->inboxProcessors[$processorMainClassNameShort] = new \stdClass(); + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction} = new \stdClass(); + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->action = "N/A"; + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false; + $this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->error = $processorMainClass; } } } diff --git a/src/View/MonadView.php b/src/View/MonadView.php index 6c72ef3..f0806a0 100644 --- a/src/View/MonadView.php +++ b/src/View/MonadView.php @@ -22,7 +22,7 @@ namespace App\View; class MonadView extends AppView { private $additionalTemplatePaths = [ - ROOT . '/libraries/default/RequestProcessors/templates/', + ROOT . '/libraries/default/InboxProcessors/templates/', ]; protected function _paths(?string $plugin = null, bool $cached = true): array