entities equip the RuleMatcher on the events they are aware of
Operations will receive the matcher instance Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
849d025d09
commit
ae1cc1d14d
|
@ -24,6 +24,7 @@ namespace OCA\WorkflowEngine\AppInfo;
|
||||||
use OCA\WorkflowEngine\Manager;
|
use OCA\WorkflowEngine\Manager;
|
||||||
use OCP\Template;
|
use OCP\Template;
|
||||||
use OCA\WorkflowEngine\Controller\RequestTime;
|
use OCA\WorkflowEngine\Controller\RequestTime;
|
||||||
|
use OCP\WorkflowEngine\IEntity;
|
||||||
use OCP\WorkflowEngine\IOperation;
|
use OCP\WorkflowEngine\IOperation;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
@ -83,13 +84,17 @@ class Application extends \OCP\AppFramework\App {
|
||||||
|
|
||||||
foreach ($configuredEvents as $operationClass => $events) {
|
foreach ($configuredEvents as $operationClass => $events) {
|
||||||
foreach ($events as $entityClass => $eventNames) {
|
foreach ($events as $entityClass => $eventNames) {
|
||||||
array_map(function (string $eventName) use ($operationClass) {
|
array_map(function (string $eventName) use ($operationClass, $entityClass) {
|
||||||
$this->dispatcher->addListener(
|
$this->dispatcher->addListener(
|
||||||
$eventName,
|
$eventName,
|
||||||
function (GenericEvent $event) use ($eventName, $operationClass) {
|
function (GenericEvent $event) use ($eventName, $operationClass, $entityClass) {
|
||||||
|
$ruleMatcher = $this->manager->getRuleMatcher();
|
||||||
|
/** @var IEntity $entity */
|
||||||
|
$entity = $this->getContainer()->query($entityClass);
|
||||||
|
$entity->prepareRuleMatcher($ruleMatcher, $eventName, $event);
|
||||||
/** @var IOperation $operation */
|
/** @var IOperation $operation */
|
||||||
$operation = $this->getContainer()->query($operationClass);
|
$operation = $this->getContainer()->query($operationClass);
|
||||||
$operation->onEvent($eventName, $event);
|
$operation->onEvent($eventName, $event, $ruleMatcher);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, $eventNames);
|
}, $eventNames);
|
||||||
|
|
|
@ -28,6 +28,8 @@ use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\WorkflowEngine\GenericEntityEvent;
|
use OCP\WorkflowEngine\GenericEntityEvent;
|
||||||
use OCP\WorkflowEngine\IEntity;
|
use OCP\WorkflowEngine\IEntity;
|
||||||
|
use OCP\WorkflowEngine\IRuleMatcher;
|
||||||
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
class File implements IEntity {
|
class File implements IEntity {
|
||||||
|
|
||||||
|
@ -60,4 +62,21 @@ class File implements IEntity {
|
||||||
new GenericEntityEvent($this->l10n->t('File copied'), $namespace . 'postCopy' ),
|
new GenericEntityEvent($this->l10n->t('File copied'), $namespace . 'postCopy' ),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
|
public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, GenericEvent $event): void {
|
||||||
|
switch ($eventName) {
|
||||||
|
case 'postCreate':
|
||||||
|
case 'postWrite':
|
||||||
|
case 'postDelete':
|
||||||
|
case 'postTouch':
|
||||||
|
$ruleMatcher->setEntitySubject($this, $event->getSubject());
|
||||||
|
break;
|
||||||
|
case 'postRename':
|
||||||
|
case 'postCopy':
|
||||||
|
$ruleMatcher->setEntitySubject($this, $event->getSubject()[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCP\WorkflowEngine;
|
namespace OCP\WorkflowEngine;
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface IEntity
|
* Interface IEntity
|
||||||
*
|
*
|
||||||
|
@ -67,4 +69,9 @@ interface IEntity {
|
||||||
*/
|
*/
|
||||||
public function getEvents(): array;
|
public function getEvents(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 18.0.0
|
||||||
|
*/
|
||||||
|
public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, GenericEvent $event): void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,13 @@ interface IOperation {
|
||||||
* Is being called by the workflow engine when an event was triggered that
|
* Is being called by the workflow engine when an event was triggered that
|
||||||
* is configured for this operation. An evaluation whether the event
|
* is configured for this operation. An evaluation whether the event
|
||||||
* qualifies for this operation to run has still to be done by the
|
* qualifies for this operation to run has still to be done by the
|
||||||
* implementor.
|
* implementor by calling the RuleMatchers getMatchingOperations method
|
||||||
|
* and evaluating the results.
|
||||||
*
|
*
|
||||||
* If the implementor is an IComplexOperation, this method will not be
|
* If the implementor is an IComplexOperation, this method will not be
|
||||||
* called automatically. It can be used or left as no-op by the implementor.
|
* called automatically. It can be used or left as no-op by the implementor.
|
||||||
*
|
*
|
||||||
* @since 18.0.0
|
* @since 18.0.0
|
||||||
*/
|
*/
|
||||||
public function onEvent(string $eventName, GenericEvent $event): void;
|
public function onEvent(string $eventName, GenericEvent $event, IRuleMatcher $ruleMatcher): void;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue