-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathWorkspaceService.php
140 lines (122 loc) · 5.6 KB
/
WorkspaceService.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Neos\Neos\Ui\ContentRepository\Service;
/*
* This file is part of the Neos.Neos.Ui 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.
*/
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\PendingChangesProjection\Change;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;
/**
* @internal
* @Flow\Scope("singleton")
*/
class WorkspaceService
{
private const NODE_HAS_BEEN_CREATED = 0b0001;
private const NODE_HAS_BEEN_CHANGED = 0b0010;
private const NODE_HAS_BEEN_MOVED = 0b0100;
private const NODE_HAS_BEEN_DELETED = 0b1000;
use NodeTypeWithFallbackProvider;
#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;
#[Flow\Inject]
protected WorkspacePublishingService $workspacePublishingService;
/**
* Get all publishable node context paths for a workspace
*
* @return array{contextPath:string,documentContextPath:string,typeOfChange:int}[]
*/
public function getPublishableNodeInfo(WorkspaceName $workspaceName, ContentRepositoryId $contentRepositoryId): array
{
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$contentGraph = $contentRepository->getContentGraph($workspaceName);
$pendingChanges = $this->workspacePublishingService->pendingWorkspaceChanges($contentRepositoryId, $workspaceName);
/** @var array{contextPath:string,documentContextPath:string,typeOfChange:int}[] $unpublishedNodes */
$unpublishedNodes = [];
foreach ($pendingChanges as $change) {
if ($change->removalAttachmentPoint && $change->originDimensionSpacePoint !== null) {
$nodeAddress = NodeAddress::create(
$contentRepositoryId,
$workspaceName,
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->nodeAggregateId
);
/**
* See {@see Remove::apply} -> Removal Attachment Point == closest document node.
*/
$documentNodeAddress = NodeAddress::create(
$contentRepositoryId,
$workspaceName,
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->removalAttachmentPoint
);
$unpublishedNodes[] = [
'contextPath' => $nodeAddress->toJson(),
'documentContextPath' => $documentNodeAddress->toJson(),
'typeOfChange' => $this->getTypeOfChange($change)
];
} else {
if ($change->originDimensionSpacePoint !== null) {
$originDimensionSpacePoints = [$change->originDimensionSpacePoint];
} else {
// If originDimensionSpacePoint is null, we have a change to the nodeAggregate. All nodes in the
// occupied dimensionspacepoints shall be marked as changed.
$originDimensionSpacePoints = $contentGraph
->findNodeAggregateById($change->nodeAggregateId)
?->occupiedDimensionSpacePoints ?: [];
}
foreach ($originDimensionSpacePoints as $originDimensionSpacePoint) {
$subgraph = $contentRepository->getContentSubgraph(
$workspaceName,
$originDimensionSpacePoint->toDimensionSpacePoint(),
);
$node = $subgraph->findNodeById($change->nodeAggregateId);
if ($node instanceof Node) {
$documentNode = $subgraph->findClosestNode($node->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT));
if ($documentNode instanceof Node) {
$unpublishedNodes[] = [
'contextPath' => NodeAddress::fromNode($node)->toJson(),
'documentContextPath' => NodeAddress::fromNode($documentNode)->toJson(),
'typeOfChange' => $this->getTypeOfChange($change)
];
}
}
}
}
}
return array_values(array_filter($unpublishedNodes, function ($item) {
return (bool)$item;
}));
}
private function getTypeOfChange(Change $change): int
{
$result = 0;
if ($change->created) {
$result = $result | self::NODE_HAS_BEEN_CREATED;
}
if ($change->changed) {
$result = $result | self::NODE_HAS_BEEN_CHANGED;
}
if ($change->moved) {
$result = $result | self::NODE_HAS_BEEN_MOVED;
}
if ($change->deleted) {
$result = $result | self::NODE_HAS_BEEN_DELETED;
}
return $result;
}
}