@@ -20,7 +20,7 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | script('core', [ |
| 23 | - 'dist/systemtags', |
|
| 23 | + 'dist/systemtags', |
|
| 24 | 24 | ]); |
| 25 | 25 | |
| 26 | 26 | script('systemtags', 'admin'); |
@@ -35,105 +35,105 @@ |
||
| 35 | 35 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 36 | 36 | |
| 37 | 37 | class Application extends \OCP\AppFramework\App { |
| 38 | - public const APP_ID = 'workflowengine'; |
|
| 39 | - |
|
| 40 | - /** @var EventDispatcherInterface */ |
|
| 41 | - protected $dispatcher; |
|
| 42 | - /** @var Manager */ |
|
| 43 | - protected $manager; |
|
| 44 | - |
|
| 45 | - public function __construct() { |
|
| 46 | - parent::__construct(self::APP_ID); |
|
| 47 | - |
|
| 48 | - $this->getContainer()->registerAlias('RequestTimeController', RequestTime::class); |
|
| 49 | - |
|
| 50 | - $this->dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 51 | - $this->manager = $this->getContainer()->query(Manager::class); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Register all hooks and listeners |
|
| 56 | - */ |
|
| 57 | - public function registerHooksAndListeners() { |
|
| 58 | - $this->dispatcher->addListener( |
|
| 59 | - 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 60 | - function () { |
|
| 61 | - if (!function_exists('style')) { |
|
| 62 | - // This is hacky, but we need to load the template class |
|
| 63 | - class_exists(Template::class, true); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - script('core', [ |
|
| 67 | - 'files/fileinfo', |
|
| 68 | - 'files/client', |
|
| 69 | - 'dist/systemtags', |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - script(self::APP_ID, [ |
|
| 73 | - 'workflowengine', |
|
| 74 | - ]); |
|
| 75 | - }, |
|
| 76 | - -100 |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function registerRuleListeners() { |
|
| 81 | - $configuredEvents = $this->manager->getAllConfiguredEvents(); |
|
| 82 | - |
|
| 83 | - foreach ($configuredEvents as $operationClass => $events) { |
|
| 84 | - foreach ($events as $entityClass => $eventNames) { |
|
| 85 | - array_map(function (string $eventName) use ($operationClass, $entityClass) { |
|
| 86 | - $this->dispatcher->addListener( |
|
| 87 | - $eventName, |
|
| 88 | - function ($event) use ($eventName, $operationClass, $entityClass) { |
|
| 89 | - $ruleMatcher = $this->manager->getRuleMatcher(); |
|
| 90 | - try { |
|
| 91 | - /** @var IEntity $entity */ |
|
| 92 | - $entity = $this->getContainer()->query($entityClass); |
|
| 93 | - /** @var IOperation $operation */ |
|
| 94 | - $operation = $this->getContainer()->query($operationClass); |
|
| 95 | - |
|
| 96 | - $ruleMatcher->setEntity($entity); |
|
| 97 | - $ruleMatcher->setOperation($operation); |
|
| 98 | - |
|
| 99 | - $ctx = new LogContext(); |
|
| 100 | - $ctx |
|
| 101 | - ->setOperation($operation) |
|
| 102 | - ->setEntity($entity) |
|
| 103 | - ->setEventName($eventName); |
|
| 104 | - |
|
| 105 | - /** @var Logger $flowLogger */ |
|
| 106 | - $flowLogger = $this->getContainer()->query(Logger::class); |
|
| 107 | - $flowLogger->logEventInit($ctx); |
|
| 108 | - |
|
| 109 | - if ($event instanceof Event) { |
|
| 110 | - $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
| 111 | - $operation->onEvent($eventName, $event, $ruleMatcher); |
|
| 112 | - } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
| 113 | - // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
| 114 | - $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
| 115 | - $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
| 116 | - } else { |
|
| 117 | - $logger = $this->getContainer()->getServer()->getLogger(); |
|
| 118 | - $logger->debug( |
|
| 119 | - 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
| 120 | - [ |
|
| 121 | - 'app' => self::APP_ID, |
|
| 122 | - 'name' => $eventName, |
|
| 123 | - 'event' => get_class($event), |
|
| 124 | - 'entity' => $entityClass, |
|
| 125 | - 'operation' => $operationClass, |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - $flowLogger->logEventDone($ctx); |
|
| 130 | - } catch (QueryException $e) { |
|
| 131 | - // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - ); |
|
| 135 | - }, $eventNames ?? []); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 38 | + public const APP_ID = 'workflowengine'; |
|
| 39 | + |
|
| 40 | + /** @var EventDispatcherInterface */ |
|
| 41 | + protected $dispatcher; |
|
| 42 | + /** @var Manager */ |
|
| 43 | + protected $manager; |
|
| 44 | + |
|
| 45 | + public function __construct() { |
|
| 46 | + parent::__construct(self::APP_ID); |
|
| 47 | + |
|
| 48 | + $this->getContainer()->registerAlias('RequestTimeController', RequestTime::class); |
|
| 49 | + |
|
| 50 | + $this->dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 51 | + $this->manager = $this->getContainer()->query(Manager::class); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Register all hooks and listeners |
|
| 56 | + */ |
|
| 57 | + public function registerHooksAndListeners() { |
|
| 58 | + $this->dispatcher->addListener( |
|
| 59 | + 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 60 | + function () { |
|
| 61 | + if (!function_exists('style')) { |
|
| 62 | + // This is hacky, but we need to load the template class |
|
| 63 | + class_exists(Template::class, true); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + script('core', [ |
|
| 67 | + 'files/fileinfo', |
|
| 68 | + 'files/client', |
|
| 69 | + 'dist/systemtags', |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + script(self::APP_ID, [ |
|
| 73 | + 'workflowengine', |
|
| 74 | + ]); |
|
| 75 | + }, |
|
| 76 | + -100 |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function registerRuleListeners() { |
|
| 81 | + $configuredEvents = $this->manager->getAllConfiguredEvents(); |
|
| 82 | + |
|
| 83 | + foreach ($configuredEvents as $operationClass => $events) { |
|
| 84 | + foreach ($events as $entityClass => $eventNames) { |
|
| 85 | + array_map(function (string $eventName) use ($operationClass, $entityClass) { |
|
| 86 | + $this->dispatcher->addListener( |
|
| 87 | + $eventName, |
|
| 88 | + function ($event) use ($eventName, $operationClass, $entityClass) { |
|
| 89 | + $ruleMatcher = $this->manager->getRuleMatcher(); |
|
| 90 | + try { |
|
| 91 | + /** @var IEntity $entity */ |
|
| 92 | + $entity = $this->getContainer()->query($entityClass); |
|
| 93 | + /** @var IOperation $operation */ |
|
| 94 | + $operation = $this->getContainer()->query($operationClass); |
|
| 95 | + |
|
| 96 | + $ruleMatcher->setEntity($entity); |
|
| 97 | + $ruleMatcher->setOperation($operation); |
|
| 98 | + |
|
| 99 | + $ctx = new LogContext(); |
|
| 100 | + $ctx |
|
| 101 | + ->setOperation($operation) |
|
| 102 | + ->setEntity($entity) |
|
| 103 | + ->setEventName($eventName); |
|
| 104 | + |
|
| 105 | + /** @var Logger $flowLogger */ |
|
| 106 | + $flowLogger = $this->getContainer()->query(Logger::class); |
|
| 107 | + $flowLogger->logEventInit($ctx); |
|
| 108 | + |
|
| 109 | + if ($event instanceof Event) { |
|
| 110 | + $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
| 111 | + $operation->onEvent($eventName, $event, $ruleMatcher); |
|
| 112 | + } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
| 113 | + // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
| 114 | + $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
| 115 | + $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
| 116 | + } else { |
|
| 117 | + $logger = $this->getContainer()->getServer()->getLogger(); |
|
| 118 | + $logger->debug( |
|
| 119 | + 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
| 120 | + [ |
|
| 121 | + 'app' => self::APP_ID, |
|
| 122 | + 'name' => $eventName, |
|
| 123 | + 'event' => get_class($event), |
|
| 124 | + 'entity' => $entityClass, |
|
| 125 | + 'operation' => $operationClass, |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + $flowLogger->logEventDone($ctx); |
|
| 130 | + } catch (QueryException $e) { |
|
| 131 | + // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + ); |
|
| 135 | + }, $eventNames ?? []); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | } |