Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix possible leaking scope in Flow #22359

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}