-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentReleaseMetadata.php
More file actions
175 lines (145 loc) · 5.99 KB
/
ContentReleaseMetadata.php
File metadata and controls
175 lines (145 loc) · 5.99 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
declare(strict_types=1);
namespace Flowpack\DecoupledContentStore\PrepareContentRelease\Dto;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\PrunnerJobId;
use Flowpack\DecoupledContentStore\NodeRendering\Dto\NodeRenderingCompletionStatus;
use Neos\Flow\Annotations as Flow;
/**
* @Flow\Proxy(false)
*/
final class ContentReleaseMetadata implements \JsonSerializable
{
private PrunnerJobId $prunnerJobId;
/**
* @var \DateTimeInterface|null
*/
private $startTime;
/**
* @var \DateTimeInterface|null
*/
private $endTime;
/**
* @var \DateTimeInterface|null
*/
private $switchTime;
/**
* @var PrunnerJobId[]
*/
private $manualTransferJobIds;
private NodeRenderingCompletionStatus $status;
private ?string $workspaceName;
private ?string $accountId;
private function __construct(
PrunnerJobId $prunnerJobId,
?\DateTimeInterface $startTime,
?\DateTimeInterface $endTime,
?\DateTimeInterface $switchTime,
?NodeRenderingCompletionStatus $status,
?array $manualTransferJobIds = [],
string $workspaceName = 'live',
?string $accountId = 'cli'
)
{
$this->prunnerJobId = $prunnerJobId;
$this->startTime = $startTime;
$this->endTime = $endTime;
$this->switchTime = $switchTime;
$this->status = $status ?: NodeRenderingCompletionStatus::scheduled();
$this->manualTransferJobIds = $manualTransferJobIds;
$this->workspaceName = $workspaceName;
$this->accountId = $accountId;
}
public static function create(PrunnerJobId $prunnerJobId, \DateTimeInterface $startTime, string $workspace = 'live', string $accountId = 'cli'): self
{
return new self($prunnerJobId, $startTime, null, null, NodeRenderingCompletionStatus::scheduled(), [], $workspace, $accountId);
}
public static function fromJsonString($metadataEncoded, ContentReleaseIdentifier $contentReleaseIdentifier): self
{
if (!is_string($metadataEncoded)) {
throw new \Exception('Metadata is no string for ' . $contentReleaseIdentifier->getIdentifier());
}
$tmp = json_decode($metadataEncoded, true);
if (!is_array($tmp)) {
throw new \Exception('ContentReleaseMetadata cannot be constructed from: ' . $metadataEncoded);
}
return new self(
PrunnerJobId::fromString($tmp['prunnerJobId']),
($tmp['startTime'] !== null) ? \DateTimeImmutable::createFromFormat(\DateTime::RFC3339_EXTENDED, $tmp['startTime']) : null,
($tmp['endTime'] !== null) ? \DateTimeImmutable::createFromFormat(\DateTime::RFC3339_EXTENDED, $tmp['endTime']) : null,
($tmp['switchTime'] !== null) ? \DateTimeImmutable::createFromFormat(\DateTime::RFC3339_EXTENDED, $tmp['switchTime']) : null,
NodeRenderingCompletionStatus::fromString($tmp['status']),
isset($tmp['manualTransferJobIds']) ? array_map(function (string $item) {
return PrunnerJobId::fromString($item);
}, json_decode($tmp['manualTransferJobIds'])) : [],
$tmp['workspaceName'] ?? 'live',
key_exists('accountId', $tmp) ? $tmp['accountId'] : 'cli',
);
}
public function jsonSerialize(): array
{
return [
'prunnerJobId' => $this->prunnerJobId->getIdentifier(),
'startTime' => $this->startTime ? $this->startTime->format(\DateTime::RFC3339_EXTENDED) : null,
'endTime' => $this->endTime ? $this->endTime->format(\DateTime::RFC3339_EXTENDED) : null,
'switchTime' => $this->switchTime ? $this->switchTime->format(\DateTime::RFC3339_EXTENDED) : null,
'status' => $this->status,
'manualTransferJobIds' => json_encode($this->manualTransferJobIds),
'workspaceName' => $this->workspaceName,
'accountId' => $this->accountId,
];
}
public function withEndTime(\DateTimeInterface $endTime): self
{
return new self($this->prunnerJobId, $this->startTime, $endTime, $this->switchTime, $this->status, $this->manualTransferJobIds, $this->workspaceName, $this->accountId);
}
public function withSwitchTime(\DateTimeInterface $switchTime): self
{
return new self($this->prunnerJobId, $this->startTime, $this->endTime, $switchTime, $this->status, $this->manualTransferJobIds, $this->workspaceName, $this->accountId);
}
public function withStatus(NodeRenderingCompletionStatus $status): self
{
return new self($this->prunnerJobId, $this->startTime, $this->endTime, $this->switchTime, $status, $this->manualTransferJobIds, $this->workspaceName, $this->accountId);
}
public function withAdditionalManualTransferJobId(PrunnerJobId $prunnerJobId): self
{
$manualTransferIdArray = $this->getManualTransferJobIds();
$manualTransferIdArray[] = $prunnerJobId;
return new self($this->prunnerJobId, $this->startTime, $this->endTime, $this->switchTime, $this->status, $manualTransferIdArray, $this->workspaceName, $this->accountId);
}
public function getPrunnerJobId(): PrunnerJobId
{
return $this->prunnerJobId;
}
public function getStartTime(): ?\DateTimeInterface
{
return $this->startTime;
}
public function getEndTime(): ?\DateTimeInterface
{
return $this->endTime;
}
public function getSwitchTime(): ?\DateTimeInterface
{
return $this->switchTime;
}
public function getStatus(): NodeRenderingCompletionStatus
{
return $this->status;
}
/**
* @return PrunnerJobId[]
*/
public function getManualTransferJobIds(): ?array
{
return $this->manualTransferJobIds;
}
public function getWorkspaceName(): ?string
{
return $this->workspaceName;
}
public function getAccountId(): ?string
{
return $this->accountId;
}
}