Skip to content

Commit

Permalink
TASK: Reimplement 40e8d35
Browse files Browse the repository at this point in the history
Under consideration of the new `ProjectionSubscriptionStatus`
  • Loading branch information
mhsdesign committed Nov 24, 2024
1 parent 9675572 commit 655ac3c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Neos\ContentRepository\Core\Subscription;

use Neos\ContentRepository\Core\Projection\ProjectionSetupStatusType;

/**
* A collection of the states of the subscribers.
*
Expand Down Expand Up @@ -62,20 +60,4 @@ public function isEmpty(): bool
{
return $this->statuses === [];
}

public function isOk(): bool
{
foreach ($this->statuses as $status) {
// ignores DetachedSubscriptionStatus
if ($status instanceof ProjectionSubscriptionStatus) {
if ($status->subscriptionStatus === SubscriptionStatus::ERROR) {
return false;
}
if ($status->setupStatus->type !== ProjectionSetupStatusType::OK) {
return false;
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,85 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
}
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$contentRepositoryMaintainer = $this->contentRepositoryRegistry->buildService($contentRepositoryId, new ContentRepositoryMaintainerFactory());

$eventStoreStatus = $contentRepositoryMaintainer->eventStoreStatus();
$hasErrors = false;
$setupRequired = false;
$bootingRequired = false;
$this->output('Event Store: ');
$this->outputLine(match ($eventStoreStatus->type) {
StatusType::OK => '<success>OK</success>',
StatusType::SETUP_REQUIRED => '<comment>Setup required!</comment>',
StatusType::ERROR => '<error>ERROR</error>',
});
$hasErrors |= $eventStoreStatus->type === StatusType::ERROR;
if ($verbose && $eventStoreStatus->details !== '') {
$this->outputFormatted($eventStoreStatus->details, [], 2);
}
$this->outputLine();

$this->outputLine('Subscriptions:');
$subscriptionStatuses = $contentRepositoryMaintainer->subscriptionStatuses();
foreach ($subscriptionStatuses as $subscriptionStatus) {
if ($subscriptionStatus instanceof DetachedSubscriptionStatus) {
$this->output('<comment>Subscriber "<b>%s</b>" %s detached.</comment>', [$subscriptionStatus->subscriptionId->value, $subscriptionStatus->subscriptionStatus === SubscriptionStatus::DETACHED ? 'is' : 'will be']);
if ($subscriptionStatuses->isEmpty()) {
$this->outputLine('<error>There are no registered subscriptions yet, please run <em>./flow cr:setup</em></error>');
$this->quit(1);
}
foreach ($subscriptionStatuses as $status) {
if ($status instanceof DetachedSubscriptionStatus) {
$this->outputLine(' <b>%s</b>:', [$status->subscriptionId->value]);
$this->output(' Subscription: ');
$this->output('%s <comment>DETACHED</comment>', [$status->subscriptionId->value, $status->subscriptionStatus === SubscriptionStatus::DETACHED ? 'is' : 'will be']);
$this->outputLine(' at position <b>%d</b>', [$status->subscriptionPosition->value]);
}
if ($subscriptionStatus instanceof ProjectionSubscriptionStatus) {
// todo reimplement 40e8d35e09ee690406c6a9cfc823c775d4ee3b51
$this->output('Projection "<b>%s</b>": ', [$subscriptionStatus->subscriptionId->value]);
$projectionStatus = $subscriptionStatus->setupStatus;

$this->outputLine(match ($projectionStatus->type) {
if ($status instanceof ProjectionSubscriptionStatus) {
$this->outputLine(' <b>%s</b>:', [$status->subscriptionId->value]);
$this->output(' Projection: ');
$this->output(match ($status->subscriptionStatus) {
SubscriptionStatus::NEW => '<comment>NEW</comment>',
SubscriptionStatus::BOOTING => '<comment>BOOTING</comment>',
SubscriptionStatus::ACTIVE => '<success>ACTIVE</success>',
SubscriptionStatus::DETACHED => '<comment>DETACHED</comment>',
SubscriptionStatus::ERROR => '<error>ERROR</error>',
});
$this->outputLine(' at position <b>%d</b>', [$status->subscriptionPosition->value]);
$hasErrors |= $status->subscriptionStatus === SubscriptionStatus::ERROR;
$bootingRequired |= $status->subscriptionStatus === SubscriptionStatus::BOOTING;
// detached can be reattached via setup:
$setupRequired |= $status->subscriptionStatus === SubscriptionStatus::DETACHED;
if ($verbose && $status->subscriptionError !== null) {
$lines = explode(chr(10), $status->subscriptionError->errorMessage ?: '<comment>No details available.</comment>');
foreach ($lines as $line) {
$this->outputLine('<error> %s</error>', [$line]);
}
}
$this->output(' Setup: ');
$this->outputLine(match ($status->setupStatus->type) {
ProjectionSetupStatusType::OK => '<success>OK</success>',
ProjectionSetupStatusType::SETUP_REQUIRED => '<comment>Setup required!</comment>',
ProjectionSetupStatusType::SETUP_REQUIRED => '<comment>SETUP REQUIRED</comment>',
ProjectionSetupStatusType::ERROR => '<error>ERROR</error>',
});
if ($verbose && ($projectionStatus->type !== ProjectionSetupStatusType::OK || $projectionStatus->details)) {
$lines = explode(chr(10), $projectionStatus->details ?: '<comment>No details available.</comment>');
$hasErrors |= $status->setupStatus->type === ProjectionSetupStatusType::ERROR;
$setupRequired |= $status->setupStatus->type === ProjectionSetupStatusType::SETUP_REQUIRED;
if ($verbose && ($status->setupStatus->type !== ProjectionSetupStatusType::OK || $status->setupStatus->details)) {
$lines = explode(chr(10), $status->setupStatus->details ?: '<comment>No details available.</comment>');
foreach ($lines as $line) {
$this->outputLine(' ' . $line);
$this->outputLine(' ' . $line);
}
$this->outputLine();
}
}
}
if ($eventStoreStatus->type !== StatusType::OK || !$subscriptionStatuses->isOk()) {
if ($verbose) {
$this->outputLine();
if ($setupRequired) {
$this->outputLine('<comment>Setup required, please run <em>./flow cr:setup</em></comment>');
}
if ($bootingRequired) {
$this->outputLine('<comment>Catchup needed for projections, please run <em>./flow cr:projectioncatchup [projection-name]</em></comment>');
}
if ($hasErrors) {
$this->outputLine('<error>Some projections are not okay</error>');
}
}
if ($hasErrors) {
$this->quit(1);
}
}
Expand Down
13 changes: 11 additions & 2 deletions Neos.Neos/Classes/Domain/Service/SiteImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
use Doctrine\DBAL\Exception as DBALException;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Neos\ContentRepository\Core\Projection\ProjectionSetupStatusType;
use Neos\ContentRepository\Core\Service\ContentRepositoryMaintainer;
use Neos\ContentRepository\Core\Service\ContentRepositoryMaintainerFactory;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\Subscription\ProjectionSubscriptionStatus;
use Neos\ContentRepository\Export\Factory\EventStoreImportProcessorFactory;
use Neos\ContentRepository\Export\ProcessingContext;
use Neos\ContentRepository\Export\ProcessorInterface;
Expand Down Expand Up @@ -94,10 +96,17 @@ public function importFromPath(ContentRepositoryId $contentRepositoryId, string
private function requireContentRepositoryToBeSetup(ContentRepositoryMaintainer $contentRepositoryMaintainer, ContentRepositoryId $contentRepositoryId): void
{
$eventStoreStatus = $contentRepositoryMaintainer->eventStoreStatus();
$subscriptionStatuses = $contentRepositoryMaintainer->subscriptionStatuses();
if ($eventStoreStatus->type !== StatusType::OK || !$subscriptionStatuses->isOk()) {
if ($eventStoreStatus->type !== StatusType::OK) {
throw new \RuntimeException(sprintf('Content repository %s is not setup correctly, please run `./flow cr:setup`', $contentRepositoryId->value));
}
$subscriptionStatuses = $contentRepositoryMaintainer->subscriptionStatuses();
foreach ($subscriptionStatuses as $status) {
if ($status instanceof ProjectionSubscriptionStatus) {
if ($status->setupStatus->type !== ProjectionSetupStatusType::OK) {
throw new \RuntimeException(sprintf('Projection %s in content repository %s is not setup correctly, please run `./flow cr:setup`', $status->subscriptionId->value, $contentRepositoryId->value));
}
}
}
}

private function requireDataBaseSchemaToBeSetup(): void
Expand Down

0 comments on commit 655ac3c

Please sign in to comment.