-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathRuntime.php
More file actions
105 lines (92 loc) · 2.5 KB
/
Copy pathRuntime.php
File metadata and controls
105 lines (92 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?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\Core\Command\Base;
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\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Runtime extends Base {
public function __construct(
private Manager $manager,
private IUserManager $userManager,
private IUserSession $userSession,
) {
parent::__construct();
}
#[Override]
protected function configure() {
parent::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 ($user === null) {
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;
$operation = $operation->toArray();
$operation['checks'] = $this->manager->getRuntimeChecks($checks, $appId);
}
unset($operation);
}
unset($operations);
$this->writeArrayInOutputFormat($input, $output, $opsByClass);
return 0;
}
}