Skip to content

Commit

Permalink
fix possible leaking scope in Flow
Browse files Browse the repository at this point in the history
- a configured flow can be brought into consideration, despite its event
  was not fired
- it could either run through
- or run into a RuntimeException and killing processing of valid flows

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Aug 24, 2020
1 parent 9073a69 commit 28c0eea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/workflowengine/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function boot(IBootContext $context): void {
private function registerRuleListeners(IEventDispatcher $dispatcher,
IServerContainer $container,
ILogger $logger): void {
/** @var Manager $manager */
$manager = $container->query(Manager::class);
$configuredEvents = $manager->getAllConfiguredEvents();

Expand All @@ -81,6 +82,7 @@ function ($event) use ($manager, $container, $eventName, $logger, $operationClas
/** @var IOperation $operation */
$operation = $container->query($operationClass);

$ruleMatcher->setEventName($eventName);
$ruleMatcher->setEntity($entity);
$ruleMatcher->setOperation($operation);

Expand Down
14 changes: 14 additions & 0 deletions apps/workflowengine/lib/Service/RuleMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class RuleMatcher implements IRuleMatcher {
protected $entity;
/** @var Logger */
protected $logger;
/** @var string */
protected $eventName;

public function __construct(
IUserSession $session,
Expand Down Expand Up @@ -101,6 +103,13 @@ public function setEntity(IEntity $entity): void {
$this->entity = $entity;
}

public function setEventName(string $eventName): void {
if ($this->eventName !== null) {
throw new RuntimeException('This method must not be called more than once');
}
$this->eventName = $eventName;
}

public function getEntity(): IEntity {
if ($this->entity === null) {
throw new \LogicException('Entity was not set yet');
Expand Down Expand Up @@ -155,6 +164,11 @@ public function getMatchingOperations(string $class, bool $returnFirstMatchingOp

$matches = [];
foreach ($operations as $operation) {
$configuredEvents = json_decode($operation['events'], true);
if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) {
continue;
}

$checkIds = json_decode($operation['checks'], true);
$checks = $this->manager->getChecks($checkIds);

Expand Down
10 changes: 10 additions & 0 deletions lib/public/WorkflowEngine/IRuleMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ public function setEntity(IEntity $entity): void;
* @since 18.0.0
*/
public function getEntity(): IEntity;

/**
* this method can be called once to set the event name that is currently
* being processed. The workflow engine takes care of this usually, only an
* IComplexOperation might want to make use of it.
*
* @throws RuntimeException
* @since 20.0.0
*/
public function setEventName(string $eventName): void;
}

0 comments on commit 28c0eea

Please sign in to comment.