Skip to content
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

DRAFT: Neos9 compatibility #18

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
191 changes: 0 additions & 191 deletions Classes/Command/NodeRepairCommand.php

This file was deleted.

83 changes: 60 additions & 23 deletions Classes/Command/SearchCommand.php
Expand Up @@ -13,12 +13,30 @@
* source code.
*/

use Neos\ContentRepository\Domain\Model\NodeInterface;
use GuzzleHttp\Psr7\Uri;
use http\Env\Request;
use http\Message;
use Neos\Cache\Exception;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter;
use Neos\Flow\Mvc\Routing\Dto\ResolveContext;
use Neos\Flow\Mvc\Routing\Dto\RouteParameters;
use Neos\Neos\FrontendRouting\EventSourcedFrontendNodeRoutePartHandler;
use Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder;
use ProxyManager\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentSubgraph;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cache\CacheManager;
use Neos\Flow\I18n\Translator;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Neos\Domain\Service\NodeSearchServiceInterface;
use Neos\Neos\Service\LinkingService;
use Shel\Neos\Terminal\Domain\CommandContext;
use Shel\Neos\Terminal\Domain\CommandInvocationResult;
Expand Down Expand Up @@ -51,9 +69,15 @@ class SearchCommand implements TerminalCommandInterface

/**
* @Flow\Inject
* @var NodeSearchServiceInterface
* @var ContentRepositoryRegistry
*/
protected $nodeSearchService;
protected $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var EventSourcedFrontendNodeRoutePartHandler
*/
protected $frontendNodeRoutePartHandler;

public static function getCommandName(): string
{
Expand Down Expand Up @@ -112,29 +136,41 @@ public function invokeCommand(string $argument, CommandContext $commandContext):
'Shel.Neos.Terminal'));
}

// The NodeSearchInterface does not yet have a 4th argument for the startingPoint but all known implementations do
$nodes = $this->nodeSearchService->findByProperties(
$input->getArgument('searchword'),
$input->getOption('nodeTypes'),
$contextNode->getContext(),
$contextNode
/** @var ContentSubgraph $subgraph */
$subgraph = $this->contentRepositoryRegistry->subgraphForNode(($contextNode));

try{
$searchedNodeTypes = $input->getArgument('nodeTypes');
}catch (InvalidArgumentException $e){
$searchedNodeTypes = null;
}

$nodes = iterator_to_array($subgraph->findDescendantNodes(
$contextNode->nodeAggregateId,
FindDescendantNodesFilter::create(nodeTypes: $searchedNodeTypes, searchTerm: $input->getArgument('searchword')))
);

$results = array_map(function ($node) use ($documentNode, $commandContext) {
$breadcrumbs = [];
$parent = $node->getParent();
while ($parent) {
if ($parent->getNodeType()->isOfType('Neos.Neos:Document')) {
$breadcrumbs[] = $parent->getLabel();
}
$parent = $parent->getParent();
// todo get live uri
// probably use UriBuilder Packages/Framework/Neos.Flow/Classes/Mvc/Routing/UriBuilder.php
//$documentUriPathFinder = $this->contentRepositoryRegistry->projectionState(DocumentUriPathFinder::class);
//$documentUriPathFinder-> getLiveContentStreamId
//or
// DynamicRoutePart::resolveWithParameters

$results = array_map(function ($node) use ($documentNode, $commandContext, $subgraph, $contextNode) {

try{
$nodePath = $subgraph->retrieveNodePath($node->nodeAggregateId);
}catch(\InvalidArgumentException $e){
$nodePath = "NodePath could not be retrieved: $e";
}

return [
'label' => $node->getLabel(),
'nodeType' => $node->getNodeType()->getName(),
'breadcrumb' => implode(' / ', array_reverse($breadcrumbs)),
'nodeType' => $node->nodeTypeName,
'nodePath' => $nodePath,
'uri' => $this->getUriForNode($commandContext->getControllerContext(), $documentNode, $documentNode),
'tst' => $this->getUriForNode(ControllerContext(new Request(), new Res))
];
}, $nodes);

Expand All @@ -143,9 +179,10 @@ public function invokeCommand(string $argument, CommandContext $commandContext):

protected function getUriForNode(
ControllerContext $controllerContext,
NodeInterface $node,
NodeInterface $baseNode
): string {
Node $node,
Node $baseNode
): string
{
try {
return $this->linkingService->createNodeUri(
$controllerContext,
Expand Down
19 changes: 11 additions & 8 deletions Classes/Controller/TerminalCommandController.php
Expand Up @@ -13,7 +13,7 @@
* source code.
*/

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\I18n\Exception\IndexOutOfBoundsException;
use Neos\Flow\I18n\Exception\InvalidFormatPlaceholderException;
Expand Down Expand Up @@ -79,17 +79,20 @@ class TerminalCommandController extends ActionController

public function getCommandsAction(): void
{
if (!$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
/* TODO re-establish privilege checks when supported by NEOS 9*/
/*if (!$this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
$this->view->assign('value', ['success' => false, 'result' => []]);
return;
}
}*/

$commandNames = $this->terminalCommandService->getCommandNames();

$availableCommandNames = array_filter($commandNames, function ($commandName) {
/* TODO re-establish privilege checks when supported by NEOS 9*/
$availableCommandNames = $commandNames;
/*$availableCommandNames = array_filter($commandNames, function ($commandName) {
return $this->privilegeManager->isGranted(TerminalCommandPrivilege::class,
new TerminalCommandPrivilegeSubject($commandName));
});
});*/

$commandDefinitions = array_reduce($availableCommandNames, function (array $carry, string $commandName) {
$command = $this->terminalCommandService->getCommand($commandName);
Expand All @@ -107,9 +110,9 @@ public function getCommandsAction(): void
public function invokeCommandAction(
string $commandName,
string $argument = null,
NodeInterface $siteNode = null,
NodeInterface $documentNode = null,
NodeInterface $focusedNode = null
Node $siteNode = null,
Node $documentNode = null,
Node $focusedNode = null
): void {
$this->response->setContentType('application/json');

Expand Down