-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
!!! FEATURE: Neos 9.0 compatibility #62
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,55 +5,24 @@ | |
|
||
use Flowpack\Varnish\Service\ContentCacheFlusherService; | ||
use Flowpack\Varnish\Service\VarnishBanService; | ||
use Neos\ContentRepository\Domain\Model\Node; | ||
use Neos\ContentRepository\Domain\Service\NodeTypeManager; | ||
use Neos\ContentRepository\Core\NodeType\NodeTypeNames; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria; | ||
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; | ||
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; | ||
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Error\Messages\Message; | ||
use Neos\Flow\Http\Client\CurlEngine; | ||
use Neos\Flow\Mvc\View\JsonView; | ||
use Neos\FluidAdaptor\View\TemplateView; | ||
use Neos\Neos\Controller\Module\AbstractModuleController; | ||
use Neos\Neos\Domain\Model\Domain; | ||
use Neos\Neos\Domain\Model\Site; | ||
use Neos\Neos\Domain\Repository\SiteRepository; | ||
use Neos\Neos\Domain\Service\ContentContext; | ||
use Neos\Neos\Domain\Service\ContentContextFactory; | ||
use Neos\Neos\Domain\Service\ContentDimensionPresetSourceInterface; | ||
use Neos\Neos\Domain\Service\NodeSearchService; | ||
use Neos\Neos\Domain\Service\SiteNodeUtility; | ||
|
||
class VarnishCacheController extends AbstractModuleController | ||
{ | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var NodeTypeManager | ||
*/ | ||
protected $nodeTypeManager; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var ContentContextFactory | ||
*/ | ||
protected $contextFactory; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var NodeSearchService | ||
*/ | ||
protected $nodeSearchService; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var SiteRepository | ||
*/ | ||
protected $siteRepository; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var ContentDimensionPresetSourceInterface | ||
*/ | ||
protected $contentDimensionPresetSource; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
|
@@ -62,6 +31,18 @@ class VarnishCacheController extends AbstractModuleController | |
'json' => JsonView::class, | ||
]; | ||
|
||
#[Flow\Inject] | ||
protected SiteRepository $siteRepository; | ||
|
||
#[Flow\Inject] | ||
protected ContentRepositoryRegistry $contentRepositoryRegistry; | ||
|
||
#[Flow\Inject] | ||
protected SiteNodeUtility $siteNodeUtility; | ||
|
||
#[Flow\Inject] | ||
protected ContentCacheFlusherService $contentCacheFlusherService; | ||
Comment on lines
+34
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here: lazy => eager There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, didn't know that. Any way to use PHP Attributes and lazy injecton? Does it matter in these cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think that's possible. |
||
|
||
public function indexAction(): void | ||
{ | ||
$this->view->assign('activeSites', $this->siteRepository->findOnline()); | ||
|
@@ -71,7 +52,6 @@ public function indexAction(): void | |
* @param string $searchWord | ||
* @param Site $selectedSite | ||
* @return void | ||
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException | ||
* @throws \Neos\Flow\Mvc\Exception\ForwardException | ||
*/ | ||
public function searchForNodeAction(string $searchWord = '', Site $selectedSite = null): void | ||
|
@@ -81,38 +61,53 @@ public function searchForNodeAction(string $searchWord = '', Site $selectedSite | |
$this->forward('index'); | ||
} | ||
|
||
$documentNodeTypes = $this->nodeTypeManager->getSubNodeTypes('Neos.Neos:Document'); | ||
$shortcutNodeType = $this->nodeTypeManager->getNodeType('Neos.Neos:Shortcut'); | ||
$nodeTypes = array_diff($documentNodeTypes, array($shortcutNodeType)); | ||
$sites = []; | ||
$activeSites = $this->siteRepository->findOnline(); | ||
foreach ($selectedSite ? [$selectedSite] : $activeSites as $site) { | ||
/** @var Site $site */ | ||
$contextProperties = [ | ||
'workspaceName' => 'live', | ||
'currentSite' => $site | ||
]; | ||
$contentDimensionPresets = $this->contentDimensionPresetSource->getAllPresets(); | ||
if (count($contentDimensionPresets) > 0) { | ||
$mergedContentDimensions = []; | ||
foreach ($contentDimensionPresets as $contentDimensionIdentifier => $contentDimension) { | ||
$mergedContentDimensions[$contentDimensionIdentifier] = [$contentDimension['default']]; | ||
foreach ($contentDimension['presets'] as $contentDimensionPreset) { | ||
$mergedContentDimensions[$contentDimensionIdentifier] = array_merge($mergedContentDimensions[$contentDimensionIdentifier], $contentDimensionPreset['values']); | ||
} | ||
$mergedContentDimensions[$contentDimensionIdentifier] = array_values(array_unique($mergedContentDimensions[$contentDimensionIdentifier])); | ||
$contentRepository = $this->contentRepositoryRegistry->get($site->getConfiguration()->contentRepositoryId); | ||
$nodeTypeManager = $contentRepository->getNodeTypeManager(); | ||
|
||
$documentNodeTypes = $nodeTypeManager->getSubNodeTypes('Neos.Neos:Document'); | ||
$shortcutNodeType = $nodeTypeManager->getNodeType('Neos.Neos:Shortcut'); | ||
|
||
$nodes = []; | ||
|
||
$contentDimensionSpacePoints = $contentRepository->getVariationGraph()->getDimensionSpacePoints(); | ||
foreach ($contentDimensionSpacePoints as $contentDimensionSpacePoint) { | ||
$currentSiteNode = $this->siteNodeUtility->findSiteNodeBySite( | ||
$site, | ||
WorkspaceName::forLive(), | ||
$contentDimensionSpacePoint | ||
); | ||
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($currentSiteNode); | ||
|
||
$descendantNodes = $subgraph->findDescendantNodes( | ||
$currentSiteNode->aggregateId, | ||
filter: FindDescendantNodesFilter::create( | ||
nodeTypes: NodeTypeCriteria::create( | ||
NodeTypeNames::fromArray(array_map(static fn ($documentNodeType) => $documentNodeType->name, $documentNodeTypes)), | ||
NodeTypeNames::fromArray([$shortcutNodeType->name])), | ||
searchTerm: $searchWord) | ||
); | ||
|
||
|
||
if ($descendantNodes->count()) { | ||
$nodes[] = array_map(fn ($node) => [ | ||
'node' => $node, | ||
'nodeAddress' => NodeAddress::fromNode($node)->toJson(), | ||
'nodeTypeIcon' => $nodeTypeManager->getNodeType($node->nodeTypeName)->getConfiguration('ui.icon'), | ||
'nodeTypeLabel' => $nodeTypeManager->getNodeType($node->nodeTypeName)->getLabel(), | ||
], iterator_to_array($descendantNodes->getIterator())); | ||
} | ||
$contextProperties['dimensions'] = $mergedContentDimensions; | ||
} | ||
/** @var ContentContext $liveContext */ | ||
$liveContext = $this->contextFactory->create($contextProperties); | ||
$nodes = $this->nodeSearchService->findByProperties($searchWord, $nodeTypes, $liveContext, $liveContext->getCurrentSiteNode()); | ||
|
||
if (count($nodes) > 0) { | ||
$sites[$site->getNodeName()] = [ | ||
$sites[$site->getNodeName()->value] = [ | ||
'site' => $site, | ||
'nodes' => $nodes | ||
'nodes' => array_merge(...$nodes) | ||
]; | ||
} | ||
|
||
} | ||
$this->view->assignMultiple([ | ||
'searchWord' => $searchWord, | ||
|
@@ -122,22 +117,19 @@ public function searchForNodeAction(string $searchWord = '', Site $selectedSite | |
]); | ||
} | ||
|
||
/** | ||
* @param Node $node | ||
* @return void | ||
* @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException | ||
*/ | ||
public function purgeCacheAction(Node $node): void | ||
public function purgeCacheAction(string $nodeAddress): void | ||
{ | ||
$service = new ContentCacheFlusherService(); | ||
$service->flushForNode($node); | ||
$nodeAddress = NodeAddress::fromJsonString($nodeAddress); | ||
$contentRepository = $this->contentRepositoryRegistry->get($nodeAddress->contentRepositoryId); | ||
$subgraph = $contentRepository->getContentSubgraph($nodeAddress->workspaceName, $nodeAddress->dimensionSpacePoint); | ||
$node = $subgraph->findNodeById($nodeAddress->aggregateId); | ||
|
||
$this->contentCacheFlusherService->flushForNode($node); | ||
|
||
$this->view->assign('value', true); | ||
} | ||
|
||
/** | ||
* @param string $tags | ||
* @param Site $site | ||
* @return void | ||
* @throws \Neos\Flow\Mvc\Exception\StopActionException | ||
*/ | ||
public function purgeCacheByTagsAction(string $tags, Site $site = null): void | ||
|
@@ -157,9 +149,6 @@ public function purgeCacheByTagsAction(string $tags, Site $site = null): void | |
} | ||
|
||
/** | ||
* @param Site $site | ||
* @param string $contentType | ||
* @return void | ||
* @throws \Neos\Flow\Mvc\Exception\StopActionException | ||
*/ | ||
public function purgeAllVarnishCacheAction(Site $site = null, $contentType = null): void | ||
|
@@ -177,8 +166,6 @@ public function purgeAllVarnishCacheAction(Site $site = null, $contentType = nul | |
} | ||
|
||
/** | ||
* @param string $url | ||
* @return void | ||
* @throws \Neos\Flow\Http\Client\CurlEngineException | ||
* @throws \Neos\Flow\Http\Exception | ||
*/ | ||
|
@@ -194,13 +181,13 @@ public function checkUrlAction(string $url): void | |
$engine->setOption(CURLOPT_SSL_VERIFYPEER, false); | ||
$engine->setOption(CURLOPT_SSL_VERIFYHOST, false); | ||
$response = $engine->sendRequest($request); | ||
$this->view->assign('value', array( | ||
$this->view->assign('value', [ | ||
'statusCode' => $response->getStatusCode(), | ||
'host' => parse_url($url, PHP_URL_HOST), | ||
'url' => $url, | ||
'headers' => array_map(function ($value) { | ||
return current($value); | ||
}, $response->getHeaders()) | ||
)); | ||
]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a FYI: This changes the behavior slightly because previously the injections were lazy