Skip to content

Commit

Permalink
TASK: Improve flow cr:status
Browse files Browse the repository at this point in the history
Followup to neos#4846

- require a $details string for all non-ok status
- print "No details available." if verbose and non-ok and no details are available
- dont wortbreak details in verbose mode but print them with indentation of 2 full line per line
- print new line after printing details
- add details to AssetUsageProjection's setupRequired
  • Loading branch information
mhsdesign committed Jan 23, 2024
1 parent 9e32944 commit 5219dcc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
final readonly class ProjectionStatus
{
public function __construct(
private function __construct(
public ProjectionStatusType $type,
public string $details,
) {
Expand All @@ -18,18 +18,35 @@ public static function ok(): self
return new self(ProjectionStatusType::OK, '');
}

/**
* @param non-empty-string $details
*/
public static function error(string $details): self
{
return new self(ProjectionStatusType::ERROR, $details);
}

public static function setupRequired(string $details = ''): self
/**
* @param non-empty-string $details
*/
public static function setupRequired(string $details): self
{
return new self(ProjectionStatusType::SETUP_REQUIRED, $details);
}

public static function replayRequired(string $details = ''): self
/**
* @param non-empty-string $details
*/
public static function replayRequired(string $details): self
{
return new self(ProjectionStatusType::REPLAY_REQUIRED, $details);
}

/**
* @param non-empty-string $details
*/
public function withDetails(string $details): self
{
return new self($this->type, $details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ public function statusCommand(string $contentRepository = 'default', bool $verbo
if ($projectionStatus->type !== ProjectionStatusType::OK) {
$hasErrorsOrWarnings = true;
}
if ($verbose && $projectionStatus->details !== '') {
$this->outputFormatted($projectionStatus->details, [], 2);
if ($verbose && ($projectionStatus->type !== ProjectionStatusType::OK || $projectionStatus->details)) {
$lines = explode(chr(10), $projectionStatus->details ?: '<comment>No details available.</comment>');
foreach ($lines as $line) {
$this->outputLine(' ' . $line);
}
$this->outputLine();
}
}
if ($hasErrorsOrWarnings) {
Expand Down
10 changes: 5 additions & 5 deletions Neos.Neos/Classes/AssetUsage/Projection/AssetUsageProjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ public function status(): ProjectionStatus
return ProjectionStatus::setupRequired($checkpointStorageStatus->details);
}
try {
$this->repository->findUsages(AssetUsageFilter::create());
$falseOrDetailsString = $this->repository->isSetupRequired();
if ($falseOrDetailsString !== false) {
return ProjectionStatus::setupRequired($falseOrDetailsString);
}
} catch (\Throwable $e) {
return ProjectionStatus::error($e->getMessage());
}
if ($this->repository->isSetupRequired()) {
return ProjectionStatus::setupRequired();
return ProjectionStatus::error(sprintf('Failed to determine required SQL statements: %s', $e->getMessage()));
}
return ProjectionStatus::ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public function setUp(): void
}
}

public function isSetupRequired(): bool
public function isSetupRequired(): false|string
{
return DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $this->databaseSchema()) !== [];
$requiredSqlStatements = DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $this->databaseSchema());
if ($requiredSqlStatements !== []) {
return sprintf('The following SQL statement%s required: %s', count($requiredSqlStatements) !== 1 ? 's are' : ' is', implode(chr(10), $requiredSqlStatements));
}
return false;
}

private function databaseSchema(): Schema
Expand Down

0 comments on commit 5219dcc

Please sign in to comment.