aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-06 10:54:37 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-13 14:23:39 +0100
commit2efe8aad38b83e0ec7f21b836f4e503045990213 (patch)
tree8ee6f6ea0f802687e27c7c5797154369206c109f /apps/workflowengine/lib
parentd9204f61ead5f5c95cbef21a5d6fc40ac2d1861a (diff)
downloadnextcloud-server-2efe8aad38b83e0ec7f21b836f4e503045990213.tar.gz
nextcloud-server-2efe8aad38b83e0ec7f21b836f4e503045990213.zip
relax dependency on GenericEvent, instead stay compatible with old events
* also fixes tagging events Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/workflowengine/lib')
-rw-r--r--apps/workflowengine/lib/AppInfo/Application.php32
-rw-r--r--apps/workflowengine/lib/Entity/File.php36
2 files changed, 48 insertions, 20 deletions
diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php
index cea6ac7a1e5..8ac291b9289 100644
--- a/apps/workflowengine/lib/AppInfo/Application.php
+++ b/apps/workflowengine/lib/AppInfo/Application.php
@@ -23,12 +23,14 @@ namespace OCA\WorkflowEngine\AppInfo;
use OCA\WorkflowEngine\Manager;
use OCP\AppFramework\QueryException;
+use OCP\EventDispatcher\Event;
use OCP\Template;
use OCA\WorkflowEngine\Controller\RequestTime;
use OCP\WorkflowEngine\IEntity;
+use OCP\WorkflowEngine\IEntityCompat;
use OCP\WorkflowEngine\IOperation;
+use OCP\WorkflowEngine\IOperationCompat;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends \OCP\AppFramework\App {
@@ -54,7 +56,7 @@ class Application extends \OCP\AppFramework\App {
public function registerHooksAndListeners() {
$this->dispatcher->addListener(
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
- function() {
+ function () {
if (!function_exists('style')) {
// This is hacky, but we need to load the template class
class_exists(Template::class, true);
@@ -88,15 +90,35 @@ class Application extends \OCP\AppFramework\App {
array_map(function (string $eventName) use ($operationClass, $entityClass) {
$this->dispatcher->addListener(
$eventName,
- function (GenericEvent $event) use ($eventName, $operationClass, $entityClass) {
+ function ($event) use ($eventName, $operationClass, $entityClass) {
$ruleMatcher = $this->manager->getRuleMatcher();
try {
/** @var IEntity $entity */
$entity = $this->getContainer()->query($entityClass);
- $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event);
/** @var IOperation $operation */
$operation = $this->getContainer()->query($operationClass);
- $operation->onEvent($eventName, $event, $ruleMatcher);
+
+ if ($event instanceof Event) {
+ $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event);
+ $operation->onEvent($eventName, $event, $ruleMatcher);
+ } else if ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) {
+ // TODO: Remove this block (and the compat classes) in the first major release in 2023
+ $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event);
+ $operation->onEventCompat($eventName, $event, $ruleMatcher);
+ } else {
+ $logger = $this->getContainer()->getServer()->getLogger();
+ $logger->warning(
+ 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}',
+ [
+ 'app' => self::APP_ID,
+ 'name' => $eventName,
+ 'event' => get_class($event),
+ 'entity' => $entityClass,
+ 'operation' => $operationClass,
+ ]
+ );
+ }
+
} catch (QueryException $e) {
// Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now
}
diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php
index 8fb035afacc..a9d71d5f8c1 100644
--- a/apps/workflowengine/lib/Entity/File.php
+++ b/apps/workflowengine/lib/Entity/File.php
@@ -24,8 +24,11 @@ declare(strict_types=1);
namespace OCA\WorkflowEngine\Entity;
+use OCA\WorkflowEngine\AppInfo\Application;
+use OCP\EventDispatcher\Event;
use OCP\Files\IRootFolder;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\SystemTag\MapperEvent;
use OCP\WorkflowEngine\GenericEntityEvent;
@@ -40,12 +43,15 @@ class File implements IEntity {
/** @var IURLGenerator */
protected $urlGenerator;
/** @var IRootFolder */
- private $root;
+ protected $root;
+ /** @var ILogger */
+ protected $logger;
- public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, IRootFolder $root) {
+ public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, IRootFolder $root, ILogger $logger) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->root = $root;
+ $this->logger = $logger;
}
public function getName(): string {
@@ -59,20 +65,20 @@ class File implements IEntity {
public function getEvents(): array {
$namespace = '\OCP\Files::';
return [
- new GenericEntityEvent($this->l10n->t('File created'), $namespace . 'postCreate' ),
- new GenericEntityEvent($this->l10n->t('File updated'), $namespace . 'postWrite' ),
- new GenericEntityEvent($this->l10n->t('File renamed'), $namespace . 'postRename' ),
- new GenericEntityEvent($this->l10n->t('File deleted'), $namespace . 'postDelete' ),
- new GenericEntityEvent($this->l10n->t('File accessed'), $namespace . 'postTouch' ),
- new GenericEntityEvent($this->l10n->t('File copied'), $namespace . 'postCopy' ),
- new GenericEntityEvent($this->l10n->t('Tag assigned'), MapperEvent::EVENT_ASSIGN ),
+ new GenericEntityEvent($this->l10n->t('File created'), $namespace . 'postCreate'),
+ new GenericEntityEvent($this->l10n->t('File updated'), $namespace . 'postWrite'),
+ new GenericEntityEvent($this->l10n->t('File renamed'), $namespace . 'postRename'),
+ new GenericEntityEvent($this->l10n->t('File deleted'), $namespace . 'postDelete'),
+ new GenericEntityEvent($this->l10n->t('File accessed'), $namespace . 'postTouch'),
+ new GenericEntityEvent($this->l10n->t('File copied'), $namespace . 'postCopy'),
+ new GenericEntityEvent($this->l10n->t('Tag assigned'), MapperEvent::EVENT_ASSIGN),
];
}
- /**
- * @since 18.0.0
- */
- public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, GenericEvent $event): void {
+ public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, Event $event): void {
+ if (!$event instanceof GenericEvent && !$event instanceof MapperEvent) {
+ return;
+ }
switch ($eventName) {
case 'postCreate':
case 'postWrite':
@@ -85,11 +91,11 @@ class File implements IEntity {
$ruleMatcher->setEntitySubject($this, $event->getSubject()[1]);
break;
case MapperEvent::EVENT_ASSIGN:
- if(!$event instanceof MapperEvent || $event->getObjectType() !== 'files') {
+ if (!$event instanceof MapperEvent || $event->getObjectType() !== 'files') {
break;
}
$nodes = $this->root->getById((int)$event->getObjectId());
- if(is_array($nodes) && !empty($nodes)) {
+ if (is_array($nodes) && !empty($nodes)) {
$node = array_shift($nodes);
$ruleMatcher->setEntitySubject($this, $node);
}