diff options
Diffstat (limited to 'apps/workflowengine/lib')
18 files changed, 52 insertions, 67 deletions
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index d75b025b3f4..c9e982a311f 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -35,7 +35,6 @@ use OCP\WorkflowEngine\IOperationCompat; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class Application extends \OCP\AppFramework\App { - const APP_ID = 'workflowengine'; /** @var EventDispatcherInterface */ @@ -130,7 +129,6 @@ class Application extends \OCP\AppFramework\App { ); } $flowLogger->logEventDone($ctx); - } catch (QueryException $e) { // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now } @@ -139,7 +137,5 @@ class Application extends \OCP\AppFramework\App { }, $eventNames ?? []); } } - - } } diff --git a/apps/workflowengine/lib/BackgroundJobs/Rotate.php b/apps/workflowengine/lib/BackgroundJobs/Rotate.php index 1602e5a72da..aee817e3cc8 100644 --- a/apps/workflowengine/lib/BackgroundJobs/Rotate.php +++ b/apps/workflowengine/lib/BackgroundJobs/Rotate.php @@ -39,14 +39,14 @@ class Rotate extends TimedJob { $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log'; $this->filePath = trim((string)$config->getAppValue(Application::APP_ID, 'logfile', $default)); - if($this->filePath === '') { + if ($this->filePath === '') { // disabled, nothing to do return; } $this->maxSize = $config->getSystemValue('log_rotate_size', 100 * 1024 * 1024); - if($this->shouldRotateBySize()) { + if ($this->shouldRotateBySize()) { $this->rotate(); } } diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php index 9d378379e5e..0e02c405126 100644 --- a/apps/workflowengine/lib/Check/FileMimeType.php +++ b/apps/workflowengine/lib/Check/FileMimeType.php @@ -62,7 +62,6 @@ class FileMimeType extends AbstractStringCheck implements IFileCheck { $this->_setFileInfo($storage, $path, $isDir); if (!isset($this->mimeType[$this->storage->getId()][$this->path]) || $this->mimeType[$this->storage->getId()][$this->path] === '') { - if ($isDir) { $this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory'; } else { diff --git a/apps/workflowengine/lib/Check/RequestTime.php b/apps/workflowengine/lib/Check/RequestTime.php index aa35e8b84c9..9729129104f 100644 --- a/apps/workflowengine/lib/Check/RequestTime.php +++ b/apps/workflowengine/lib/Check/RequestTime.php @@ -26,7 +26,6 @@ use OCP\IL10N; use OCP\WorkflowEngine\ICheck; class RequestTime implements ICheck { - const REGEX_TIME = '([0-1][0-9]|2[0-3]):([0-5][0-9])'; const REGEX_TIMEZONE = '([a-zA-Z]+(?:\\/[a-zA-Z\-\_]+)+)'; diff --git a/apps/workflowengine/lib/Check/RequestUserAgent.php b/apps/workflowengine/lib/Check/RequestUserAgent.php index 24dfb1b906e..9679f631897 100644 --- a/apps/workflowengine/lib/Check/RequestUserAgent.php +++ b/apps/workflowengine/lib/Check/RequestUserAgent.php @@ -82,5 +82,4 @@ class RequestUserAgent extends AbstractStringCheck { public function isAvailableForScope(int $scope): bool { return true; } - } diff --git a/apps/workflowengine/lib/Controller/AWorkflowController.php b/apps/workflowengine/lib/Controller/AWorkflowController.php index 767ae79c5fd..6d109f7dccf 100644 --- a/apps/workflowengine/lib/Controller/AWorkflowController.php +++ b/apps/workflowengine/lib/Controller/AWorkflowController.php @@ -112,7 +112,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch(DBALException $e) { + } catch (DBALException $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } @@ -139,7 +139,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch(DBALException $e) { + } catch (DBALException $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } @@ -157,7 +157,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch(DBALException $e) { + } catch (DBALException $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } diff --git a/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php index 45930c34c5b..6641155f032 100644 --- a/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php +++ b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php @@ -34,7 +34,7 @@ class GlobalWorkflowsController extends AWorkflowController { private $scopeContext; protected function getScopeContext(): ScopeContext { - if($this->scopeContext === null) { + if ($this->scopeContext === null) { $this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN); } return $this->scopeContext; diff --git a/apps/workflowengine/lib/Controller/UserWorkflowsController.php b/apps/workflowengine/lib/Controller/UserWorkflowsController.php index 226746a2264..c3884b61979 100644 --- a/apps/workflowengine/lib/Controller/UserWorkflowsController.php +++ b/apps/workflowengine/lib/Controller/UserWorkflowsController.php @@ -105,14 +105,13 @@ class UserWorkflowsController extends AWorkflowController { * @throws OCSForbiddenException */ protected function getScopeContext(): ScopeContext { - if($this->scopeContext === null) { + if ($this->scopeContext === null) { $user = $this->session->getUser(); - if(!$user || !$this->manager->isUserScopeEnabled()) { + if (!$user || !$this->manager->isUserScopeEnabled()) { throw new OCSForbiddenException('User not logged in'); } $this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID()); } return $this->scopeContext; } - } diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php index 78178ff759d..4f98a3e5cad 100644 --- a/apps/workflowengine/lib/Entity/File.php +++ b/apps/workflowengine/lib/Entity/File.php @@ -46,7 +46,6 @@ use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IRuleMatcher; class File implements IEntity, IDisplayText, IUrl { - private const EVENT_NAMESPACE = '\OCP\Files::'; /** @var IL10N */ @@ -125,7 +124,7 @@ class File implements IEntity, IDisplayText, IUrl { public function isLegitimatedForUserId(string $uid): bool { try { $node = $this->getNode(); - if($node->getOwner()->getUID() === $uid) { + if ($node->getOwner()->getUID() === $uid) { return true; } $acl = $this->shareManager->getAccessList($node, true, true); @@ -192,19 +191,19 @@ class File implements IEntity, IDisplayText, IUrl { return $this->l10n->t('%s copied %s', $options); case MapperEvent::EVENT_ASSIGN: $tagNames = []; - if($this->event instanceof MapperEvent) { + if ($this->event instanceof MapperEvent) { $tagIDs = $this->event->getTags(); $tagObjects = $this->tagManager->getTagsByIds($tagIDs); foreach ($tagObjects as $systemTag) { /** @var ISystemTag $systemTag */ - if($systemTag->isUserVisible()) { + if ($systemTag->isUserVisible()) { $tagNames[] = $systemTag->getName(); } } } $filename = array_pop($options); $tagString = implode(', ', $tagNames); - if($tagString === '') { + if ($tagString === '') { return ''; } array_push($options, $tagString, $filename); diff --git a/apps/workflowengine/lib/Helper/LogContext.php b/apps/workflowengine/lib/Helper/LogContext.php index 231294d8c74..405d8ceb4ee 100644 --- a/apps/workflowengine/lib/Helper/LogContext.php +++ b/apps/workflowengine/lib/Helper/LogContext.php @@ -41,8 +41,8 @@ class LogContext { public function setScopes(array $scopes): LogContext { $this->details['scopes'] = []; foreach ($scopes as $scope) { - if($scope instanceof ScopeContext) { - switch($scope->getScope()) { + if ($scope instanceof ScopeContext) { + switch ($scope->getScope()) { case IManager::SCOPE_ADMIN: $this->details['scopes'][] = ['scope' => 'admin']; break; @@ -61,7 +61,7 @@ class LogContext { } public function setOperation(?IOperation $operation): LogContext { - if($operation instanceof IOperation) { + if ($operation instanceof IOperation) { $this->details['operation'] = [ 'class' => get_class($operation), 'name' => $operation->getDisplayName(), @@ -71,7 +71,7 @@ class LogContext { } public function setEntity(?IEntity $entity): LogContext { - if($entity instanceof IEntity) { + if ($entity instanceof IEntity) { $this->details['entity'] = [ 'class' => get_class($entity), 'name' => $entity->getName(), diff --git a/apps/workflowengine/lib/Helper/ScopeContext.php b/apps/workflowengine/lib/Helper/ScopeContext.php index e0251131a01..2ddea398f6b 100644 --- a/apps/workflowengine/lib/Helper/ScopeContext.php +++ b/apps/workflowengine/lib/Helper/ScopeContext.php @@ -41,16 +41,15 @@ class ScopeContext { } private function evaluateScope(int $scope): int { - if(in_array($scope, [IManager::SCOPE_ADMIN, IManager::SCOPE_USER], true)) { + if (in_array($scope, [IManager::SCOPE_ADMIN, IManager::SCOPE_USER], true)) { return $scope; } throw new \InvalidArgumentException('Invalid scope'); } private function evaluateScopeId(string $scopeId = null): string { - if($this->scope === IManager::SCOPE_USER - && trim((string)$scopeId) === '') - { + if ($this->scope === IManager::SCOPE_USER + && trim((string)$scopeId) === '') { throw new \InvalidArgumentException('user scope requires a user id'); } return trim((string)$scopeId); @@ -71,7 +70,7 @@ class ScopeContext { } public function getHash(): string { - if($this->hash === null) { + if ($this->hash === null) { $this->hash = \hash('sha256', $this->getScope() . '::' . $this->getScopeId()); } return $this->hash; diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index fbcf3a48493..b583b190070 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -154,7 +154,7 @@ class Manager implements IManager { $result = $query->execute(); $operations = []; - while($row = $result->fetch()) { + while ($row = $result->fetch()) { $eventNames = \json_decode($row['events']); $operation = $row['class']; @@ -201,7 +201,7 @@ class Manager implements IManager { } public function getAllOperations(ScopeContext $scopeContext): array { - if(isset($this->operations[$scopeContext->getHash()])) { + if (isset($this->operations[$scopeContext->getHash()])) { return $this->operations[$scopeContext->getHash()]; } @@ -214,7 +214,7 @@ class Manager implements IManager { ->leftJoin('o', 'flow_operations_scope', 's', $query->expr()->eq('o.id', 's.operation_id')) ->where($query->expr()->eq('s.type', $query->createParameter('scope'))); - if($scopeContext->getScope() === IManager::SCOPE_USER) { + if ($scopeContext->getScope() === IManager::SCOPE_USER) { $query->andWhere($query->expr()->eq('s.value', $query->createParameter('scopeId'))); } @@ -223,7 +223,7 @@ class Manager implements IManager { $this->operations[$scopeContext->getHash()] = []; while ($row = $result->fetch()) { - if(!isset($this->operations[$scopeContext->getHash()][$row['class']])) { + if (!isset($this->operations[$scopeContext->getHash()][$row['class']])) { $this->operations[$scopeContext->getHash()][$row['class']] = []; } $this->operations[$scopeContext->getHash()][$row['class']][] = $row; @@ -324,7 +324,7 @@ class Manager implements IManager { } protected function canModify(int $id, ScopeContext $scopeContext):bool { - if(isset($this->operationsByScope[$scopeContext->getHash()])) { + if (isset($this->operationsByScope[$scopeContext->getHash()])) { return in_array($id, $this->operationsByScope[$scopeContext->getHash()], true); } @@ -334,7 +334,7 @@ class Manager implements IManager { ->leftJoin('o', 'flow_operations_scope', 's', $qb->expr()->eq('o.id', 's.operation_id')) ->where($qb->expr()->eq('s.type', $qb->createParameter('scope'))); - if($scopeContext->getScope() !== IManager::SCOPE_ADMIN) { + if ($scopeContext->getScope() !== IManager::SCOPE_ADMIN) { $qb->where($qb->expr()->eq('s.value', $qb->createParameter('scopeId'))); } @@ -342,7 +342,7 @@ class Manager implements IManager { $result = $qb->execute(); $this->operationsByScope[$scopeContext->getHash()] = []; - while($opId = $result->fetchColumn(0)) { + while ($opId = $result->fetchColumn(0)) { $this->operationsByScope[$scopeContext->getHash()][] = (int)$opId; } $result->closeCursor(); @@ -369,7 +369,7 @@ class Manager implements IManager { string $entity, array $events ): array { - if(!$this->canModify($id, $scopeContext)) { + if (!$this->canModify($id, $scopeContext)) { throw new \DomainException('Target operation not within scope'); }; $row = $this->getOperation($id); @@ -409,7 +409,7 @@ class Manager implements IManager { * @throws \DomainException */ public function deleteOperation($id, ScopeContext $scopeContext) { - if(!$this->canModify($id, $scopeContext)) { + if (!$this->canModify($id, $scopeContext)) { throw new \DomainException('Target operation not within scope'); }; $query = $this->connection->getQueryBuilder(); @@ -418,7 +418,7 @@ class Manager implements IManager { $result = (bool)$query->delete('flow_operations') ->where($query->expr()->eq('id', $query->createNamedParameter($id))) ->execute(); - if($result) { + if ($result) { $qb = $this->connection->getQueryBuilder(); $result &= (bool)$qb->delete('flow_operations_scope') ->where($qb->expr()->eq('operation_id', $qb->createNamedParameter($id))) @@ -430,7 +430,7 @@ class Manager implements IManager { throw $e; } - if(isset($this->operations[$scopeContext->getHash()])) { + if (isset($this->operations[$scopeContext->getHash()])) { unset($this->operations[$scopeContext->getHash()]); } @@ -445,12 +445,12 @@ class Manager implements IManager { throw new \UnexpectedValueException($this->l->t('Entity %s does not exist', [$entity])); } - if(!$instance instanceof IEntity) { + if (!$instance instanceof IEntity) { throw new \UnexpectedValueException($this->l->t('Entity %s is invalid', [$entity])); } - if(empty($events)) { - if(!$operation instanceof IComplexOperation) { + if (empty($events)) { + if (!$operation instanceof IComplexOperation) { throw new \UnexpectedValueException($this->l->t('No events are chosen.')); } return; @@ -463,7 +463,7 @@ class Manager implements IManager { } $diff = array_diff($events, $availableEvents); - if(!empty($diff)) { + if (!empty($diff)) { throw new \UnexpectedValueException($this->l->t('Entity %s has no event %s', [$entity, array_shift($diff)])); } } diff --git a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php index 3c8d4ce81f8..6f344c2ee2d 100644 --- a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php +++ b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php @@ -62,14 +62,13 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { ->set('entity', $qb->createNamedParameter(File::class)) ->where($qb->expr()->emptyString('entity')) ->execute(); - } protected function populateScopeTable(Statement $ids): void { $qb = $this->dbc->getQueryBuilder(); $insertQuery = $qb->insert('flow_operations_scope'); - while($id = $ids->fetchColumn(0)) { + while ($id = $ids->fetchColumn(0)) { $insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]); $insertQuery->execute(); } @@ -86,5 +85,4 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { return $selectQuery->execute(); } - } diff --git a/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php b/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php index 787cd06bfa1..cfbd852d49f 100644 --- a/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php +++ b/apps/workflowengine/lib/Migration/Version2000Date20190808074233.php @@ -112,14 +112,14 @@ class Version2000Date20190808074233 extends SimpleMigrationStep { } protected function ensureEntityColumns(Table $table) { - if(!$table->hasColumn('entity')) { + if (!$table->hasColumn('entity')) { $table->addColumn('entity', Type::STRING, [ 'notnull' => true, 'length' => 256, 'default' => '', ]); } - if(!$table->hasColumn('events')) { + if (!$table->hasColumn('events')) { $table->addColumn('events', Type::TEXT, [ 'notnull' => true, 'default' => '[]', diff --git a/apps/workflowengine/lib/Service/Logger.php b/apps/workflowengine/lib/Service/Logger.php index f369a304e9c..d5aca8f84b7 100644 --- a/apps/workflowengine/lib/Service/Logger.php +++ b/apps/workflowengine/lib/Service/Logger.php @@ -53,7 +53,7 @@ class Logger { protected function initLogger() { $default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log'; $logFile = trim((string)$this->config->getAppValue(Application::APP_ID, 'logfile', $default)); - if($logFile !== '') { + if ($logFile !== '') { $this->flowLogger = $this->logFactory->getCustomLogger($logFile); } } @@ -152,17 +152,16 @@ class Logger { string $message, array $context, LogContext $logContext - ): void - { - if(!isset($context['app'])) { + ): void { + if (!isset($context['app'])) { $context['app'] = Application::APP_ID; } - if(!isset($context['level'])) { + if (!isset($context['level'])) { $context['level'] = ILogger::INFO; } $this->generalLogger->log($context['level'], $message, $context); - if(!$this->flowLogger instanceof IDataLogger) { + if (!$this->flowLogger instanceof IDataLogger) { return; } diff --git a/apps/workflowengine/lib/Service/RuleMatcher.php b/apps/workflowengine/lib/Service/RuleMatcher.php index b022bafb11a..f02c28fa27e 100644 --- a/apps/workflowengine/lib/Service/RuleMatcher.php +++ b/apps/workflowengine/lib/Service/RuleMatcher.php @@ -88,28 +88,28 @@ class RuleMatcher implements IRuleMatcher { } public function setOperation(IOperation $operation): void { - if($this->operation !== null) { + if ($this->operation !== null) { throw new RuntimeException('This method must not be called more than once'); } $this->operation = $operation; } public function setEntity(IEntity $entity): void { - if($this->entity !== null) { + if ($this->entity !== null) { throw new RuntimeException('This method must not be called more than once'); } $this->entity = $entity; } public function getEntity(): IEntity { - if($this->entity === null) { + if ($this->entity === null) { throw new \LogicException('Entity was not set yet'); } return $this->entity; } public function getFlows(bool $returnFirstMatchingOperationOnly = true): array { - if(!$this->operation) { + if (!$this->operation) { throw new RuntimeException('Operation is not set'); } return $this->getMatchingOperations(get_class($this->operation), $returnFirstMatchingOperationOnly); @@ -118,7 +118,7 @@ class RuleMatcher implements IRuleMatcher { public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array { $scopes[] = new ScopeContext(IManager::SCOPE_ADMIN); $user = $this->session->getUser(); - if($user !== null && $this->manager->isUserScopeEnabled()) { + if ($user !== null && $this->manager->isUserScopeEnabled()) { $scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID()); } @@ -134,7 +134,7 @@ class RuleMatcher implements IRuleMatcher { $operations = array_merge($operations, $this->manager->getOperations($class, $scope)); } - if($this->entity instanceof IEntity) { + if ($this->entity instanceof IEntity) { /** @var ScopeContext[] $additionalScopes */ $additionalScopes = $this->manager->getAllConfiguredScopesForOperation($class); foreach ($additionalScopes as $hash => $scopeCandidate) { @@ -188,7 +188,7 @@ class RuleMatcher implements IRuleMatcher { $ctx ->setEntity($this->entity) ->setOperation($this->operation); - if(!empty($matches)) { + if (!empty($matches)) { $ctx->setConfiguration($matches); $this->logger->logRunAll($ctx); } else { @@ -216,11 +216,11 @@ class RuleMatcher implements IRuleMatcher { } $checkInstance->setFileInfo($this->fileInfo['storage'], $this->fileInfo['path'], $this->fileInfo['isDir']); } elseif ($checkInstance instanceof IEntityCheck) { - foreach($this->contexts as $entityInfo) { + foreach ($this->contexts as $entityInfo) { list($entity, $subject) = $entityInfo; $checkInstance->setEntitySubject($entity, $subject); } - } elseif(!$checkInstance instanceof ICheck) { + } elseif (!$checkInstance instanceof ICheck) { // Check is invalid throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class'])); } diff --git a/apps/workflowengine/lib/Settings/Admin.php b/apps/workflowengine/lib/Settings/Admin.php index 3f8cb00982e..11e9096bc56 100644 --- a/apps/workflowengine/lib/Settings/Admin.php +++ b/apps/workflowengine/lib/Settings/Admin.php @@ -28,7 +28,6 @@ namespace OCA\WorkflowEngine\Settings; use OCP\WorkflowEngine\IManager; class Admin extends ASettings { - function getScope(): int { return IManager::SCOPE_ADMIN; } diff --git a/apps/workflowengine/lib/Settings/Personal.php b/apps/workflowengine/lib/Settings/Personal.php index 15f4df3c7e6..af922726121 100644 --- a/apps/workflowengine/lib/Settings/Personal.php +++ b/apps/workflowengine/lib/Settings/Personal.php @@ -28,7 +28,6 @@ namespace OCA\WorkflowEngine\Settings; use OCP\WorkflowEngine\IManager; class Personal extends ASettings { - function getScope(): int { return IManager::SCOPE_USER; } |