Skip to content

Commit d3551d6

Browse files
authored
Merge pull request #62 from Flowpack/feature/neos-9
!!! FEATURE: Neos 9.0 compatibility
2 parents a05b8ae + b2a93a5 commit d3551d6

File tree

12 files changed

+162
-389
lines changed

12 files changed

+162
-389
lines changed

Classes/Aspects/ContentCacheAspect.php

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,31 @@
33

44
namespace Flowpack\Varnish\Aspects;
55

6-
use Flowpack\Varnish\Service\CacheTagService;
76
use Flowpack\Varnish\Service\VarnishBanService;
87
use Neos\Flow\Annotations as Flow;
98
use Neos\Flow\Aop\JoinPointInterface;
109
use Neos\Flow\Configuration\Exception\InvalidConfigurationException;
1110
use Neos\Flow\Log\Utility\LogEnvironment;
1211
use Neos\Flow\Mvc\Exception\StopActionException;
12+
use Neos\Fusion\Core\Runtime;
1313
use Neos\Fusion\Exception;
1414
use Neos\Fusion\Exception\RuntimeException;
1515
use Neos\Utility\Exception\PropertyNotAccessibleException;
1616
use Neos\Utility\ObjectAccess;
17-
use Neos\Fusion\Core\Runtime;
1817
use Psr\Log\LoggerInterface;
1918

2019
/**
2120
* Advice the RuntimeContentCache to check for uncached segments that should prevent caching
22-
*
23-
* @Flow\Aspect
24-
* @Flow\Scope("singleton")
2521
*/
22+
#[Flow\Aspect]
23+
#[Flow\Scope("singleton")]
2624
class ContentCacheAspect
2725
{
26+
#[Flow\Inject]
27+
protected LoggerInterface $logger;
2828

29-
/**
30-
* @Flow\Inject
31-
* @var LoggerInterface
32-
*/
33-
protected $logger;
34-
35-
/**
36-
* @Flow\Inject
37-
* @var VarnishBanService
38-
*/
39-
protected $varnishBanService;
40-
41-
/**
42-
* @Flow\Inject
43-
* @var CacheTagService
44-
*/
45-
protected $cacheTagService;
29+
#[Flow\Inject]
30+
protected VarnishBanService $varnishBanService;
4631

4732
/**
4833
* @var bool
@@ -53,7 +38,6 @@ class ContentCacheAspect
5338
* Advice for uncached segments when rendering the initial output (without replacing an uncached marker in cached output)
5439
*
5540
* @Flow\AfterReturning("setting(Flowpack.Varnish.enabled) && method(Neos\Fusion\Core\Cache\RuntimeContentCache->postProcess())")
56-
* @param JoinPointInterface $joinPoint
5741
* @throws PropertyNotAccessibleException
5842
* @throws InvalidConfigurationException
5943
* @throws StopActionException
@@ -82,7 +66,6 @@ public function registerCreateUncached(JoinPointInterface $joinPoint): void
8266
* Advice for uncached segments when rendering from a cached version
8367
*
8468
* @Flow\AfterReturning("setting(Flowpack.Varnish.enabled) && method(Neos\Fusion\Core\Cache\RuntimeContentCache->evaluateUncached())")
85-
* @param JoinPointInterface $joinPoint
8669
* @throws PropertyNotAccessibleException
8770
* @throws InvalidConfigurationException
8871
* @throws StopActionException
@@ -109,7 +92,6 @@ public function registerEvaluateUncached(JoinPointInterface $joinPoint): void
10992
* Advice for a disabled content cache (e.g. because an exception was handled)
11093
*
11194
* @Flow\AfterReturning("setting(Flowpack.Varnish.enabled) && method(Neos\Fusion\Core\Cache\RuntimeContentCache->setEnableContentCache())")
112-
* @param JoinPointInterface $joinPoint
11395
*/
11496
public function registerDisableContentCache(JoinPointInterface $joinPoint): void
11597
{
@@ -121,17 +103,15 @@ public function registerDisableContentCache(JoinPointInterface $joinPoint): void
121103
}
122104

123105
/**
124-
* @Flow\Before("setting(Flowpack.Varnish.enabled) && method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->shutdownObject())")
125-
* @param JoinPointInterface $joinPoint
106+
* @Flow\Before("setting(Flowpack.Varnish.enabled) && method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->flushTagsImmediately())")
126107
*
127108
* @throws PropertyNotAccessibleException
128109
*/
129-
public function interceptContentCacheFlush(JoinPointInterface $joinPoint)
110+
public function interceptContentCacheFlush(JoinPointInterface $joinPoint): void
130111
{
131-
$object = $joinPoint->getProxy();
132-
$tags = array_keys(ObjectAccess::getProperty($object, 'tagsToFlush', true));
112+
$tags = array_keys($joinPoint->getMethodArgument('tagsToFlush'));
133113
if ($tags === []) {
134-
return;
114+
return;
135115
}
136116

137117
$this->varnishBanService->banByTags($tags);

Classes/Controller/VarnishCacheController.php

Lines changed: 67 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,24 @@
55

66
use Flowpack\Varnish\Service\ContentCacheFlusherService;
77
use 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;
1014
use Neos\Flow\Annotations as Flow;
11-
use Neos\Error\Messages\Message;
1215
use Neos\Flow\Http\Client\CurlEngine;
1316
use Neos\Flow\Mvc\View\JsonView;
1417
use Neos\FluidAdaptor\View\TemplateView;
1518
use Neos\Neos\Controller\Module\AbstractModuleController;
1619
use Neos\Neos\Domain\Model\Domain;
1720
use Neos\Neos\Domain\Model\Site;
1821
use 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

2424
class 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

Comments
 (0)