13
13
* source code.
14
14
*/
15
15
16
- use Neos \ContentRepository \Domain \ Model \ NodeInterface ;
17
- use Neos \ContentRepository \Domain \ Model \ NodeTemplate ;
18
- use Neos \ContentRepository \Domain \ Service \ NodeTypeManager ;
19
- use Neos \ContentRepository \Exception \ NodeException ;
20
- use Neos \ContentRepository \Exception \ NodeExistsException ;
21
- use Neos \ContentRepository \Exception \ NodeTypeNotFoundException ;
22
- use Neos \ContentRepository \Utility ;
23
- use Neos \Eel \ Exception ;
16
+ use Neos \ContentRepository \Core \ DimensionSpace \ DimensionSpacePoint ;
17
+ use Neos \ContentRepository \Core \ NodeType \ NodeTypeName ;
18
+ use Neos \ContentRepository \Core \ Projection \ ContentGraph \ Node ;
19
+ use Neos \ContentRepository \Core \ Projection \ ContentGraph \ VisibilityConstraints ;
20
+ use Neos \ContentRepository \Core \ SharedModel \ ContentRepository \ ContentRepositoryId ;
21
+ use Neos \ContentRepository \Core \ SharedModel \ Node \ NodeName ;
22
+ use Neos \ContentRepository \Core \ SharedModel \ Workspace \ WorkspaceName ;
23
+ use Neos \ContentRepositoryRegistry \ ContentRepositoryRegistry ;
24
24
use Neos \Eel \FlowQuery \FlowQuery ;
25
25
use Neos \Flow \Annotations as Flow ;
26
26
use Neos \Flow \Cli \CommandController ;
27
- use Neos \Neos \ Domain \ Service \ ContentContextFactory ;
27
+ use Neos \Rector \ ContentRepository90 \ Legacy \ LegacyContextStub ;
28
28
29
29
/**
30
30
* BlogCommand command controller for the RobertLemke.Plugin.Blog package
33
33
*/
34
34
class AtomImportCommandController extends CommandController
35
35
{
36
- /**
37
- * @Flow\Inject
38
- * @var NodeTypeManager
39
- */
40
- protected $ nodeTypeManager ;
36
+ protected Node $ blogNode ;
41
37
42
- /**
43
- * @Flow\Inject
44
- * @var ContentContextFactory
45
- */
46
- protected $ contentContextFactory ;
38
+ protected array $ tagNodes = [];
47
39
48
- /**
49
- * @var NodeInterface
50
- */
51
- protected $ blogNode ;
52
-
53
- /**
54
- * @var array
55
- */
56
- protected $ tagNodes = [];
40
+ #[Flow \Inject]
41
+ protected ContentRepositoryRegistry $ contentRepositoryRegistry ;
57
42
58
43
/**
59
44
* Imports atom data into the blog
@@ -62,10 +47,6 @@ class AtomImportCommandController extends CommandController
62
47
* @param string $targetNode The target node (expressed as a FlowQuery find condition)
63
48
* @param string $atomFile The atom file to import
64
49
* @return void
65
- * @throws NodeException
66
- * @throws NodeExistsException
67
- * @throws NodeTypeNotFoundException
68
- * @throws Exception
69
50
*/
70
51
public function migrateCommand (string $ workspace , string $ targetNode , string $ atomFile ): void
71
52
{
@@ -74,10 +55,15 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
74
55
$ this ->quit (1 );
75
56
}
76
57
77
- $ context = $ this ->contentContextFactory ->create (['workspaceName ' => $ workspace ]);
78
- $ q = new FlowQuery ([$ context ->getRootNode ()]);
58
+ $ context = new LegacyContextStub (['workspaceName ' => $ workspace ]);
59
+ // TODO 9.0 migration: !! MEGA DIRTY CODE! Ensure to rewrite this; by getting rid of LegacyContextStub.
60
+ $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ('default ' ));
61
+ $ workspace = $ contentRepository ->findWorkspaceByName (WorkspaceName::fromString ('live ' ));
62
+ $ rootNodeAggregate = $ contentRepository ->getContentGraph ($ workspace ->workspaceName )->findRootNodeAggregateByType (NodeTypeName::fromString ('Neos.Neos:Sites ' ));
63
+ $ subgraph = $ contentRepository ->getContentGraph ($ workspace ->workspaceName )->getSubgraph (DimensionSpacePoint::fromLegacyDimensionArray ($ context ->dimensions ?? []), $ context ->invisibleContentShown ? VisibilityConstraints::withoutRestrictions () : VisibilityConstraints::default ());
64
+ $ q = new FlowQuery ([$ subgraph ->findNodeById ($ rootNodeAggregate ->nodeAggregateId )]);
79
65
$ this ->blogNode = $ q ->find ($ targetNode )->get (0 );
80
- if (!($ this ->blogNode instanceof NodeInterface )) {
66
+ if (!($ this ->blogNode instanceof Node )) {
81
67
$ this ->outputLine ('<error>Target node not found.</error> ' );
82
68
$ this ->quit (1 );
83
69
}
@@ -93,15 +79,15 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
93
79
$ items = $ parser ->get_items ();
94
80
95
81
$ comments = [];
96
- /** @var $item \SimplePie_Item */
82
+ /** @var \SimplePie_Item $item */
97
83
foreach ($ items as $ item ) {
98
84
$ categories = $ item ->get_categories ();
99
85
100
86
if (!is_array ($ categories )) {
101
87
continue ;
102
88
}
103
89
104
- /** @var $category \SimplePie_Category */
90
+ /** @var \SimplePie_Category $category */
105
91
foreach ($ categories as $ category ) {
106
92
if ($ category ->get_term () === 'http://schemas.google.com/blogger/2008/kind#comment ' ) {
107
93
$ inReplyTo = current ($ item ->get_item_tags ('http://purl.org/syndication/thread/1.0 ' , 'in-reply-to ' ));
@@ -110,9 +96,10 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
110
96
}
111
97
}
112
98
}
99
+ $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ('default ' ));
113
100
114
- $ textNodeType = $ this -> nodeTypeManager ->getNodeType ('Neos.NodeTypes:Text ' );
115
- $ commentNodeType = $ this -> nodeTypeManager ->getNodeType ('RobertLemke.Plugin.Blog:Content.Comment ' );
101
+ $ textNodeType = $ contentRepository -> getNodeTypeManager () ->getNodeType ('Neos.NodeTypes:Text ' );
102
+ $ commentNodeType = $ contentRepository -> getNodeTypeManager () ->getNodeType ('RobertLemke.Plugin.Blog:Content.Comment ' );
116
103
$ counter = 0 ;
117
104
foreach ($ parser ->get_items () as $ item ) {
118
105
$ categories = $ item ->get_categories ();
@@ -134,8 +121,9 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
134
121
continue ;
135
122
}
136
123
124
+ // TODO 9.0 migration: !! NodeTemplate is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions.
137
125
$ nodeTemplate = new NodeTemplate ();
138
- $ nodeTemplate ->setNodeType ($ this -> nodeTypeManager ->getNodeType ('RobertLemke.Plugin.Blog:Document.Post ' ));
126
+ $ nodeTemplate ->setNodeType ($ contentRepository -> getNodeTypeManager () ->getNodeType ('RobertLemke.Plugin.Blog:Document.Post ' ));
139
127
$ nodeTemplate ->setProperty ('title ' , $ item ->get_title ());
140
128
$ nodeTemplate ->setProperty ('author ' , $ item ->get_author ()->get_name ());
141
129
$ published = new \DateTime ();
@@ -144,15 +132,15 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
144
132
$ nodeTemplate ->setProperty ('tags ' , $ this ->getTagNodes ($ tags ));
145
133
146
134
$ slug = strtolower (str_replace ([' ' , ', ' , ': ' , 'ü ' , 'à ' , 'é ' , '? ' , '! ' , '[ ' , '] ' , '. ' , '\'' ], ['- ' , '' , '' , 'u ' , 'a ' , 'e ' , '' , '' , '' , '' , '- ' , '' ], $ item ->get_title ()));
147
- /** @var NodeInterface $postNode */
135
+ /** @var Node $postNode */
148
136
$ postNode = $ this ->blogNode ->createNodeFromTemplate ($ nodeTemplate , $ slug );
149
137
$ postNode ->getNode ('main ' )->createNode (uniqid ('node ' ), $ textNodeType )->setProperty ('text ' , $ item ->get_content ());
150
138
151
139
$ postComments = $ comments [$ item ->get_id ()] ?? [];
152
140
if ($ postComments !== []) {
153
- /** @var NodeInterface $commentsNode */
141
+ /** @var Node $commentsNode */
154
142
$ commentsNode = $ postNode ->getNode ('comments ' );
155
- /** @var $postComment \SimplePie_Item */
143
+ /** @var \SimplePie_Item $postComment */
156
144
foreach ($ postComments as $ postComment ) {
157
145
$ commentNode = $ commentsNode ->createNode (uniqid ('comment- ' , true ), $ commentNodeType );
158
146
$ commentNode ->setProperty ('author ' , html_entity_decode ($ postComment ->get_author ()->get_name (), ENT_QUOTES , 'utf-8 ' ));
@@ -164,9 +152,7 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
164
152
$ commentNode ->setProperty ('text ' , $ commentText );
165
153
$ commentNode ->setProperty ('spam ' , false );
166
154
$ previousCommentNode = $ commentNode ;
167
- if ($ previousCommentNode !== null ) {
168
- $ commentNode ->moveAfter ($ previousCommentNode );
169
- }
155
+ $ commentNode ->moveAfter ($ previousCommentNode );
170
156
}
171
157
}
172
158
@@ -179,19 +165,18 @@ public function migrateCommand(string $workspace, string $targetNode, string $at
179
165
180
166
/**
181
167
* @param array $tags
182
- * @return array<NodeInterface>
183
- * @throws NodeExistsException
184
- * @throws NodeTypeNotFoundException
168
+ * @return array<Node>
185
169
*/
186
170
protected function getTagNodes (array $ tags ): array
187
171
{
188
172
$ tagNodes = [];
189
173
190
174
foreach ($ tags as $ tag ) {
191
175
if (!isset ($ this ->tagNodes [$ tag ])) {
192
- $ tagNodeType = $ this ->nodeTypeManager ->getNodeType ('RobertLemke.Plugin.Blog:Document.Tag ' );
176
+ $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ('default ' ));
177
+ $ tagNodeType = $ contentRepository ->getNodeTypeManager ()->getNodeType ('RobertLemke.Plugin.Blog:Document.Tag ' );
193
178
194
- $ tagNode = $ this ->blogNode ->createNode (Utility:: renderValidNodeName ($ tag ), $ tagNodeType );
179
+ $ tagNode = $ this ->blogNode ->createNode (NodeName:: fromString ($ tag )-> value , $ tagNodeType );
195
180
$ tagNode ->setProperty ('title ' , $ tag );
196
181
$ this ->tagNodes [$ tag ] = $ tagNode ;
197
182
}
0 commit comments