Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/workflowengine/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

<commands>
<command>OCA\WorkflowEngine\Command\Index</command>
<command>OCA\WorkflowEngine\Command\Runtime</command>
</commands>

<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/TFileCheck.php',
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php',
'OCA\\WorkflowEngine\\Command\\Index' => $baseDir . '/../lib/Command/Index.php',
'OCA\\WorkflowEngine\\Command\\Runtime' => $baseDir . '/../lib/Command/Runtime.php',
'OCA\\WorkflowEngine\\Controller\\AWorkflowOCSController' => $baseDir . '/../lib/Controller/AWorkflowOCSController.php',
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTimeController' => $baseDir . '/../lib/Controller/RequestTimeController.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ComposerStaticInitWorkflowEngine
'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/TFileCheck.php',
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php',
'OCA\\WorkflowEngine\\Command\\Index' => __DIR__ . '/..' . '/../lib/Command/Index.php',
'OCA\\WorkflowEngine\\Command\\Runtime' => __DIR__ . '/..' . '/../lib/Command/Runtime.php',
'OCA\\WorkflowEngine\\Controller\\AWorkflowOCSController' => __DIR__ . '/..' . '/../lib/Controller/AWorkflowOCSController.php',
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTimeController' => __DIR__ . '/..' . '/../lib/Controller/RequestTimeController.php',
Expand Down
12 changes: 11 additions & 1 deletion apps/workflowengine/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,25 @@ public function register(IRegistrationContext $context): void {

#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'emitRuntimeEvent']));
$context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners']));
}

private function emitRuntimeEvent(IEventDispatcher $dispatcher, ContainerInterface $container): void {
/** @var Manager $manager */
$manager = $container->get(Manager::class);
$manager->reloadRuntimeOperations();
}

private function registerRuleListeners(IEventDispatcher $dispatcher,
ContainerInterface $container,
LoggerInterface $logger): void {
/** @var Manager $manager */
$manager = $container->get(Manager::class);
$configuredEvents = $manager->getAllConfiguredEvents();
$configuredEvents = array_merge_recursive(
$manager->getAllConfiguredEvents(),
$manager->getAllConfiguredRuntimeEvents(),
);

foreach ($configuredEvents as $operationClass => $events) {
foreach ($events as $entityClass => $eventNames) {
Expand Down
103 changes: 103 additions & 0 deletions apps/workflowengine/lib/Command/Runtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WorkflowEngine\Command;

use OC\User\NoUserException;
use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Manager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\WorkflowEngine\IManager;
use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Runtime extends Command {

public function __construct(
private Manager $manager,
private IUserManager $userManager,
private IUserSession $userSession,
) {
parent::__construct();
}

#[Override]
protected function configure() {
$this
->setName('workflows:runtime:list')
->setDescription('Lists configured runtime workflows')
// need to add an optional filtering by app
->addArgument(
'appId',
InputArgument::OPTIONAL,
'Filter runtime workflows by appId',
null
)
->addArgument(
'scope',
InputArgument::OPTIONAL,
'Lists workflows for "admin", "user"',
'admin'
)
->addArgument(
'userId',
InputArgument::OPTIONAL,
'User ID used for user scope and session',
null
);
}

protected function mappedScope(string $scope): int {
return match($scope) {
'admin' => IManager::SCOPE_ADMIN,
'user' => IManager::SCOPE_USER,
default => -1,
};
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$appId = $input->getArgument('appId');
$userId = $input->getArgument('userId');

if ($userId !== null) {
$user = $this->userManager->get($userId);
if (is_null($user)) {
throw new NoUserException("user $userId not found");
}
$this->userSession->setUser($user);
$this->manager->reloadRuntimeOperations();
}

$opsByClass = $this->manager->getAllRuntimeOperations(
new ScopeContext(
$this->mappedScope($input->getArgument('scope')),
$input->getArgument('userId')
),
$appId,
);

foreach ($opsByClass as &$operations) {
foreach ($operations as &$operation) {
$checks = $operation['checks'];
$appId = $operation['appId'];
$decodedChecks = json_decode($checks, true);
$operation['checks'] = $this->manager->getRuntimeChecks($decodedChecks, $appId);
}
unset($operation);
}
unset($operations);

$output->writeln(\json_encode($opsByClass, JSON_PRETTY_PRINT));
return 0;
}
}
Loading
Loading