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

WIP: cr:list command #4900

Draft
wants to merge 1 commit into
base: 9.0
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
Expand Up @@ -28,9 +28,14 @@ class ContentStreamCommandController extends CommandController
* If you also call with "--removeTemporary", will delete ALL content streams which are currently not assigned
* to a workspace (f.e. dangling ones in FORKED or CREATED.).
*/
public function pruneCommand(string $contentRepositoryIdentifier = 'default', bool $removeTemporary = false): void
public function pruneCommand(string $contentRepository = 'default', bool $removeTemporary = false): void
{
$contentRepositoryId = ContentRepositoryId::fromString($contentRepositoryIdentifier);
if (!$this->output->askConfirmation(sprintf('> This operation in "%s" cannot be reverted. Are you sure to proceed? (y/n) ', $contentRepository), false)) {
$this->outputLine('<comment>Abort.</comment>');
return;
}

$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$contentStreamPruner = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentStreamPrunerFactory());

$unusedContentStreams = $contentStreamPruner->prune($removeTemporary);
Expand All @@ -47,9 +52,14 @@ public function pruneCommand(string $contentRepositoryIdentifier = 'default', bo
/**
* Remove unused and deleted content streams from the event stream; effectively REMOVING information completely
*/
public function pruneRemovedFromEventStreamCommand(string $contentRepositoryIdentifier = 'default'): void
public function pruneRemovedFromEventStreamCommand(string $contentRepository = 'default'): void
{
$contentRepositoryId = ContentRepositoryId::fromString($contentRepositoryIdentifier);
if (!$this->output->askConfirmation(sprintf('> This operation in "%s" cannot be reverted. Are you sure to proceed? (y/n) ', $contentRepository), false)) {
$this->outputLine('<comment>Abort.</comment>');
return;
}

$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$contentStreamPruner = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentStreamPrunerFactory());

$unusedContentStreams = $contentStreamPruner->pruneRemovedFromEventStream();
Expand Down
Expand Up @@ -7,12 +7,16 @@
use Neos\ContentRepository\Core\Projection\CatchUpOptions;
use Neos\ContentRepository\Core\Projection\ProjectionStatusType;
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\ContentRepository\Core\Service\ContentStreamPrunerFactory;
use Neos\ContentRepository\Core\Service\WorkspaceMaintenanceServiceFactory;
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
Expand All @@ -21,6 +25,7 @@
public function __construct(
private readonly ContentRepositoryRegistry $contentRepositoryRegistry,
private readonly ProjectionReplayServiceFactory $projectionServiceFactory,
private readonly SiteRepository $siteRepository,
) {
parent::__construct();
}
Expand Down Expand Up @@ -217,4 +222,73 @@

$this->outputLine('<success>Done.</success>');
}

public function listCommand()

Check failure on line 226 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)

Method Neos\ContentRepositoryRegistry\Command\CrCommandController::listCommand() has no return type specified.

Check failure on line 226 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)

Method Neos\ContentRepositoryRegistry\Command\CrCommandController::listCommand() has no return type specified.
{
$rows = [];

/** @var list<Site> $sites */
$sites = [];
try {
$sites = iterator_to_array($this->siteRepository->findAll());
} catch (DatabaseException) {
// doctrine might have not been migrated yet or no database is connected.
$this->outputLine('<comment>Site repository is not accessible.</comment>');
}

foreach ($this->contentRepositoryRegistry->getAllContentRepositoryIds() as $contentRepositoryId) {
$contentRepository = null;
try {
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
} catch (InvalidConfigurationException $exception) {
$this->outputLine('<comment>Content repository %s is not well configures: %s.</comment>', [$contentRepositoryId->value, $exception->getMessage()]);
}

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

$statusString = '-';
$workspacesString = '-';
$contentStreamsString = '-';
$nodesString = '-';

if ($contentRepository) {
$statusString = $contentRepository->status()->isOk() ? 'okay' : 'not okay';

try {
$workspacesString = sprintf('%d entries', count($contentRepository->getWorkspaceFinder()->findAll()));
} catch (\Throwable $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()));

Check failure on line 270 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 270 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 (\Throwable $e) {
$this->outputLine('<comment>ContentStreamFinder of %s not functional: %s.</comment>', [$contentRepositoryId->value, $e->getMessage()]);
}

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

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

$this->output->outputTable($rows, ['Identifier', 'Status', 'Sites', 'Workspaces', 'Contentstreams', 'Nodes']);
}
}
Expand Up @@ -64,6 +64,19 @@ public function get(ContentRepositoryId $contentRepositoryId): ContentRepository
return $this->getFactory($contentRepositoryId)->getOrBuild();
}

/**
* @return iterable<int, ContentRepositoryId>
*/
public function getAllContentRepositoryIds(): iterable
{
if (!is_array($this->settings['contentRepositories'] ?? null)) {
throw InvalidConfigurationException::fromMessage('No Content Repositories are configured');
}
foreach (array_keys($this->settings['contentRepositories']) as $contentRepositoryId) {
yield ContentRepositoryId::fromString($contentRepositoryId);
}
}

/**
* @internal for test cases only
*/
Expand Down
2 changes: 2 additions & 0 deletions Neos.Neos/Classes/Command/SiteCommandController.php
Expand Up @@ -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)
Expand Down