Skip to content

Commit

Permalink
WIP: cr:list command
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 19, 2024
1 parent c726eae commit 26fff3a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ final class CrCommandController extends CommandController
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 @@ public function pruneCommand(string $contentRepository = 'default', bool $force

$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']);
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 26fff3a

Please sign in to comment.