File tree Expand file tree Collapse file tree 4 files changed +46
-12
lines changed
Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Repository
Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Repository
Neos.ContentRepository.Core/Classes/Projection/ContentGraph Expand file tree Collapse file tree 4 files changed +46
-12
lines changed Original file line number Diff line number Diff line change @@ -121,10 +121,28 @@ public function findRootNodeAggregateByType(
121
121
ContentStreamId $ contentStreamId ,
122
122
NodeTypeName $ nodeTypeName
123
123
): NodeAggregate {
124
- return $ this ->findRootNodeAggregates (
124
+ $ rootNodeAggregates = $ this ->findRootNodeAggregates (
125
125
$ contentStreamId ,
126
126
FindRootNodeAggregatesFilter::nodeTypeName ($ nodeTypeName )
127
- )->first ();
127
+ );
128
+
129
+ if ($ rootNodeAggregates ->count () === 0 ) {
130
+ throw new \RuntimeException ('Root Node Aggregate not found ' );
131
+ }
132
+
133
+ if ($ rootNodeAggregates ->count () > 1 ) {
134
+ $ ids = [];
135
+ foreach ($ rootNodeAggregates as $ rootNodeAggregate ) {
136
+ $ ids [] = $ rootNodeAggregate ->nodeAggregateId ->value ;
137
+ }
138
+ throw new \RuntimeException (sprintf (
139
+ 'More than one root node aggregate of type "%s" found (IDs: %s). ' ,
140
+ $ nodeTypeName ->value ,
141
+ implode (', ' , $ ids )
142
+ ));
143
+ }
144
+
145
+ return $ rootNodeAggregates ->first ();
128
146
}
129
147
130
148
public function findRootNodeAggregates (
Original file line number Diff line number Diff line change @@ -108,10 +108,28 @@ public function findRootNodeAggregateByType(
108
108
ContentStreamId $ contentStreamId ,
109
109
NodeTypeName $ nodeTypeName
110
110
): NodeAggregate {
111
- return $ this ->findRootNodeAggregates (
111
+ $ rootNodeAggregates = $ this ->findRootNodeAggregates (
112
112
$ contentStreamId ,
113
113
FindRootNodeAggregatesFilter::nodeTypeName ($ nodeTypeName )
114
- )->first ();
114
+ );
115
+
116
+ if ($ rootNodeAggregates ->count () === 0 ) {
117
+ throw new \RuntimeException ('Root Node Aggregate not found ' );
118
+ }
119
+
120
+ if ($ rootNodeAggregates ->count () > 1 ) {
121
+ $ ids = [];
122
+ foreach ($ rootNodeAggregates as $ rootNodeAggregate ) {
123
+ $ ids [] = $ rootNodeAggregate ->nodeAggregateId ->value ;
124
+ }
125
+ throw new \RuntimeException (sprintf (
126
+ 'More than one root node aggregate of type "%s" found (IDs: %s). ' ,
127
+ $ nodeTypeName ->value ,
128
+ implode (', ' , $ ids )
129
+ ));
130
+ }
131
+
132
+ return $ rootNodeAggregates ->first ();
115
133
}
116
134
117
135
public function findRootNodeAggregates (
Original file line number Diff line number Diff line change @@ -46,8 +46,9 @@ public function getSubgraph(
46
46
): ContentSubgraphInterface ;
47
47
48
48
/**
49
- * @deprecated please use {@see findRootNodeAggregates} instead
50
- * @internal
49
+ * @api
50
+ * Throws exception if no root aggregate found, because a Content Repository needs at least
51
+ * one root node to function.
51
52
*/
52
53
public function findRootNodeAggregateByType (
53
54
ContentStreamId $ contentStreamId ,
Original file line number Diff line number Diff line change @@ -74,17 +74,14 @@ public function count(): int
74
74
}
75
75
76
76
/**
77
- * Throws exception if no root aggregate found, because a Content Repository needs at least
78
- * one root node to function.
79
- *
80
- * @return NodeAggregate
77
+ * @return NodeAggregate|null
81
78
*/
82
- public function first (): NodeAggregate
79
+ public function first (): ? NodeAggregate
83
80
{
84
81
if (count ($ this ->nodeAggregates ) > 0 ) {
85
82
$ array = $ this ->nodeAggregates ;
86
83
return reset ($ array );
87
84
}
88
- throw new \ RuntimeException ( ' Root Node Aggregate not found ' ) ;
85
+ return null ;
89
86
}
90
87
}
You can’t perform that action at this time.
0 commit comments