mirror of
https://github.com/nextcloud/server.git
synced 2026-05-23 02:26:10 -04:00
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> # Conflicts: # apps/workflowengine/lib/Manager.php
105 lines
2.5 KiB
PHP
105 lines
2.5 KiB
PHP
<?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;
|
|
}
|
|
}
|