summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-09-03 12:42:57 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-09-09 22:56:04 +0200
commitd2c8b939d58239a99163445b83d80873932a5514 (patch)
tree97b20dded7223e2e0fc49704a8b5a1c7b190cefb /apps/workflowengine
parentbed518e8abd60875f4fe3d2b0e15fd87b489b6d4 (diff)
downloadnextcloud-server-d2c8b939d58239a99163445b83d80873932a5514.tar.gz
nextcloud-server-d2c8b939d58239a99163445b83d80873932a5514.zip
WFE as proxy listen to relevent events and forwards them
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/workflowengine')
-rw-r--r--apps/workflowengine/appinfo/app.php1
-rw-r--r--apps/workflowengine/lib/AppInfo/Application.php36
-rw-r--r--apps/workflowengine/lib/Manager.php27
3 files changed, 60 insertions, 4 deletions
diff --git a/apps/workflowengine/appinfo/app.php b/apps/workflowengine/appinfo/app.php
index f6f22ce9488..d99c5892231 100644
--- a/apps/workflowengine/appinfo/app.php
+++ b/apps/workflowengine/appinfo/app.php
@@ -21,3 +21,4 @@
$application = new \OCA\WorkflowEngine\AppInfo\Application();
$application->registerHooksAndListeners();
+$application->registerRuleListeners();
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php
index 358353b6623..e691c53d528 100644
--- a/apps/workflowengine/lib/AppInfo/Application.php
+++ b/apps/workflowengine/lib/AppInfo/Application.php
@@ -21,27 +21,36 @@
namespace OCA\WorkflowEngine\AppInfo;
+use OCA\WorkflowEngine\Manager;
use OCP\Template;
use OCA\WorkflowEngine\Controller\RequestTime;
-use OCA\WorkflowEngine\Controller\FlowOperations;
+use OCP\WorkflowEngine\IOperation;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends \OCP\AppFramework\App {
const APP_ID = 'workflowengine';
+ /** @var EventDispatcherInterface */
+ protected $dispatcher;
+ /** @var Manager */
+ protected $manager;
+
public function __construct() {
parent::__construct(self::APP_ID);
- $this->getContainer()->registerAlias('FlowOperationsController', FlowOperations::class);
$this->getContainer()->registerAlias('RequestTimeController', RequestTime::class);
+
+ $this->dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
+ $this->manager = $this->getContainer()->query(Manager::class);
}
/**
* Register all hooks and listeners
*/
public function registerHooksAndListeners() {
- $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
- $dispatcher->addListener(
+ $this->dispatcher->addListener(
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
function() {
if (!function_exists('style')) {
@@ -68,4 +77,23 @@ class Application extends \OCP\AppFramework\App {
-100
);
}
+
+ public function registerRuleListeners() {
+ $configuredEvents = $this->manager->getAllConfiguredEvents();
+
+ foreach ($configuredEvents as $operationClass => $events) {
+ foreach ($events as $entityClass => $eventNames) {
+ array_map(function (string $eventName) use ($operationClass) {
+ $this->dispatcher->addListener(
+ $eventName,
+ function (GenericEvent $event) use ($eventName, $operationClass) {
+ /** @var IOperation $operation */
+ $operation = $this->getContainer()->query($operationClass);
+ $operation->onEvent($eventName, $event);
+ }
+ );
+ }, $eventNames);
+ }
+ }
+ }
}
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 7ca24a754dc..8782fd3efef 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -182,6 +182,33 @@ class Manager implements IManager, IEntityAware {
throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class']));
}
}
+
+ public function getAllConfiguredEvents() {
+ $query = $this->connection->getQueryBuilder();
+
+ $query->selectDistinct('class')
+ ->addSelect('entity', 'events')
+ ->from('flow_operations')
+ ->where($query->expr()->neq('events', $query->createNamedParameter('[]'), IQueryBuilder::PARAM_STR));
+
+ $result = $query->execute();
+ $operations = [];
+ while($row = $result->fetch()) {
+ $eventNames = \json_decode($row['events']);
+
+ $operation = $row['class'];
+ $entity = $row['entity'];
+
+ $operations[$operation] = $operations[$row['class']] ?? [];
+ $operations[$operation][$entity] = $operations[$operation][$entity] ?? [];
+
+ $operations[$operation][$entity] = array_unique(array_merge($operations[$operation][$entity], $eventNames));
+ }
+ $result->closeCursor();
+
+ return $operations;
+ }
+
public function getAllOperations(ScopeContext $scopeContext): array {
if(isset($this->operations[$scopeContext->getHash()])) {
return $this->operations[$scopeContext->getHash()];