Skip to content

Commit 6eb56fc

Browse files
committed
fix possible leaking scope in Flow
- 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 <blizzz@arthur-schiwon.de>
1 parent 9073a69 commit 6eb56fc

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

apps/workflowengine/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function boot(IBootContext $context): void {
6565
private function registerRuleListeners(IEventDispatcher $dispatcher,
6666
IServerContainer $container,
6767
ILogger $logger): void {
68+
/** @var Manager $manager */
6869
$manager = $container->query(Manager::class);
6970
$configuredEvents = $manager->getAllConfiguredEvents();
7071

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

85+
$ruleMatcher->setEventName($eventName);
8486
$ruleMatcher->setEntity($entity);
8587
$ruleMatcher->setOperation($operation);
8688

apps/workflowengine/lib/Service/RuleMatcher.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class RuleMatcher implements IRuleMatcher {
6262
protected $entity;
6363
/** @var Logger */
6464
protected $logger;
65+
/** @var string */
66+
protected $eventName;
6567

6668
public function __construct(
6769
IUserSession $session,
@@ -101,6 +103,13 @@ public function setEntity(IEntity $entity): void {
101103
$this->entity = $entity;
102104
}
103105

106+
public function setEventName(string $eventName): void {
107+
if ($this->eventName !== null) {
108+
throw new RuntimeException('This method must not be called more than once');
109+
}
110+
$this->eventName = $eventName;
111+
}
112+
104113
public function getEntity(): IEntity {
105114
if ($this->entity === null) {
106115
throw new \LogicException('Entity was not set yet');
@@ -155,6 +164,11 @@ public function getMatchingOperations(string $class, bool $returnFirstMatchingOp
155164

156165
$matches = [];
157166
foreach ($operations as $operation) {
167+
$configuredEvents = json_decode($operation['events'], true);
168+
if($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) {
169+
continue;
170+
}
171+
158172
$checkIds = json_decode($operation['checks'], true);
159173
$checks = $this->manager->getChecks($checkIds);
160174

lib/public/WorkflowEngine/IRuleMatcher.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ public function setEntity(IEntity $entity): void;
7878
* @since 18.0.0
7979
*/
8080
public function getEntity(): IEntity;
81+
82+
/**
83+
* this method can be called once to set the event name that is currently
84+
* being processed. The workflow engine takes care of this usually, only an
85+
* IComplexOperation might want to make use of it.
86+
*
87+
* @throws RuntimeException
88+
* @since 20.0.0
89+
*/
90+
public function setEventName(string $eventName): void;
8191
}

0 commit comments

Comments
 (0)