|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl\Batch; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\BadUserRequestException; |
|
6
|
|
|
use Jabe\Engine\BatchPermissions; |
|
7
|
|
|
use Jabe\Engine\Batch\BatchInterface; |
|
8
|
|
|
use Jabe\Engine\Impl\{ |
|
9
|
|
|
ProcessEngineLogger, |
|
10
|
|
|
RestartProcessInstanceBuilderImpl, |
|
11
|
|
|
RestartProcessInstancesBatchConfiguration |
|
12
|
|
|
}; |
|
13
|
|
|
use Jabe\Engine\Impl\Batch\Builder\{ |
|
14
|
|
|
BatchBuilder, |
|
15
|
|
|
OperationLogInstanceCountHandlerInterface |
|
16
|
|
|
}; |
|
17
|
|
|
use Jabe\Engine\Impl\Cmd\{ |
|
18
|
|
|
AbstractProcessInstanceModificationCommand, |
|
19
|
|
|
AbstractRestartProcessInstanceCmd, |
|
20
|
|
|
CommandLogger |
|
21
|
|
|
}; |
|
22
|
|
|
use Jabe\Engine\Impl\Interceptor\{ |
|
23
|
|
|
CommandContext, |
|
24
|
|
|
CommandExecutorInterface |
|
25
|
|
|
}; |
|
26
|
|
|
use Jabe\Engine\Impl\Persistence\Entity\ProcessDefinitionEntity; |
|
27
|
|
|
use Jabe\Engine\Impl\Util\EnsureUtil; |
|
28
|
|
|
|
|
29
|
|
|
class RestartProcessInstancesBatchCmd extends AbstractRestartProcessInstanceCmd |
|
30
|
|
|
{ |
|
31
|
|
|
//private final CommandLogger LOG = ProcessEngineLogger.CMD_LOGGER; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(CommandExecutorInterface $commandExecutor, RestartProcessInstanceBuilderImpl $builder) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($commandExecutor, $builder); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function execute(CommandContext $commandContext) |
|
39
|
|
|
{ |
|
40
|
|
|
$collectedInstanceIds = $this->collectProcessInstanceIds(); |
|
41
|
|
|
|
|
42
|
|
|
$instructions = $this->builder->getInstructions(); |
|
43
|
|
|
EnsureUtil::ensureNotEmpty("Restart instructions cannot be empty", "instructions", $instructions); |
|
44
|
|
|
EnsureUtil::ensureNotEmpty("Process instance ids cannot be empty", "processInstanceIds", $collectedInstanceIds); |
|
45
|
|
|
EnsureUtil::ensureNotContainsNull("Process instance ids cannot be null", "processInstanceIds", $collectedInstanceIds); |
|
46
|
|
|
|
|
47
|
|
|
$processDefinitionId = $this->builder->getProcessDefinitionId(); |
|
48
|
|
|
$processDefinition = $this->getProcessDefinition($commandContext, $processDefinitionId); |
|
49
|
|
|
|
|
50
|
|
|
EnsureUtil::ensureNotNull("Process definition cannot be null", "processDefinition", $processDefinition); |
|
51
|
|
|
EnsureUtil::ensureTenantAuthorized($commandContext, $processDefinition); |
|
52
|
|
|
|
|
53
|
|
|
$tenantId = $processDefinition->getTenantId(); |
|
54
|
|
|
|
|
55
|
|
|
$scope = $this; |
|
56
|
|
|
return (new BatchBuilder($commandContext)) |
|
57
|
|
|
->type(BatchInterface::TYPE_PROCESS_INSTANCE_RESTART) |
|
58
|
|
|
->config(getConfiguration($collectedInstanceIds, $processDefinition->getDeploymentId())) |
|
|
|
|
|
|
59
|
|
|
->permission(BatchPermissions::createBatchRestartProcessInstances()) |
|
60
|
|
|
->tenantId($tenantId) |
|
|
|
|
|
|
61
|
|
|
->operationLogHandler(new class ($scope, $processDefinition) implements OperationLogInstanceCountHandlerInterface { |
|
62
|
|
|
private $scope; |
|
63
|
|
|
private $processDefinition; |
|
64
|
|
|
|
|
65
|
|
|
public function __construct($scope, $processDefinition) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->scope = $scope; |
|
68
|
|
|
$this->processDefinition = $processDefinition; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function write(CommandContext $commandContext, int $instanceCount): void |
|
72
|
|
|
{ |
|
73
|
|
|
$op = $this->scope->writeUserOperationLog; |
|
74
|
|
|
$op($commandContext, $this->processDefinition, $instanceCount, true); |
|
75
|
|
|
} |
|
76
|
|
|
}) |
|
77
|
|
|
->build(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function ensureTenantAuthorized(CommandContext $commandContext, ProcessDefinitionEntity $processDefinition): void |
|
81
|
|
|
{ |
|
82
|
|
|
if (!$commandContext->getTenantManager()->isAuthenticatedTenant($processDefinition->getTenantId())) { |
|
83
|
|
|
//throw LOG.exceptionCommandWithUnauthorizedTenant("restart process instances of process definition '" + processDefinition.getId() + "'"); |
|
84
|
|
|
throw new \Exception("restart process instances of process definition '" . $processDefinition->getId() . "'"); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getConfiguration(array $instanceIds, string $deploymentId): BatchConfiguration |
|
89
|
|
|
{ |
|
90
|
|
|
return new RestartProcessInstancesBatchConfiguration( |
|
91
|
|
|
$instanceIds, |
|
92
|
|
|
DeploymentMappings::of(new DeploymentMapping($deploymentId, count($instanceIds))), |
|
93
|
|
|
$this->builder->getInstructions(), |
|
94
|
|
|
$this->builder->getProcessDefinitionId(), |
|
95
|
|
|
$this->builder->isInitialVariables(), |
|
96
|
|
|
$this->builder->isSkipCustomListeners(), |
|
97
|
|
|
$this->builder->isSkipIoMappings(), |
|
98
|
|
|
$this->builder->isWithoutBusinessKey() |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|