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>
This commit is contained in:
Arthur Schiwon 2020-08-21 17:36:01 +02:00
parent 9073a6937d
commit 28c0eea8cb
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
3 changed files with 26 additions and 0 deletions

View File

@ -65,6 +65,7 @@ class Application extends App implements IBootstrap {
private function registerRuleListeners(IEventDispatcher $dispatcher, private function registerRuleListeners(IEventDispatcher $dispatcher,
IServerContainer $container, IServerContainer $container,
ILogger $logger): void { ILogger $logger): void {
/** @var Manager $manager */
$manager = $container->query(Manager::class); $manager = $container->query(Manager::class);
$configuredEvents = $manager->getAllConfiguredEvents(); $configuredEvents = $manager->getAllConfiguredEvents();
@ -81,6 +82,7 @@ class Application extends App implements IBootstrap {
/** @var IOperation $operation */ /** @var IOperation $operation */
$operation = $container->query($operationClass); $operation = $container->query($operationClass);
$ruleMatcher->setEventName($eventName);
$ruleMatcher->setEntity($entity); $ruleMatcher->setEntity($entity);
$ruleMatcher->setOperation($operation); $ruleMatcher->setOperation($operation);

View File

@ -62,6 +62,8 @@ class RuleMatcher implements IRuleMatcher {
protected $entity; protected $entity;
/** @var Logger */ /** @var Logger */
protected $logger; protected $logger;
/** @var string */
protected $eventName;
public function __construct( public function __construct(
IUserSession $session, IUserSession $session,
@ -101,6 +103,13 @@ class RuleMatcher implements IRuleMatcher {
$this->entity = $entity; $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 { public function getEntity(): IEntity {
if ($this->entity === null) { if ($this->entity === null) {
throw new \LogicException('Entity was not set yet'); throw new \LogicException('Entity was not set yet');
@ -155,6 +164,11 @@ class RuleMatcher implements IRuleMatcher {
$matches = []; $matches = [];
foreach ($operations as $operation) { 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); $checkIds = json_decode($operation['checks'], true);
$checks = $this->manager->getChecks($checkIds); $checks = $this->manager->getChecks($checkIds);

View File

@ -78,4 +78,14 @@ interface IRuleMatcher extends IFileCheck {
* @since 18.0.0 * @since 18.0.0
*/ */
public function getEntity(): IEntity; 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;
} }