-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathChange.php
118 lines (108 loc) · 4.62 KB
/
Change.php
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
<?php
/*
* This file is part of the Neos.ContentGraph package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
declare(strict_types=1);
namespace Neos\Neos\PendingChangesProjection;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DbalException;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Command\RemoveNodeAggregate;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Flow\Annotations as Flow;
/**
* Read model for pending changes
*
* @internal !!! Still a bit unstable - might change in the future.
* @Flow\Proxy(false)
*/
final class Change
{
public const AGGREGATE_DIMENSIONSPACEPOINT_HASH_PLACEHOLDER = 'AGGREGATE';
/**
* @param NodeAggregateId|null $removalAttachmentPoint {@see RemoveNodeAggregate::$removalAttachmentPoint} for docs
*/
public function __construct(
public ContentStreamId $contentStreamId,
public NodeAggregateId $nodeAggregateId,
// null for aggregate scoped changes (e.g. NodeAggregateNameWasChanged, NodeAggregateTypeWasChanged)
public ?OriginDimensionSpacePoint $originDimensionSpacePoint,
public bool $created,
public bool $changed,
public bool $moved,
public bool $deleted,
public ?NodeAggregateId $removalAttachmentPoint = null
) {
}
/**
* @param Connection $databaseConnection
*/
public function addToDatabase(Connection $databaseConnection, string $tableName): void
{
try {
$databaseConnection->insert($tableName, [
'contentStreamId' => $this->contentStreamId->value,
'nodeAggregateId' => $this->nodeAggregateId->value,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint?->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint?->hash ?: self::AGGREGATE_DIMENSIONSPACEPOINT_HASH_PLACEHOLDER,
'created' => (int)$this->created,
'changed' => (int)$this->changed,
'moved' => (int)$this->moved,
'deleted' => (int)$this->deleted,
'removalAttachmentPoint' => $this->removalAttachmentPoint?->value
]);
} catch (DbalException $e) {
throw new \RuntimeException(sprintf('Failed to insert Change to database: %s', $e->getMessage()), 1727272723, $e);
}
}
public function updateToDatabase(Connection $databaseConnection, string $tableName): void
{
try {
$databaseConnection->update(
$tableName,
[
'created' => (int)$this->created,
'changed' => (int)$this->changed,
'moved' => (int)$this->moved,
'deleted' => (int)$this->deleted,
'removalAttachmentPoint' => $this->removalAttachmentPoint?->value
],
[
'contentStreamId' => $this->contentStreamId->value,
'nodeAggregateId' => $this->nodeAggregateId->value,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint?->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint?->hash ?: self::AGGREGATE_DIMENSIONSPACEPOINT_HASH_PLACEHOLDER,
]
);
} catch (DbalException $e) {
throw new \RuntimeException(sprintf('Failed to update Change in database: %s', $e->getMessage()), 1727272761, $e);
}
}
/**
* @param array<string,mixed> $databaseRow
*/
public static function fromDatabaseRow(array $databaseRow): self
{
return new self(
ContentStreamId::fromString($databaseRow['contentStreamId']),
NodeAggregateId::fromString($databaseRow['nodeAggregateId']),
$databaseRow['originDimensionSpacePoint'] ?? null
? OriginDimensionSpacePoint::fromJsonString($databaseRow['originDimensionSpacePoint'])
: null,
(bool)$databaseRow['created'],
(bool)$databaseRow['changed'],
(bool)$databaseRow['moved'],
(bool)$databaseRow['deleted'],
isset($databaseRow['removalAttachmentPoint'])
? NodeAggregateId::fromString($databaseRow['removalAttachmentPoint'])
: null
);
}
}