55
66use Flowpack \Varnish \Service \ContentCacheFlusherService ;
77use Flowpack \Varnish \Service \VarnishBanService ;
8- use Neos \ContentRepository \Domain \Model \Node ;
9- use Neos \ContentRepository \Domain \Service \NodeTypeManager ;
8+ use Neos \ContentRepository \Core \NodeType \NodeTypeNames ;
9+ use Neos \ContentRepository \Core \Projection \ContentGraph \Filter \FindDescendantNodesFilter ;
10+ use Neos \ContentRepository \Core \Projection \ContentGraph \Filter \NodeType \NodeTypeCriteria ;
11+ use Neos \ContentRepository \Core \SharedModel \Node \NodeAddress ;
12+ use Neos \ContentRepository \Core \SharedModel \Workspace \WorkspaceName ;
13+ use Neos \ContentRepositoryRegistry \ContentRepositoryRegistry ;
1014use Neos \Flow \Annotations as Flow ;
11- use Neos \Error \Messages \Message ;
1215use Neos \Flow \Http \Client \CurlEngine ;
1316use Neos \Flow \Mvc \View \JsonView ;
1417use Neos \FluidAdaptor \View \TemplateView ;
1518use Neos \Neos \Controller \Module \AbstractModuleController ;
1619use Neos \Neos \Domain \Model \Domain ;
1720use Neos \Neos \Domain \Model \Site ;
1821use Neos \Neos \Domain \Repository \SiteRepository ;
19- use Neos \Neos \Domain \Service \ContentContext ;
20- use Neos \Neos \Domain \Service \ContentContextFactory ;
21- use Neos \Neos \Domain \Service \ContentDimensionPresetSourceInterface ;
22- use Neos \Neos \Domain \Service \NodeSearchService ;
22+ use Neos \Neos \Domain \Service \SiteNodeUtility ;
2323
2424class VarnishCacheController extends AbstractModuleController
2525{
26-
27- /**
28- * @Flow\Inject
29- * @var NodeTypeManager
30- */
31- protected $ nodeTypeManager ;
32-
33- /**
34- * @Flow\Inject
35- * @var ContentContextFactory
36- */
37- protected $ contextFactory ;
38-
39- /**
40- * @Flow\Inject
41- * @var NodeSearchService
42- */
43- protected $ nodeSearchService ;
44-
45- /**
46- * @Flow\Inject
47- * @var SiteRepository
48- */
49- protected $ siteRepository ;
50-
51- /**
52- * @Flow\Inject
53- * @var ContentDimensionPresetSourceInterface
54- */
55- protected $ contentDimensionPresetSource ;
56-
5726 /**
5827 * @var array
5928 */
@@ -62,6 +31,18 @@ class VarnishCacheController extends AbstractModuleController
6231 'json ' => JsonView::class,
6332 ];
6433
34+ #[Flow \Inject]
35+ protected SiteRepository $ siteRepository ;
36+
37+ #[Flow \Inject]
38+ protected ContentRepositoryRegistry $ contentRepositoryRegistry ;
39+
40+ #[Flow \Inject]
41+ protected SiteNodeUtility $ siteNodeUtility ;
42+
43+ #[Flow \Inject]
44+ protected ContentCacheFlusherService $ contentCacheFlusherService ;
45+
6546 public function indexAction (): void
6647 {
6748 $ this ->view ->assign ('activeSites ' , $ this ->siteRepository ->findOnline ());
@@ -71,7 +52,6 @@ public function indexAction(): void
7152 * @param string $searchWord
7253 * @param Site $selectedSite
7354 * @return void
74- * @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
7555 * @throws \Neos\Flow\Mvc\Exception\ForwardException
7656 */
7757 public function searchForNodeAction (string $ searchWord = '' , Site $ selectedSite = null ): void
@@ -81,38 +61,53 @@ public function searchForNodeAction(string $searchWord = '', Site $selectedSite
8161 $ this ->forward ('index ' );
8262 }
8363
84- $ documentNodeTypes = $ this ->nodeTypeManager ->getSubNodeTypes ('Neos.Neos:Document ' );
85- $ shortcutNodeType = $ this ->nodeTypeManager ->getNodeType ('Neos.Neos:Shortcut ' );
86- $ nodeTypes = array_diff ($ documentNodeTypes , array ($ shortcutNodeType ));
8764 $ sites = [];
8865 $ activeSites = $ this ->siteRepository ->findOnline ();
8966 foreach ($ selectedSite ? [$ selectedSite ] : $ activeSites as $ site ) {
90- /** @var Site $site */
91- $ contextProperties = [
92- 'workspaceName ' => 'live ' ,
93- 'currentSite ' => $ site
94- ];
95- $ contentDimensionPresets = $ this ->contentDimensionPresetSource ->getAllPresets ();
96- if (count ($ contentDimensionPresets ) > 0 ) {
97- $ mergedContentDimensions = [];
98- foreach ($ contentDimensionPresets as $ contentDimensionIdentifier => $ contentDimension ) {
99- $ mergedContentDimensions [$ contentDimensionIdentifier ] = [$ contentDimension ['default ' ]];
100- foreach ($ contentDimension ['presets ' ] as $ contentDimensionPreset ) {
101- $ mergedContentDimensions [$ contentDimensionIdentifier ] = array_merge ($ mergedContentDimensions [$ contentDimensionIdentifier ], $ contentDimensionPreset ['values ' ]);
102- }
103- $ mergedContentDimensions [$ contentDimensionIdentifier ] = array_values (array_unique ($ mergedContentDimensions [$ contentDimensionIdentifier ]));
67+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ site ->getConfiguration ()->contentRepositoryId );
68+ $ nodeTypeManager = $ contentRepository ->getNodeTypeManager ();
69+
70+ $ documentNodeTypes = $ nodeTypeManager ->getSubNodeTypes ('Neos.Neos:Document ' );
71+ $ shortcutNodeType = $ nodeTypeManager ->getNodeType ('Neos.Neos:Shortcut ' );
72+
73+ $ nodes = [];
74+
75+ $ contentDimensionSpacePoints = $ contentRepository ->getVariationGraph ()->getDimensionSpacePoints ();
76+ foreach ($ contentDimensionSpacePoints as $ contentDimensionSpacePoint ) {
77+ $ currentSiteNode = $ this ->siteNodeUtility ->findSiteNodeBySite (
78+ $ site ,
79+ WorkspaceName::forLive (),
80+ $ contentDimensionSpacePoint
81+ );
82+ $ subgraph = $ this ->contentRepositoryRegistry ->subgraphForNode ($ currentSiteNode );
83+
84+ $ descendantNodes = $ subgraph ->findDescendantNodes (
85+ $ currentSiteNode ->aggregateId ,
86+ filter: FindDescendantNodesFilter::create (
87+ nodeTypes: NodeTypeCriteria::create (
88+ NodeTypeNames::fromArray (array_map (static fn ($ documentNodeType ) => $ documentNodeType ->name , $ documentNodeTypes )),
89+ NodeTypeNames::fromArray ([$ shortcutNodeType ->name ])),
90+ searchTerm: $ searchWord )
91+ );
92+
93+
94+ if ($ descendantNodes ->count ()) {
95+ $ nodes [] = array_map (fn ($ node ) => [
96+ 'node ' => $ node ,
97+ 'nodeAddress ' => NodeAddress::fromNode ($ node )->toJson (),
98+ 'nodeTypeIcon ' => $ nodeTypeManager ->getNodeType ($ node ->nodeTypeName )->getConfiguration ('ui.icon ' ),
99+ 'nodeTypeLabel ' => $ nodeTypeManager ->getNodeType ($ node ->nodeTypeName )->getLabel (),
100+ ], iterator_to_array ($ descendantNodes ->getIterator ()));
104101 }
105- $ contextProperties ['dimensions ' ] = $ mergedContentDimensions ;
106102 }
107- /** @var ContentContext $liveContext */
108- $ liveContext = $ this ->contextFactory ->create ($ contextProperties );
109- $ nodes = $ this ->nodeSearchService ->findByProperties ($ searchWord , $ nodeTypes , $ liveContext , $ liveContext ->getCurrentSiteNode ());
103+
110104 if (count ($ nodes ) > 0 ) {
111- $ sites [$ site ->getNodeName ()] = [
105+ $ sites [$ site ->getNodeName ()-> value ] = [
112106 'site ' => $ site ,
113- 'nodes ' => $ nodes
107+ 'nodes ' => array_merge (... $ nodes)
114108 ];
115109 }
110+
116111 }
117112 $ this ->view ->assignMultiple ([
118113 'searchWord ' => $ searchWord ,
@@ -122,22 +117,19 @@ public function searchForNodeAction(string $searchWord = '', Site $selectedSite
122117 ]);
123118 }
124119
125- /**
126- * @param Node $node
127- * @return void
128- * @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
129- */
130- public function purgeCacheAction (Node $ node ): void
120+ public function purgeCacheAction (string $ nodeAddress ): void
131121 {
132- $ service = new ContentCacheFlusherService ();
133- $ service ->flushForNode ($ node );
122+ $ nodeAddress = NodeAddress::fromJsonString ($ nodeAddress );
123+ $ contentRepository = $ this ->contentRepositoryRegistry ->get ($ nodeAddress ->contentRepositoryId );
124+ $ subgraph = $ contentRepository ->getContentSubgraph ($ nodeAddress ->workspaceName , $ nodeAddress ->dimensionSpacePoint );
125+ $ node = $ subgraph ->findNodeById ($ nodeAddress ->aggregateId );
126+
127+ $ this ->contentCacheFlusherService ->flushForNode ($ node );
128+
134129 $ this ->view ->assign ('value ' , true );
135130 }
136131
137132 /**
138- * @param string $tags
139- * @param Site $site
140- * @return void
141133 * @throws \Neos\Flow\Mvc\Exception\StopActionException
142134 */
143135 public function purgeCacheByTagsAction (string $ tags , Site $ site = null ): void
@@ -157,9 +149,6 @@ public function purgeCacheByTagsAction(string $tags, Site $site = null): void
157149 }
158150
159151 /**
160- * @param Site $site
161- * @param string $contentType
162- * @return void
163152 * @throws \Neos\Flow\Mvc\Exception\StopActionException
164153 */
165154 public function purgeAllVarnishCacheAction (Site $ site = null , $ contentType = null ): void
@@ -177,8 +166,6 @@ public function purgeAllVarnishCacheAction(Site $site = null, $contentType = nul
177166 }
178167
179168 /**
180- * @param string $url
181- * @return void
182169 * @throws \Neos\Flow\Http\Client\CurlEngineException
183170 * @throws \Neos\Flow\Http\Exception
184171 */
@@ -194,13 +181,13 @@ public function checkUrlAction(string $url): void
194181 $ engine ->setOption (CURLOPT_SSL_VERIFYPEER , false );
195182 $ engine ->setOption (CURLOPT_SSL_VERIFYHOST , false );
196183 $ response = $ engine ->sendRequest ($ request );
197- $ this ->view ->assign ('value ' , array (
184+ $ this ->view ->assign ('value ' , [
198185 'statusCode ' => $ response ->getStatusCode (),
199186 'host ' => parse_url ($ url , PHP_URL_HOST ),
200187 'url ' => $ url ,
201188 'headers ' => array_map (function ($ value ) {
202189 return current ($ value );
203190 }, $ response ->getHeaders ())
204- ) );
191+ ] );
205192 }
206193}
0 commit comments