diff --git a/Neos.ContentRepository.BehavioralTests/Classes/PhpstanRules/InternalMethodsNotAllowedOutsideContentRepositoryRule.php b/Neos.ContentRepository.BehavioralTests/Classes/PhpstanRules/InternalMethodsNotAllowedOutsideContentRepositoryRule.php index 5dae4e82dfc..4a2417de07f 100644 --- a/Neos.ContentRepository.BehavioralTests/Classes/PhpstanRules/InternalMethodsNotAllowedOutsideContentRepositoryRule.php +++ b/Neos.ContentRepository.BehavioralTests/Classes/PhpstanRules/InternalMethodsNotAllowedOutsideContentRepositoryRule.php @@ -74,7 +74,7 @@ public function processNode(Node $node, Scope $scope): array $targetClassName, $node->name->toString() ) - )->build(), + )->identifier('neos.internal')->build(), ]; } } diff --git a/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php b/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php index 6cc56c336ee..bac24262942 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php +++ b/Neos.ContentRepositoryRegistry/Classes/Command/ContentStreamCommandController.php @@ -33,6 +33,11 @@ class ContentStreamCommandController extends CommandController */ public function pruneCommand(string $contentRepository = 'default', bool $removeTemporary = false): void { + if (!$this->output->askConfirmation(sprintf('> This operation in "%s" cannot be reverted. Are you sure to proceed? (y/n) ', $contentRepository), false)) { + $this->outputLine('Abort.'); + return; + } + $contentRepositoryId = ContentRepositoryId::fromString($contentRepository); $contentStreamPruner = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentStreamPrunerFactory()); @@ -54,6 +59,11 @@ public function pruneCommand(string $contentRepository = 'default', bool $remove */ public function pruneRemovedFromEventStreamCommand(string $contentRepository = 'default'): void { + if (!$this->output->askConfirmation(sprintf('> This operation in "%s" cannot be reverted. Are you sure to proceed? (y/n) ', $contentRepository), false)) { + $this->outputLine('Abort.'); + return; + } + $contentRepositoryId = ContentRepositoryId::fromString($contentRepository); $contentStreamPruner = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentStreamPrunerFactory()); diff --git a/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php b/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php index 47ab58afc2a..7914b0c72a4 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php +++ b/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php @@ -8,13 +8,21 @@ use Neos\ContentRepository\Core\Service\ContentStreamPrunerFactory; use Neos\ContentRepository\Core\Service\WorkspaceMaintenanceServiceFactory; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; +use Neos\ContentRepository\Core\SharedModel\Exception\RootNodeAggregateDoesNotExist; +use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +use Neos\ContentRepositoryRegistry\Exception\InvalidConfigurationException; use Neos\ContentRepositoryRegistry\Service\ProjectionReplayServiceFactory; use Neos\EventStore\Model\Event\SequenceNumber; use Neos\EventStore\Model\EventStore\StatusType; use Neos\Flow\Cli\CommandController; +use Neos\Neos\Domain\Service\NodeTypeNameFactory; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Output\ConsoleOutput; +use Neos\Flow\Persistence\Doctrine\Exception\DatabaseException; +use Neos\Neos\Domain\Model\Site; +use Neos\Neos\Domain\Repository\SiteRepository; use Symfony\Component\Console\Output\Output; final class CrCommandController extends CommandController @@ -23,6 +31,7 @@ final class CrCommandController extends CommandController public function __construct( private readonly ContentRepositoryRegistry $contentRepositoryRegistry, private readonly ProjectionReplayServiceFactory $projectionServiceFactory, + private readonly SiteRepository $siteRepository, ) { parent::__construct(); } @@ -244,4 +253,119 @@ public function pruneCommand(string $contentRepository = 'default', bool $force $this->outputLine('Done.'); } + + /** + * @param bool $verbose shows additional internal output regarding content-streams and nodes in the projection + */ + public function listCommand(bool $verbose = false): void + { + /** @var list $neosSiteEntities */ + $neosSiteEntities = []; + try { + $neosSiteEntities = iterator_to_array($this->siteRepository->findAll()); + } catch (DatabaseException) { + // doctrine might have not been migrated yet or no database is connected. + $this->outputLine('Site repository is not accessible.'); + } + + $rows = []; + foreach ($this->contentRepositoryRegistry->getContentRepositoryIds() as $contentRepositoryId) { + $contentRepository = null; + try { + $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId); + } catch (InvalidConfigurationException $exception) { + $this->outputLine('Content repository %s is not well configures: %s.', [$contentRepositoryId->value, $exception->getMessage()]); + } + + + $liveContentGraph = null; + try { + $liveContentGraph = $contentRepository?->getContentGraph(WorkspaceName::forLive()); + } catch (WorkspaceDoesNotExist) { + $this->outputLine('Live workspace in content repository %s not existing.', [$contentRepositoryId->value]); + } + + $currenSiteNodes = []; + // todo wrap in catch runtime exception + if ($liveContentGraph && $verbose) { + $sitesAggregate = null; + try { + $sitesAggregate = $liveContentGraph->findRootNodeAggregateByType(NodeTypeNameFactory::forSites()); + } catch (RootNodeAggregateDoesNotExist) { + $this->outputLine('Sites root node does not exist in content repository %s.', [$contentRepositoryId->value]); + } + + if ($sitesAggregate) { + $siteNodeAggregates = $liveContentGraph->findChildNodeAggregates($sitesAggregate->nodeAggregateId); + foreach ($siteNodeAggregates as $siteNodeAggregate) { + assert($siteNodeAggregate->nodeName !== null); + $currenSiteNodes[] = $siteNodeAggregate->nodeName->value; + } + } + } + + $currentNeosSiteEntities = []; + foreach ($neosSiteEntities as $site) { + if (!$site->getConfiguration()->contentRepositoryId->equals($contentRepositoryId)) { + continue; + } + $currentNeosSiteEntities[] = $site->getNodeName()->value; + } + + if ($verbose) { + $connectedWorkingSites = array_intersect($currentNeosSiteEntities, $currenSiteNodes); + $siteNodesWithoutMatchingNeosSiteEntity = array_diff($currenSiteNodes, $currentNeosSiteEntities); + $neosSiteEntitiesWithoutMatchingSiteNode = array_diff($currentNeosSiteEntities, $currenSiteNodes); + $sitesString = ltrim( + (join(', ', $connectedWorkingSites) + . ($siteNodesWithoutMatchingNeosSiteEntity ? (', (only node: ' . join(', ', $siteNodesWithoutMatchingNeosSiteEntity) . ')') : '') + . ($neosSiteEntitiesWithoutMatchingSiteNode ? (', (only neos site: ' . join(', ', $neosSiteEntitiesWithoutMatchingSiteNode) . ')') : '') + ), ' ,') ?: '-'; + } else { + $sitesString = join(', ', $currentNeosSiteEntities) ?: '-'; + } + + $statusString = '-'; + $workspacesString = '-'; + $contentStreamsString = '-'; + $nodesString = '-'; + + if ($contentRepository) { + $statusString = $contentRepository->status()->isOk() ? 'okay' : 'not okay'; + + try { + $workspacesString = sprintf('%d found', count($contentRepository->getWorkspaceFinder()->findAll())); + } catch (\RuntimeException $e) { + $this->outputLine('WorkspaceFinder of %s not functional: %s.', [$contentRepositoryId->value, $e->getMessage()]); + } + + if ($verbose) { + try { + /** @phpstan-ignore neos.internal */ + $contentStreamsString = sprintf('%d found', iterator_count($contentRepository->getContentStreamFinder()->findAllIds())); + } catch (\RuntimeException $e) { + $this->outputLine('ContentStreamFinder of %s not functional: %s.', [$contentRepositoryId->value, $e->getMessage()]); + } + + try { + if ($liveContentGraph) { + $nodesString = sprintf('%d found', $liveContentGraph->countNodes()); + } + } catch (\RuntimeException $e) { + $this->outputLine('ContentGraph of %s not functional: %s.', [$contentRepositoryId->value, $e->getMessage()]); + } + } + } + + $rows[] = [ + $contentRepositoryId->value, + $statusString, + $sitesString, + $workspacesString, + ...($verbose ? [$contentStreamsString, $nodesString] : []) + ]; + } + + $this->output->outputTable($rows, ['Identifier', 'Status', 'Sites', 'Workspaces', ...($verbose ? ['Contentstreams', 'Nodes'] : [])]); + } } diff --git a/Neos.ContentRepositoryRegistry/Classes/ContentRepositoryRegistry.php b/Neos.ContentRepositoryRegistry/Classes/ContentRepositoryRegistry.php index 1fd7cc04910..4a62124b983 100644 --- a/Neos.ContentRepositoryRegistry/Classes/ContentRepositoryRegistry.php +++ b/Neos.ContentRepositoryRegistry/Classes/ContentRepositoryRegistry.php @@ -81,6 +81,15 @@ public function get(ContentRepositoryId $contentRepositoryId): ContentRepository return $this->getFactory($contentRepositoryId)->getOrBuild(); } + /** + * @return iterable + */ + public function getContentRepositoryIds(): iterable + { + /** @phpstan-ignore argument.type */ + return array_map(ContentRepositoryId::fromString(...), array_keys($this->settings['contentRepositories'] ?? [])); + } + /** * @internal for test cases only */ diff --git a/Neos.Neos/Classes/Command/SiteCommandController.php b/Neos.Neos/Classes/Command/SiteCommandController.php index 06b9dc797fa..9e8aaefb931 100644 --- a/Neos.Neos/Classes/Command/SiteCommandController.php +++ b/Neos.Neos/Classes/Command/SiteCommandController.php @@ -175,6 +175,8 @@ public function listCommand() } } + // todo use outputTable + $this->outputLine(); $this->outputLine(' ' . str_pad('Name', $longestSiteName + 15) . str_pad('Node name', $longestNodeName + 15)