Skip to content

Commit

Permalink
TASK: Improve and document cr:status
Browse files Browse the repository at this point in the history
* adds `ContentRepositoryStatus::isOk` for simplicity
  • Loading branch information
mhsdesign committed Feb 12, 2024
1 parent 6a515d8 commit fc87012
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
namespace Neos\ContentRepository\Core\SharedModel\ContentRepository;

use Neos\ContentRepository\Core\Projection\ProjectionStatuses;
use Neos\ContentRepository\Core\Projection\ProjectionStatusType;
use Neos\EventStore\Model\EventStore\Status as EventStoreStatus;
use Neos\EventStore\Model\EventStore\StatusType as EventStoreStatusType;

/**
* @api
Expand All @@ -27,4 +29,17 @@ public function __construct(
public ProjectionStatuses $projectionStatuses,
) {
}

public function isOk(): bool
{
if ($this->eventStoreStatus->type !== EventStoreStatusType::OK) {
return false;
}
foreach ($this->projectionStatuses as $projectionStatus) {
if ($projectionStatus->type !== ProjectionStatusType::OK) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function __construct(
* Note: This command is non-destructive, i.e. it can be executed without side effects even if all dependencies are up-to-date
* Therefore it makes sense to include this command into the Continuous Integration
*
* To check if the content repository needs to be setup look into cr:status.
* That command will also display information what is about to be migrated.
*
* @param string $contentRepository Identifier of the Content Repository to set up
* @param bool $resetProjections Advanced. Can be used in rare cases when the projections cannot be migrated to reset everything in advance. This requires a full replay afterwards.
*/
Expand All @@ -57,6 +60,8 @@ public function setupCommand(string $contentRepository = 'default', bool $resetP
/**
* Determine and output the status of the event store and all registered projections for a given Content Repository
*
* In verbose mode it will also display information what should and will be migrated when cr:setup is used.
*
* @param string $contentRepository Identifier of the Content Repository to determine the status for
* @param bool $verbose If set, more details will be shown
* @param bool $quiet If set, no output is generated. This is useful if only the exit code (0 = all OK, 1 = errors or warnings) is of interest
Expand All @@ -69,8 +74,6 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$status = $this->contentRepositoryRegistry->get($contentRepositoryId)->status();

$hasErrorsOrWarnings = false;

$this->output('Event Store: ');
$this->outputLine(match ($status->eventStoreStatus->type) {
StatusType::OK => '<success>OK</success>',
Expand All @@ -80,9 +83,6 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
if ($verbose && $status->eventStoreStatus->details !== '') {
$this->outputFormatted($status->eventStoreStatus->details, [], 2);
}
if ($status->eventStoreStatus->type !== StatusType::OK) {
$hasErrorsOrWarnings = true;
}
$this->outputLine();
foreach ($status->projectionStatuses as $projectionName => $projectionStatus) {
$this->output('Projection "<b>%s</b>": ', [$projectionName]);
Expand All @@ -92,9 +92,6 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
ProjectionStatusType::REPLAY_REQUIRED => '<comment>Replay required!</comment>',
ProjectionStatusType::ERROR => '<error>ERROR</error>',
});
if ($projectionStatus->type !== ProjectionStatusType::OK) {
$hasErrorsOrWarnings = true;
}
if ($verbose && ($projectionStatus->type !== ProjectionStatusType::OK || $projectionStatus->details)) {
$lines = explode(chr(10), $projectionStatus->details ?: '<comment>No details available.</comment>');
foreach ($lines as $line) {
Expand All @@ -103,7 +100,7 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
$this->outputLine();
}
}
if ($hasErrorsOrWarnings) {
if (!$status->isOk()) {
$this->quit(1);
}
}
Expand Down

0 comments on commit fc87012

Please sign in to comment.