|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\{ |
|
6
|
|
|
ProcessEngineInterface, |
|
7
|
|
|
RepositoryServiceInterface |
|
8
|
|
|
}; |
|
9
|
|
|
use Jabe\Engine\Impl\Context\Context; |
|
10
|
|
|
use Jabe\Engine\Repository\{ |
|
11
|
|
|
CandidateDeploymentInterface, |
|
12
|
|
|
DeploymentInterface, |
|
13
|
|
|
DeploymentHandlerInterface, |
|
14
|
|
|
ProcessDefinitionInterface, |
|
15
|
|
|
ResourceInterface |
|
16
|
|
|
}; |
|
17
|
|
|
|
|
18
|
|
|
class DefaultDeploymentHandler implements DeploymentHandlerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
protected $processEngine; |
|
21
|
|
|
protected $repositoryService; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(ProcessEngineInterface $processEngine) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->processEngine = $processEngine; |
|
26
|
|
|
$this->repositoryService = $processEngine->getRepositoryService(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function shouldDeployResource(ResourceInterface $newResource, ResourceInterface $existingResource): bool |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->resourcesDiffer($newResource, $existingResource); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function determineDuplicateDeployment(CandidateDeploymentInterface $candidateDeployment): string |
|
35
|
|
|
{ |
|
36
|
|
|
return Context::getCommandContext() |
|
|
|
|
|
|
37
|
|
|
->getDeploymentManager() |
|
38
|
|
|
->findLatestDeploymentByName($candidateDeployment->getName()) |
|
39
|
|
|
->getId(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function determineDeploymentsToResumeByProcessDefinitionKey(array $processDefinitionKeys): array |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
$deploymentIds = []; |
|
46
|
|
|
$processDefinitions = Context::getCommandContext()->getProcessDefinitionManager() |
|
47
|
|
|
->findProcessDefinitionsByKeyIn($processDefinitionKeys); |
|
48
|
|
|
foreach ($processDefinitions as $processDefinition) { |
|
49
|
|
|
$deploymentIds[] = $processDefinition->getDeploymentId(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return array_unique($deploymentIds); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function determineDeploymentsToResumeByDeploymentName(CandidateDeploymentInterface $candidateDeployment): array |
|
56
|
|
|
{ |
|
57
|
|
|
$previousDeployments = $processEngine->getRepositoryService() |
|
|
|
|
|
|
58
|
|
|
->createDeploymentQuery() |
|
59
|
|
|
->deploymentName($candidateDeployment->getName()) |
|
60
|
|
|
->list(); |
|
61
|
|
|
|
|
62
|
|
|
$deploymentIds = []; |
|
63
|
|
|
foreach ($previousDeployments as $deployment) { |
|
64
|
|
|
$deploymentIds[] = $deployment->getId(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return array_unique($deploymentIds); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function resourcesDiffer(ResourceInterface $resource, ResourceInterface $existing): bool |
|
71
|
|
|
{ |
|
72
|
|
|
$bytes = $resource->getBytes(); |
|
|
|
|
|
|
73
|
|
|
$savedBytes = $existing->getBytes(); |
|
74
|
|
|
return $bytes != $savedBytes; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|