diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-11-06 10:54:37 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-11-13 14:23:39 +0100 |
commit | 2efe8aad38b83e0ec7f21b836f4e503045990213 (patch) | |
tree | 8ee6f6ea0f802687e27c7c5797154369206c109f /apps/workflowengine/lib/Entity | |
parent | d9204f61ead5f5c95cbef21a5d6fc40ac2d1861a (diff) | |
download | nextcloud-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/Entity')
-rw-r--r-- | apps/workflowengine/lib/Entity/File.php | 36 |
1 files changed, 21 insertions, 15 deletions
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); } |