diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 32b04c1021..23f62da4f8 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -28,12 +28,14 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Storage\IStorage; use OCP\IDBConnection; use OCP\IL10N; +use OCP\ILogger; use OCP\IServerContainer; use OCP\WorkflowEngine\ICheck; +use OCP\WorkflowEngine\IEntityAware; use OCP\WorkflowEngine\IManager; use OCP\WorkflowEngine\IOperation; -class Manager implements IManager { +class Manager implements IManager, IEntityAware { /** @var IStorage */ protected $storage; @@ -41,6 +43,9 @@ class Manager implements IManager { /** @var string */ protected $path; + /** @var object */ + protected $entity; + /** @var array[] */ protected $operations = []; @@ -118,7 +123,10 @@ class Manager implements IManager { return true; } - if ($checkInstance instanceof ICheck) { + if ($checkInstance instanceof IEntityAware && $this->entity !== null) { + $checkInstance->setEntity($this->entity); + return $checkInstance->executeCheck($check['operator'], $check['value']); + } elseif ($checkInstance instanceof ICheck) { $checkInstance->setFileInfo($this->storage, $this->path); return $checkInstance->executeCheck($check['operator'], $check['value']); } else { @@ -388,4 +396,22 @@ class Manager implements IManager { return $operation; } + + /** + * @param object $entity + * @since 18.0.0 + */ + public function setEntity($entity) { + if(!is_object($entity)) { + $this->container->getLogger()->logException( + new \InvalidArgumentException('provided entity is not an object'), + [ + 'app' => 'workflowengine', + 'level' => ILogger::ERROR, + ] + ); + return; + } + $this->entity = $entity; + } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 2c2b8889e2..bee3264891 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -439,6 +439,7 @@ 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\\IEntityAware' => $baseDir . '/lib/public/WorkflowEngine/IEntityAware.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 6bd401b4d7..eab2897df0 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -473,6 +473,7 @@ 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\\IEntityAware' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityAware.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/IEntityAware.php b/lib/public/WorkflowEngine/IEntityAware.php new file mode 100644 index 0000000000..2ef74d2b11 --- /dev/null +++ b/lib/public/WorkflowEngine/IEntityAware.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 OCP\WorkflowEngine; + + +interface IEntityAware { + /** + * @param object $entity + * @since 18.0.0 + */ + public function setEntity($entity); +}