Skip to content

Commit

Permalink
WIP: cr:list introduce --verbose option and show detached site nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 22, 2024
1 parent c858250 commit 4cb1889
Showing 1 changed file with 62 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
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;
Expand Down Expand Up @@ -251,10 +254,11 @@ public function pruneCommand(string $contentRepository = 'default', bool $force
$this->outputLine('<success>Done.</success>');
}

public function listCommand()
/**
* @param bool $verbose shows additional internal output regarding content-streams and nodes in the projection
*/
public function listCommand(bool $verbose = false): void
{
$rows = [];

/** @var list<Site> $sites */
$sites = [];
try {
Expand All @@ -264,6 +268,7 @@ public function listCommand()
$this->outputLine('<comment>Site repository is not accessible.</comment>');
}

$rows = [];
foreach ($this->contentRepositoryRegistry->getContentRepositoryIds() as $contentRepositoryId) {
$contentRepository = null;
try {
Expand All @@ -272,12 +277,46 @@ public function listCommand()
$this->outputLine('<comment>Content repository %s is not well configures: %s.</comment>', [$contentRepositoryId->value, $exception->getMessage()]);
}


$liveContentGraph = null;
try {
$liveContentGraph = $contentRepository->getContentGraph(WorkspaceName::forLive());

Check failure on line 283 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Cannot call method getContentGraph() on Neos\ContentRepository\Core\ContentRepository|null.

Check failure on line 283 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Cannot call method getContentGraph() on Neos\ContentRepository\Core\ContentRepository|null.
} catch (WorkspaceDoesNotExist) {
$this->outputLine('<comment>Live workspace in content repository %s not existing.</comment>', [$contentRepositoryId->value]);
}

$siteNodes = [];
// todo wrap in catch runtime exception
if ($liveContentGraph && $verbose) {
$sitesAggregate = null;
try {
$sitesAggregate = $liveContentGraph->findRootNodeAggregateByType(NodeTypeNameFactory::forSites());
} catch (RootNodeAggregateDoesNotExist) {
$this->outputLine('<comment>Sites root node does not exist in content repository %s.</comment>', [$contentRepositoryId->value]);
}

if ($sitesAggregate) {
$siteNodeAggregates = $liveContentGraph->findChildNodeAggregates($sitesAggregate->nodeAggregateId);
foreach ($siteNodeAggregates as $siteNodeAggregate) {
$siteNodes[] = $siteNodeAggregate->nodeName->value;

Check failure on line 301 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Cannot access property $value on Neos\ContentRepository\Core\SharedModel\Node\NodeName|null.

Check failure on line 301 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Cannot access property $value on Neos\ContentRepository\Core\SharedModel\Node\NodeName|null.
}
}
}

$configuredSites = [];
foreach ($sites as $site) {
if (!$site->getConfiguration()->contentRepositoryId->equals($contentRepositoryId)) {
continue;
}
$configuredSites[] = $site->getName();
$configuredSites[] = $site->getNodeName()->value;
}

if ($verbose) {
$connectedSites = array_intersect($configuredSites, $siteNodes);
$unconnectedSiteNodes = array_diff($configuredSites, $siteNodes);
$sitesString = ltrim((join(', ', $connectedSites) . ($unconnectedSiteNodes ? (', (detached: ' . join(', ', $unconnectedSiteNodes) . ')') : '')), ' ,') ?: '-';
} else {
$sitesString = join(', ', $configuredSites) ?: '-';
}

$statusString = '-';
Expand All @@ -289,34 +328,37 @@ public function listCommand()
$statusString = $contentRepository->status()->isOk() ? 'okay' : 'not okay';

try {
$workspacesString = sprintf('%d entries', count($contentRepository->getWorkspaceFinder()->findAll()));
} catch (\Throwable $e) {
$workspacesString = sprintf('%d found', count($contentRepository->getWorkspaceFinder()->findAll()));
} catch (\RuntimeException $e) {
$this->outputLine('<comment>WorkspaceFinder of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
}

try {
$contentStreamsString = sprintf('%d entries', iterator_count($contentRepository->getContentStreamFinder()->findAllIds()));
} catch (\Throwable $e) {
$this->outputLine('<comment>ContentStreamFinder of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
}

try {
$nodesString = sprintf('%d entries', $contentRepository->getContentGraph(WorkspaceName::forLive())->countNodes());
} catch (\RuntimeException $e) {
$this->outputLine('<comment>ContentGraph of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
if ($verbose) {
try {
$contentStreamsString = sprintf('%d found', iterator_count($contentRepository->getContentStreamFinder()->findAllIds()));

Check failure on line 338 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

The internal method "Neos\ContentRepository\Core\Projection\ContentStream\ContentStreamFinder::findAllIds" is called.

Check failure on line 338 in Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

The internal method "Neos\ContentRepository\Core\Projection\ContentStream\ContentStreamFinder::findAllIds" is called.
} catch (\RuntimeException $e) {
$this->outputLine('<comment>ContentStreamFinder of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
}

try {
if ($liveContentGraph) {
$nodesString = sprintf('%d found', $liveContentGraph->countNodes());
}
} catch (\RuntimeException $e) {
$this->outputLine('<comment>ContentGraph of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
}
}
}

$rows[] = [
$contentRepositoryId->value,
$statusString,
join(', ', $configuredSites) ?: '-',
$sitesString,
$workspacesString,
$contentStreamsString,
$nodesString
...($verbose ? [$contentStreamsString, $nodesString] : [])
];
}

$this->output->outputTable($rows, ['Identifier', 'Status', 'Sites', 'Workspaces', 'Contentstreams', 'Nodes']);
$this->output->outputTable($rows, ['Identifier', 'Status', 'Sites', 'Workspaces', ...($verbose ? ['Contentstreams', 'Nodes'] : [])]);
}
}

0 comments on commit 4cb1889

Please sign in to comment.