From 804d4fe69feb1853846ad7a4b92f01cc637daf71 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 9 Aug 2019 13:24:48 +0200 Subject: [PATCH] introducing Entity interfaces and a File one as first implementation also adds admin settings that pass entities as initial state Signed-off-by: Arthur Schiwon --- .../composer/composer/autoload_classmap.php | 4 + .../composer/composer/autoload_static.php | 4 + .../lib/AppInfo/Application.php | 8 +- apps/workflowengine/lib/Entity/File.php | 68 ++++++++++ .../lib/Entity/GenericEntityEmitterEvent.php | 59 ++++++++ .../lib/Entity/IEntityEmitterEvent.php | 34 +++++ apps/workflowengine/lib/Manager.php | 56 +++++++- apps/workflowengine/lib/Settings/Admin.php | 126 ++++++++++++++++++ apps/workflowengine/templates/admin.php | 20 +-- apps/workflowengine/tests/ManagerTest.php | 71 +++++++++- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + lib/public/WorkflowEngine/IEntity.php | 84 ++++++++++++ lib/public/WorkflowEngine/IEntityEvent.php | 52 ++++++++ lib/public/WorkflowEngine/IManager.php | 8 ++ 15 files changed, 571 insertions(+), 27 deletions(-) create mode 100644 apps/workflowengine/lib/Entity/File.php create mode 100644 apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php create mode 100644 apps/workflowengine/lib/Entity/IEntityEmitterEvent.php create mode 100644 apps/workflowengine/lib/Settings/Admin.php create mode 100644 lib/public/WorkflowEngine/IEntity.php create mode 100644 lib/public/WorkflowEngine/IEntityEvent.php diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php index 14fca1fce4..86a7737547 100644 --- a/apps/workflowengine/composer/composer/autoload_classmap.php +++ b/apps/workflowengine/composer/composer/autoload_classmap.php @@ -20,7 +20,11 @@ return array( 'OCA\\WorkflowEngine\\Controller\\FlowOperations' => $baseDir . '/../lib/Controller/FlowOperations.php', 'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php', 'OCA\\WorkflowEngine\\Controller\\RequestTime' => $baseDir . '/../lib/Controller/RequestTime.php', + 'OCA\\WorkflowEngine\\Entity\\File' => $baseDir . '/../lib/Entity/File.php', + 'OCA\\WorkflowEngine\\Entity\\GenericEntityEmitterEvent' => $baseDir . '/../lib/Entity/GenericEntityEmitterEvent.php', + 'OCA\\WorkflowEngine\\Entity\\IEntityEmitterEvent' => $baseDir . '/../lib/Entity/IEntityEmitterEvent.php', 'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php', 'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => $baseDir . '/../lib/Migration/Version2019Date20190808074233.php', + 'OCA\\WorkflowEngine\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', 'OCA\\WorkflowEngine\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php', ); diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php index 7af16f5370..d13578448c 100644 --- a/apps/workflowengine/composer/composer/autoload_static.php +++ b/apps/workflowengine/composer/composer/autoload_static.php @@ -35,8 +35,12 @@ class ComposerStaticInitWorkflowEngine 'OCA\\WorkflowEngine\\Controller\\FlowOperations' => __DIR__ . '/..' . '/../lib/Controller/FlowOperations.php', 'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php', 'OCA\\WorkflowEngine\\Controller\\RequestTime' => __DIR__ . '/..' . '/../lib/Controller/RequestTime.php', + 'OCA\\WorkflowEngine\\Entity\\File' => __DIR__ . '/..' . '/../lib/Entity/File.php', + 'OCA\\WorkflowEngine\\Entity\\GenericEntityEmitterEvent' => __DIR__ . '/..' . '/../lib/Entity/GenericEntityEmitterEvent.php', + 'OCA\\WorkflowEngine\\Entity\\IEntityEmitterEvent' => __DIR__ . '/..' . '/../lib/Entity/IEntityEmitterEvent.php', 'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php', 'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => __DIR__ . '/..' . '/../lib/Migration/Version2019Date20190808074233.php', + 'OCA\\WorkflowEngine\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', 'OCA\\WorkflowEngine\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php', ); diff --git a/apps/workflowengine/lib/AppInfo/Application.php b/apps/workflowengine/lib/AppInfo/Application.php index 3fee0c3bb8..358353b662 100644 --- a/apps/workflowengine/lib/AppInfo/Application.php +++ b/apps/workflowengine/lib/AppInfo/Application.php @@ -27,8 +27,10 @@ use OCA\WorkflowEngine\Controller\FlowOperations; class Application extends \OCP\AppFramework\App { + const APP_ID = 'workflowengine'; + public function __construct() { - parent::__construct('workflowengine'); + parent::__construct(self::APP_ID); $this->getContainer()->registerAlias('FlowOperationsController', FlowOperations::class); $this->getContainer()->registerAlias('RequestTimeController', RequestTime::class); @@ -47,7 +49,7 @@ class Application extends \OCP\AppFramework\App { class_exists(Template::class, true); } - style('workflowengine', [ + style(self::APP_ID, [ 'admin', ]); @@ -59,7 +61,7 @@ class Application extends \OCP\AppFramework\App { 'systemtags/systemtagscollection', ]); - script('workflowengine', [ + script(self::APP_ID, [ 'workflowengine', ]); }, diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php new file mode 100644 index 0000000000..0ba3502450 --- /dev/null +++ b/apps/workflowengine/lib/Entity/File.php @@ -0,0 +1,68 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\WorkflowEngine\Entity; + +use OCP\Files\IRootFolder; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\WorkflowEngine\IEntity; + +class File implements IEntity { + + /** @var IL10N */ + protected $l10n; + /** @var IURLGenerator */ + protected $urlGenerator; + + public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) { + $this->l10n = $l10n; + $this->urlGenerator = $urlGenerator; + } + + public function getId(): string { + return 'WorkflowEngine_Entity_File'; + } + + public function getName(): string { + return $this->l10n->t('File'); + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('core', 'categories/files.svg'); + } + + public function getEvents(): array { + $emitterClass = IRootFolder::class; + $slot = '\OC\Files'; + return [ + new GenericEntityEmitterEvent($emitterClass, $slot, 'postCreate', $this->l10n->t('File created')), + new GenericEntityEmitterEvent($emitterClass, $slot, 'postWrite', $this->l10n->t('File updated')), + new GenericEntityEmitterEvent($emitterClass, $slot, 'postRename', $this->l10n->t('File renamed')), + new GenericEntityEmitterEvent($emitterClass, $slot, 'postDelete', $this->l10n->t('File deleted')), + new GenericEntityEmitterEvent($emitterClass, $slot, 'postTouch', $this->l10n->t('File accessed')), + new GenericEntityEmitterEvent($emitterClass, $slot, 'postCopy', $this->l10n->t('File copied')), + ]; + } +} diff --git a/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php b/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php new file mode 100644 index 0000000000..60b238432c --- /dev/null +++ b/apps/workflowengine/lib/Entity/GenericEntityEmitterEvent.php @@ -0,0 +1,59 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\WorkflowEngine\Entity; + +class GenericEntityEmitterEvent implements IEntityEmitterEvent { + /** @var string */ + private $emitterClassName; + /** @var string */ + private $eventName; + /** @var string */ + private $displayName; + /** @var string */ + private $slot; + + public function __construct(string $emitterClassName, string $slot, string $eventName, string $displayName) { + $this->emitterClassName = $emitterClassName; + $this->eventName = $eventName; + $this->displayName = $displayName; + $this->slot = $slot; + } + + public function getEmitterClassName(): string { + return $this->emitterClassName; + } + + public function getSlot(): string { + return $this->slot; + } + + public function getDisplayName(): string { + return $this->displayName; + } + + public function getEventName(): string { + return $this->eventName; + } +} diff --git a/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php b/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php new file mode 100644 index 0000000000..7e2c802fe7 --- /dev/null +++ b/apps/workflowengine/lib/Entity/IEntityEmitterEvent.php @@ -0,0 +1,34 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\WorkflowEngine\Entity; + + +use OCP\WorkflowEngine\IEntityEvent; + +interface IEntityEmitterEvent extends IEntityEvent { + public function getEmitterClassName(): string; + + public function getSlot(): string; +} diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 23f62da4f8..3a382f20dc 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -23,6 +23,7 @@ namespace OCA\WorkflowEngine; use OC\Files\Storage\Wrapper\Jail; +use OCA\WorkflowEngine\Entity\File; use OCP\AppFramework\QueryException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Storage\IStorage; @@ -31,9 +32,12 @@ use OCP\IL10N; use OCP\ILogger; use OCP\IServerContainer; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntity; use OCP\WorkflowEngine\IEntityAware; use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IOperation; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class Manager implements IManager, IEntityAware { @@ -61,15 +65,32 @@ class Manager implements IManager, IEntityAware { /** @var IL10N */ protected $l; + /** @var EventDispatcherInterface */ + protected $eventDispatcher; + + /** @var IEntity[] */ + protected $registeredEntities = []; + + /** @var ILogger */ + protected $logger; + /** * @param IDBConnection $connection * @param IServerContainer $container * @param IL10N $l */ - public function __construct(IDBConnection $connection, IServerContainer $container, IL10N $l) { + public function __construct( + IDBConnection $connection, + IServerContainer $container, + IL10N $l, + EventDispatcherInterface $eventDispatcher, + ILogger $logger + ) { $this->connection = $connection; $this->container = $container; $this->l = $l; + $this->eventDispatcher = $eventDispatcher; + $this->logger = $logger; } /** @@ -414,4 +435,37 @@ class Manager implements IManager, IEntityAware { } $this->entity = $entity; } + + /** + * @return IEntity[] + */ + public function getEntitiesList() { + $this->eventDispatcher->dispatch('OCP\WorkflowEngine::registerEntities', new GenericEvent($this)); + + return array_merge($this->getBuildInEntities(), $this->registeredEntities); + } + + /** + * Listen to 'OCP/WorkflowEngine::registerEntities' at the EventDispatcher + * for registering your entities + * + * @since 18.0.0 + */ + public function registerEntity(IEntity $entity): void { + $this->registeredEntities[$entity->getId()] = $entity; + } + + /** + * @return IEntity[] + */ + protected function getBuildInEntities(): array { + try { + return [ + $this->container->query(File::class), + ]; + } catch (QueryException $e) { + $this->logger->logException($e); + return []; + } + } } diff --git a/apps/workflowengine/lib/Settings/Admin.php b/apps/workflowengine/lib/Settings/Admin.php new file mode 100644 index 0000000000..8ffd8533d3 --- /dev/null +++ b/apps/workflowengine/lib/Settings/Admin.php @@ -0,0 +1,126 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\WorkflowEngine\Settings; + +use OCA\WorkflowEngine\AppInfo\Application; +use OCA\WorkflowEngine\Manager; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IInitialStateService; +use OCP\IL10N; +use OCP\Settings\ISettings; +use OCP\WorkflowEngine\IEntity; +use OCP\WorkflowEngine\IEntityEvent; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +class Admin implements ISettings { + + /** @var IL10N */ + private $l10n; + + /** @var string */ + private $appName; + + /** @var EventDispatcherInterface */ + private $eventDispatcher; + + /** @var Manager */ + private $manager; + + /** @var IInitialStateService */ + private $initialStateService; + + /** + * @param string $appName + * @param IL10N $l + * @param EventDispatcherInterface $eventDispatcher + */ + public function __construct( + $appName, + IL10N $l, + EventDispatcherInterface $eventDispatcher, + Manager $manager, + IInitialStateService $initialStateService + ) { + $this->appName = $appName; + $this->l10n = $l; + $this->eventDispatcher = $eventDispatcher; + $this->manager = $manager; + $this->initialStateService = $initialStateService; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts'); + + $entities = $this->manager->getEntitiesList(); + + $this->initialStateService->provideInitialState( + Application::APP_ID, + 'entities', + $this->entitiesToArray($entities) + ); + + return new TemplateResponse(Application::APP_ID, 'admin', [], 'blank'); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'workflow'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 0; + } + + private function entitiesToArray(array $entities) { + return array_map(function (IEntity $entity) { + $events = array_map(function(IEntityEvent $entityEvent) { + return [ + 'eventName' => $entityEvent->getEventName(), + 'displayName' => $entityEvent->getDisplayName() + ]; + }, $entity->getEvents()); + + return [ + 'id' => $entity->getId(), + 'icon' => $entity->getIcon(), + 'name' => $entity->getName(), + 'events' => $events, + ]; + }, $entities); + } + +} diff --git a/apps/workflowengine/templates/admin.php b/apps/workflowengine/templates/admin.php index d3faace71f..04f43bb257 100644 --- a/apps/workflowengine/templates/admin.php +++ b/apps/workflowengine/templates/admin.php @@ -22,22 +22,4 @@ /** @var array $_ */ /** @var \OCP\IL10N $l */ ?> -
-

- - - - - - -

- - - -

- - -
t('Loading…')); ?>
-
+
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index 9136bf0e7c..ecfc92713a 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -22,10 +22,15 @@ namespace OCA\WorkflowEngine\Tests; +use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowEngine\Manager; use OCP\IDBConnection; use OCP\IL10N; +use OCP\ILogger; use OCP\IServerContainer; +use OCP\WorkflowEngine\IEntity; +use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** @@ -38,24 +43,36 @@ class ManagerTest extends TestCase { /** @var Manager */ protected $manager; - /** @var IDBConnection */ + /** @var MockObject|IDBConnection */ protected $db; + /** @var \PHPUnit\Framework\MockObject\MockObject|ILogger */ + protected $logger; + /** @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */ + protected $eventDispatcher; + /** @var MockObject|IServerContainer */ + protected $container; protected function setUp() { parent::setUp(); $this->db = \OC::$server->getDatabaseConnection(); - $container = $this->createMock(IServerContainer::class); + $this->container = $this->createMock(IServerContainer::class); + /** @var IL10N|MockObject $l */ $l = $this->createMock(IL10N::class); $l->method('t') ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); })); + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->logger = $this->createMock(ILogger::class); + $this->manager = new Manager( \OC::$server->getDatabaseConnection(), - $container, - $l + $this->container, + $l, + $this->eventDispatcher, + $this->logger ); $this->clearChecks(); } @@ -91,4 +108,50 @@ class ManagerTest extends TestCase { $this->assertArrayNotHasKey($check1, $data); $this->assertArrayHasKey($check2, $data); } + + public function testGetEntitiesListBuildInOnly() { + $fileEntityMock = $this->createMock(File::class); + + $this->container->expects($this->once()) + ->method('query') + ->with(File::class) + ->willReturn($fileEntityMock); + + $entities = $this->manager->getEntitiesList(); + + $this->assertCount(1, $entities); + $this->assertInstanceOf(IEntity::class, $entities[0]); + } + + public function testGetEntitiesList() { + $fileEntityMock = $this->createMock(File::class); + + $this->container->expects($this->once()) + ->method('query') + ->with(File::class) + ->willReturn($fileEntityMock); + + /** @var MockObject|IEntity $extraEntity */ + $extraEntity = $this->createMock(IEntity::class); + + $this->eventDispatcher->expects($this->once()) + ->method('dispatch') + ->with('OCP\WorkflowEngine::registerEntities', $this->anything()) + ->willReturnCallback(function() use ($extraEntity) { + $this->manager->registerEntity($extraEntity); + }); + + $entities = $this->manager->getEntitiesList(); + + $this->assertCount(2, $entities); + + $entityTypeCounts = array_reduce($entities, function (array $carry, IEntity $entity) { + if($entity instanceof File) $carry[0]++; + else if($entity instanceof IEntity) $carry[1]++; + return $carry; + }, [0, 0]); + + $this->assertSame(1, $entityTypeCounts[0]); + $this->assertSame(1, $entityTypeCounts[1]); + } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index bee3264891..2c76674ee5 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -439,7 +439,9 @@ return array( 'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\Util' => $baseDir . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php', + 'OCP\\WorkflowEngine\\IEntity' => $baseDir . '/lib/public/WorkflowEngine/IEntity.php', 'OCP\\WorkflowEngine\\IEntityAware' => $baseDir . '/lib/public/WorkflowEngine/IEntityAware.php', + 'OCP\\WorkflowEngine\\IEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/IEntityEvent.php', 'OCP\\WorkflowEngine\\IManager' => $baseDir . '/lib/public/WorkflowEngine/IManager.php', 'OCP\\WorkflowEngine\\IOperation' => $baseDir . '/lib/public/WorkflowEngine/IOperation.php', 'OC\\Accounts\\Account' => $baseDir . '/lib/private/Accounts/Account.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index eab2897df0..651364d06c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -473,7 +473,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php', 'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php', + 'OCP\\WorkflowEngine\\IEntity' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntity.php', 'OCP\\WorkflowEngine\\IEntityAware' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityAware.php', + 'OCP\\WorkflowEngine\\IEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityEvent.php', 'OCP\\WorkflowEngine\\IManager' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IManager.php', 'OCP\\WorkflowEngine\\IOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IOperation.php', 'OC\\Accounts\\Account' => __DIR__ . '/../../..' . '/lib/private/Accounts/Account.php', diff --git a/lib/public/WorkflowEngine/IEntity.php b/lib/public/WorkflowEngine/IEntity.php new file mode 100644 index 0000000000..2e77b74136 --- /dev/null +++ b/lib/public/WorkflowEngine/IEntity.php @@ -0,0 +1,84 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\WorkflowEngine; + +/** + * Interface IEntity + * + * This interface represents an entity that supports events the workflow engine + * can listen to. For example a file with the create, update, etc. events. + * + * Ensure to listen to 'OCP/WorkflowEngine::loadEntities' for registering your + * entities. + * + * @package OCP\WorkflowEngine + * @since 18.0.0 + */ +interface IEntity { + + /** + * returns a unique ID of the entity. + * + * It can be, but does not need to be the class name of the entitiy. Beware + * that it will be referenced in the database when rules are established, + * so it should not change over the course of the app life. + * + * Example 1: "OCA/MyApp/Entity/Cat" + * Example 2: "myapp_Cats" + * + * @since 18.0.0 + */ + public function getId(): string; + + /** + * returns a translated name to be presented in the web interface. + * + * Example: "File" (en), "Dosiero" (eo) + * + * @since 18.0.0 + */ + public function getName(): string; + + /** + * returns the URL to the icon of the entity for display in the web interface. + * + * Usually, the implementation would utilize the `imagePath()` method of the + * `\OCP\IURLGenerator` instance and simply return its result. + * + * Example implementation: return $this->urlGenerator->imagePath('myApp', 'cat.svg'); + * + * @since 18.0.0 + */ + public function getIcon(): string; + + /** + * returns a list of supported events + * + * @return IEntityEvent[] + * @since 18.0.0 + */ + public function getEvents(): array; + +} diff --git a/lib/public/WorkflowEngine/IEntityEvent.php b/lib/public/WorkflowEngine/IEntityEvent.php new file mode 100644 index 0000000000..89186e808e --- /dev/null +++ b/lib/public/WorkflowEngine/IEntityEvent.php @@ -0,0 +1,52 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\WorkflowEngine; + +/** + * Interface IEntityEvent + * + * represents an entitiy event that is dispatched via EventDispatcher + * + * @package OCP\WorkflowEngine + */ +interface IEntityEvent { + /** + * returns a translated name to be presented in the web interface. + * + * Example: "created" (en), "kreita" (eo) + * + * @since 18.0.0 + */ + public function getDisplayName(): string; + + /** + * returns the event name that is emitted by the EventDispatcher, e.g.: + * + * Example: "OCA\MyApp\Factory\Cats::postCreated" + * + * @since 18.0.0 + */ + public function getEventName(): string; +} diff --git a/lib/public/WorkflowEngine/IManager.php b/lib/public/WorkflowEngine/IManager.php index cd323a816f..33a1dd1bb6 100644 --- a/lib/public/WorkflowEngine/IManager.php +++ b/lib/public/WorkflowEngine/IManager.php @@ -47,4 +47,12 @@ interface IManager { * @since 9.1 */ public function getMatchingOperations($class, $returnFirstMatchingOperationOnly = true); + + /** + * Listen to 'OCP/WorkflowEngine::registerEntities' at the EventDispatcher + * for registering your entities + * + * @since 18.0.0 + */ + public function registerEntity(IEntity $entity): void; }