summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2020-01-07 09:58:40 +0100
committerGitHub <noreply@github.com>2020-01-07 09:58:40 +0100
commit55fd157f15fa264b1170da4ebce830349fc85991 (patch)
treebe26a1726445840e547e1128a3383612879bf31a /apps
parent1b8f81617079cd49fb35d9d893370815ea5d05c1 (diff)
parent25d4f3230d840d88191f905b2f3767d982c311b6 (diff)
downloadnextcloud-server-55fd157f15fa264b1170da4ebce830349fc85991.tar.gz
nextcloud-server-55fd157f15fa264b1170da4ebce830349fc85991.zip
Merge pull request #18535 from nextcloud/enh/flow/newDispatcher
Use the new Events in Flow
Diffstat (limited to 'apps')
-rw-r--r--apps/workflowengine/lib/Manager.php35
-rw-r--r--apps/workflowengine/tests/ManagerTest.php15
2 files changed, 31 insertions, 19 deletions
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 7e447a38a01..5ba2533ffe6 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -37,12 +37,16 @@ use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Service\RuleMatcher;
use OCP\AppFramework\QueryException;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IUserSession;
+use OCP\WorkflowEngine\Events\RegisterChecksEvent;
+use OCP\WorkflowEngine\Events\RegisterEntitiesEvent;
+use OCP\WorkflowEngine\Events\RegisterOperationsEvent;
use OCP\WorkflowEngine\ICheck;
use OCP\WorkflowEngine\IComplexOperation;
use OCP\WorkflowEngine\IEntity;
@@ -50,7 +54,7 @@ use OCP\WorkflowEngine\IEntityEvent;
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IOperation;
use OCP\WorkflowEngine\IRuleMatcher;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface as LegacyDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
class Manager implements IManager {
@@ -79,8 +83,8 @@ class Manager implements IManager {
/** @var IL10N */
protected $l;
- /** @var EventDispatcherInterface */
- protected $eventDispatcher;
+ /** @var LegacyDispatcher */
+ protected $legacyEventDispatcher;
/** @var IEntity[] */
protected $registeredEntities = [];
@@ -100,26 +104,26 @@ class Manager implements IManager {
/** @var IUserSession */
protected $session;
- /**
- * @param IDBConnection $connection
- * @param IServerContainer $container
- * @param IL10N $l
- */
+ /** @var IEventDispatcher */
+ private $dispatcher;
+
public function __construct(
IDBConnection $connection,
IServerContainer $container,
IL10N $l,
- EventDispatcherInterface $eventDispatcher,
+ LegacyDispatcher $eventDispatcher,
ILogger $logger,
- IUserSession $session
+ IUserSession $session,
+ IEventDispatcher $dispatcher
) {
$this->connection = $connection;
$this->container = $container;
$this->l = $l;
- $this->eventDispatcher = $eventDispatcher;
+ $this->legacyEventDispatcher = $eventDispatcher;
$this->logger = $logger;
$this->operationsByScope = new CappedMemoryCache(64);
$this->session = $session;
+ $this->dispatcher = $dispatcher;
}
public function getRuleMatcher(): IRuleMatcher {
@@ -606,7 +610,8 @@ class Manager implements IManager {
* @return IEntity[]
*/
public function getEntitiesList(): array {
- $this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this));
+ $this->dispatcher->dispatchTyped(new RegisterEntitiesEvent($this));
+ $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this));
return array_values(array_merge($this->getBuildInEntities(), $this->registeredEntities));
}
@@ -615,7 +620,8 @@ class Manager implements IManager {
* @return IOperation[]
*/
public function getOperatorList(): array {
- $this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this));
+ $this->dispatcher->dispatchTyped(new RegisterOperationsEvent($this));
+ $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this));
return array_merge($this->getBuildInOperators(), $this->registeredOperators);
}
@@ -624,7 +630,8 @@ class Manager implements IManager {
* @return ICheck[]
*/
public function getCheckList(): array {
- $this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this));
+ $this->dispatcher->dispatchTyped(new RegisterChecksEvent($this));
+ $this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this));
return array_merge($this->getBuildInChecks(), $this->registeredChecks);
}
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php
index 82f1653ef25..22d323a9436 100644
--- a/apps/workflowengine/tests/ManagerTest.php
+++ b/apps/workflowengine/tests/ManagerTest.php
@@ -26,6 +26,7 @@ use OC\L10N\L10N;
use OCA\WorkflowEngine\Entity\File;
use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Manager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -57,13 +58,15 @@ class ManagerTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|ILogger */
protected $logger;
/** @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */
- protected $eventDispatcher;
+ protected $legacyDispatcher;
/** @var MockObject|IServerContainer */
protected $container;
/** @var MockObject|IUserSession */
protected $session;
/** @var MockObject|L10N */
protected $l;
+ /** @var MockObject|IEventDispatcher */
+ protected $dispatcher;
protected function setUp(): void {
parent::setUp();
@@ -77,17 +80,19 @@ class ManagerTest extends TestCase {
return vsprintf($text, $parameters);
}));
- $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->logger = $this->createMock(ILogger::class);
$this->session = $this->createMock(IUserSession::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->manager = new Manager(
\OC::$server->getDatabaseConnection(),
$this->container,
$this->l,
- $this->eventDispatcher,
+ $this->legacyDispatcher,
$this->logger,
- $this->session
+ $this->session,
+ $this->dispatcher
);
$this->clearTables();
}
@@ -402,7 +407,7 @@ class ManagerTest extends TestCase {
/** @var MockObject|IEntity $extraEntity */
$extraEntity = $this->createMock(IEntity::class);
- $this->eventDispatcher->expects($this->once())
+ $this->legacyDispatcher->expects($this->once())
->method('dispatch')
->with('OCP\WorkflowEngine::registerEntities', $this->anything())
->willReturnCallback(function() use ($extraEntity) {