88use Flowpack \NodeTemplates \Domain \NodeCreation \NodeCreationService ;
99use Flowpack \NodeTemplates \Domain \NodeTemplateDumper \NodeTemplateDumper ;
1010use Flowpack \NodeTemplates \Domain \TemplateConfiguration \TemplateConfigurationProcessor ;
11- use Neos \ContentRepository \Domain \Model \NodeInterface ;
12- use Neos \ContentRepository \Domain \Service \ContextFactoryInterface ;
13- use Neos \ContentRepository \Domain \Service \NodeTypeManager ;
11+ use Neos \ContentRepository \Core \Feature \NodeCreation \Command \CreateNodeAggregateWithNode ;
12+ use Neos \ContentRepository \Core \Projection \ContentGraph \AbsoluteNodePath ;
13+ use Neos \ContentRepository \Core \Projection \ContentGraph \NodePath ;
14+ use Neos \ContentRepository \Core \Projection \ContentGraph \VisibilityConstraints ;
15+ use Neos \ContentRepository \Core \SharedModel \Node \NodeAggregateId ;
16+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceName ;
17+ use Neos \ContentRepositoryRegistry \ContentRepositoryRegistry ;
1418use Neos \Flow \Annotations as Flow ;
1519use Neos \Flow \Cli \CommandController ;
16- use Neos \Neos \Domain \Service \ContentContext ;
20+ use Neos \Neos \Domain \Repository \SiteRepository ;
21+ use Neos \Neos \Domain \Service \NodeTypeNameFactory ;
22+ use Neos \Neos \Ui \Domain \NodeCreation \NodeCreationCommands ;
1723
1824class NodeTemplateCommandController extends CommandController
1925{
@@ -23,12 +29,6 @@ class NodeTemplateCommandController extends CommandController
2329 */
2430 protected $ nodeCreationService ;
2531
26- /**
27- * @Flow\Inject
28- * @var ContextFactoryInterface
29- */
30- protected $ contextFactory ;
31-
3232 /**
3333 * @Flow\Inject
3434 * @var NodeTemplateDumper
@@ -42,30 +42,52 @@ class NodeTemplateCommandController extends CommandController
4242 protected $ templateConfigurationProcessor ;
4343
4444 /**
45+ * @var SiteRepository
4546 * @Flow\Inject
46- * @var NodeTypeManager
4747 */
48- protected $ nodeTypeManager ;
48+ protected $ siteRepository ;
49+
50+ /**
51+ * @var ContentRepositoryRegistry
52+ * @Flow\Inject
53+ */
54+ protected $ contentRepositoryRegistry ;
4955
5056 /**
5157 * Dump the node tree structure into a NodeTemplate YAML structure.
5258 * References to Nodes and non-primitive property values are commented out in the YAML.
5359 *
5460 * @param string $startingNodeId specified root node of the node tree.
61+ * @param string|null $site the Neos site, which determines the content repository. Defaults to the first available one.
5562 * @param string $workspaceName custom workspace to dump from. Defaults to 'live'.
5663 * @return void
5764 */
58- public function createFromNodeSubtreeCommand (string $ startingNodeId , string $ workspaceName = 'live ' ): void
65+ public function createFromNodeSubtreeCommand (string $ startingNodeId , ? string $ site = null , string $ workspaceName = 'live ' ): void
5966 {
60- $ subgraph = $ this ->contextFactory ->create ([
61- 'workspaceName ' => $ workspaceName
62- ]);
63- /** @var ?NodeInterface $node */
64- $ node = $ subgraph ->getNodeByIdentifier ($ startingNodeId );
67+ $ siteInstance = $ site
68+ ? $ this ->siteRepository ->findOneByNodeName ($ site )
69+ : $ this ->siteRepository ->findDefault ();
70+
71+ if (!$ siteInstance ) {
72+ $ this ->outputLine (sprintf ('<error>Site "%s" does not exist.</error> ' , $ site ));
73+ $ this ->quit (2 );
74+ }
75+
76+ $ siteConfiguration = $ siteInstance ->getConfiguration ();
77+
78+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ siteConfiguration ->contentRepositoryId );
79+
80+ // default context? https://github.com/neos/neos-development-collection/issues/5113
81+ $ subgraph = $ contentRepository ->getContentGraph (WorkspaceName::fromString ($ workspaceName ))->getSubgraph (
82+ $ siteConfiguration ->defaultDimensionSpacePoint ,
83+ VisibilityConstraints::default ()
84+ );
85+
86+ $ node = $ subgraph ->findNodeById (NodeAggregateId::fromString ($ startingNodeId ));
6587 if (!$ node ) {
6688 throw new \InvalidArgumentException ("Node $ startingNodeId doesnt exist in workspace $ workspaceName. " );
6789 }
68- echo $ this ->nodeTemplateDumper ->createNodeTemplateYamlDumpFromSubtree ($ node );
90+ echo $ this ->nodeTemplateDumper ->createNodeTemplateYamlDumpFromSubtree ($ node, $ contentRepository );
6991 }
7092
7193 /**
@@ -74,25 +96,54 @@ public function createFromNodeSubtreeCommand(string $startingNodeId, string $wor
7496 *
7597 * We process and build all configured NodeType templates. No nodes will be created in the Content Repository.
7698 *
99+ * @param string|null $site the Neos site, which determines the content repository. Defaults to the first available one.
77100 */
78- public function validateCommand (): void
101+ public function validateCommand (? string $ site = null ): void
79102 {
103+ $ siteInstance = $ site
104+ ? $ this ->siteRepository ->findOneByNodeName ($ site )
105+ : $ this ->siteRepository ->findDefault ();
106+
107+ if (!$ siteInstance ) {
108+ $ this ->outputLine (sprintf ('<error>Site "%s" does not exist.</error> ' , $ site ));
109+ $ this ->quit (2 );
110+ }
111+
112+ $ siteConfiguration = $ siteInstance ->getConfiguration ();
113+
114+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ siteConfiguration ->contentRepositoryId );
115+
80116 $ templatesChecked = 0 ;
81117 /**
82118 * nodeTypeNames as index
83119 * @var array<string, array{processingErrors: ProcessingErrors, dataWasAccessed: bool}> $faultyNodeTypeTemplates
84120 */
85121 $ faultyNodeTypeTemplates = [];
86122
87- foreach ($ this ->nodeTypeManager ->getNodeTypes (false ) as $ nodeType ) {
123+ // default context? https://github.com/neos/neos-development-collection/issues/5113
124+ $ subgraph = $ contentRepository ->getContentGraph (WorkspaceName::forLive ())->getSubgraph (
125+ $ siteConfiguration ->defaultDimensionSpacePoint ,
126+ VisibilityConstraints::default ()
127+ );
128+
129+ $ sitesNode = $ subgraph ->findRootNodeByType (NodeTypeNameFactory::forSites ());
130+ $ siteNode = $ sitesNode ? $ subgraph ->findNodeByPath (
131+ $ siteInstance ->getNodeName ()->toNodeName (),
132+ $ sitesNode ->aggregateId
133+ ) : null ;
134+
135+ if (!$ siteNode ) {
136+ $ this ->outputLine (sprintf ('<error>Could not resolve site node for site "%s".</error> ' , $ siteInstance ->getNodeName ()->value ));
137+ $ this ->quit (3 );
138+ }
139+
140+ foreach ($ contentRepository ->getNodeTypeManager ()->getNodeTypes (false ) as $ nodeType ) {
88141 $ templateConfiguration = $ nodeType ->getOptions ()['template ' ] ?? null ;
89142 if (!$ templateConfiguration ) {
90143 continue ;
91144 }
92145 $ processingErrors = ProcessingErrors::create ();
93146
94- /** @var ContentContext $subgraph */
95- $ subgraph = $ this ->contextFactory ->create ();
96147
97148 $ observableEmptyData = new class ([]) extends \ArrayObject
98149 {
@@ -104,27 +155,37 @@ public function offsetExists($key): bool
104155 }
105156 };
106157
107- $ siteNode = $ subgraph ->getCurrentSiteNode ();
108-
109158 $ template = $ this ->templateConfigurationProcessor ->processTemplateConfiguration (
110159 $ templateConfiguration ,
111160 [
112161 'data ' => $ observableEmptyData ,
113- 'triggeringNode ' => $ siteNode , // @deprecated
114162 'site ' => $ siteNode ,
115163 'parentNode ' => $ siteNode ,
116164 ],
117165 $ processingErrors
118166 );
119167
120- $ this ->nodeCreationService ->createMutatorsForRootTemplate ($ template , $ nodeType , $ this ->nodeTypeManager , $ subgraph , $ processingErrors );
168+ $ fakeNodeCreationCommands = NodeCreationCommands::fromFirstCommand (
169+ CreateNodeAggregateWithNode::create (
170+ $ siteNode ->workspaceName ,
171+ NodeAggregateId::create (),
172+ $ nodeType ->name ,
173+ $ siteNode ->originDimensionSpacePoint ,
174+ $ siteNode ->aggregateId
175+ ),
176+ $ contentRepository ->getNodeTypeManager ()
177+ );
178+
179+ $ this ->nodeCreationService ->apply ($ template , $ fakeNodeCreationCommands , $ contentRepository ->getNodeTypeManager (), $ subgraph , $ nodeType , $ processingErrors );
121180
122181 if ($ processingErrors ->hasError ()) {
123- $ faultyNodeTypeTemplates [$ nodeType ->getName () ] = ['processingErrors ' => $ processingErrors , 'dataWasAccessed ' => $ observableEmptyData ->dataWasAccessed ];
182+ $ faultyNodeTypeTemplates [$ nodeType ->name -> value ] = ['processingErrors ' => $ processingErrors , 'dataWasAccessed ' => $ observableEmptyData ->dataWasAccessed ];
124183 }
125184 $ templatesChecked ++;
126185 }
127186
187+ $ this ->output (sprintf ('<comment>Content repository "%s": </comment> ' , $ contentRepository ->id ->value ));
188+
128189 if ($ templatesChecked === 0 ) {
129190 $ this ->outputLine ('<comment>No NodeType templates found.</comment> ' );
130191 return ;
0 commit comments