mirror of
https://github.com/nextcloud/server.git
synced 2026-04-05 00:56:16 -04:00
Add RichObject support for SetupChecks descriptions
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
67fba0a574
commit
f34865eb4e
2 changed files with 54 additions and 8 deletions
|
|
@ -45,6 +45,30 @@ class SetupChecks extends Base {
|
|||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException if a parameter has no name or no type
|
||||
*/
|
||||
private function richToParsed(string $message, array $parameters): string {
|
||||
$placeholders = [];
|
||||
$replacements = [];
|
||||
foreach ($parameters as $placeholder => $parameter) {
|
||||
$placeholders[] = '{' . $placeholder . '}';
|
||||
foreach (['name','type'] as $requiredField) {
|
||||
if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
|
||||
throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
|
||||
}
|
||||
}
|
||||
if ($parameter['type'] === 'user') {
|
||||
$replacements[] = '@' . $parameter['name'];
|
||||
} elseif ($parameter['type'] === 'file') {
|
||||
$replacements[] = $parameter['path'] ?? $parameter['name'];
|
||||
} else {
|
||||
$replacements[] = $parameter['name'];
|
||||
}
|
||||
}
|
||||
return str_replace($placeholders, $replacements, $message);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$results = $this->setupCheckManager->runAll();
|
||||
switch ($input->getOption('output')) {
|
||||
|
|
@ -70,6 +94,10 @@ class SetupChecks extends Base {
|
|||
};
|
||||
$verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL);
|
||||
$description = $check->getDescription();
|
||||
$descriptionParameters = $check->getDescriptionParameters();
|
||||
if ($descriptionParameters !== null) {
|
||||
$description = $this->richToParsed($description, $descriptionParameters);
|
||||
}
|
||||
$output->writeln(
|
||||
"\t\t".
|
||||
($styleTag !== null ? "<{$styleTag}>" : '').
|
||||
|
|
|
|||
|
|
@ -46,10 +46,12 @@ class SetupResult implements \JsonSerializable {
|
|||
* @brief Private constructor, use success()/info()/warning()/error() instead
|
||||
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
*/
|
||||
private function __construct(
|
||||
private string $severity,
|
||||
private ?string $description = null,
|
||||
private ?array $descriptionParameters = null,
|
||||
private ?string $linkToDoc = null,
|
||||
) {
|
||||
}
|
||||
|
|
@ -59,9 +61,10 @@ class SetupResult implements \JsonSerializable {
|
|||
* @param ?string $description Translated detailed description to display to the user
|
||||
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
*/
|
||||
public static function success(?string $description = null, ?string $linkToDoc = null): self {
|
||||
return new self(self::SUCCESS, $description, $linkToDoc);
|
||||
public static function success(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
||||
return new self(self::SUCCESS, $description, $descriptionParameters, $linkToDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,9 +72,10 @@ class SetupResult implements \JsonSerializable {
|
|||
* @param ?string $description Translated detailed description to display to the user
|
||||
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
*/
|
||||
public static function info(?string $description = null, ?string $linkToDoc = null): self {
|
||||
return new self(self::INFO, $description, $linkToDoc);
|
||||
public static function info(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
||||
return new self(self::INFO, $description, $descriptionParameters, $linkToDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -79,9 +83,10 @@ class SetupResult implements \JsonSerializable {
|
|||
* @param ?string $description Translated detailed description to display to the user
|
||||
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
*/
|
||||
public static function warning(?string $description = null, ?string $linkToDoc = null): self {
|
||||
return new self(self::WARNING, $description, $linkToDoc);
|
||||
public static function warning(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
||||
return new self(self::WARNING, $description, $descriptionParameters, $linkToDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,9 +94,10 @@ class SetupResult implements \JsonSerializable {
|
|||
* @param ?string $description Translated detailed description to display to the user
|
||||
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
*/
|
||||
public static function error(?string $description = null, ?string $linkToDoc = null): self {
|
||||
return new self(self::ERROR, $description, $linkToDoc);
|
||||
public static function error(?string $description = null, ?string $linkToDoc = null, ?array $descriptionParameters = null): self {
|
||||
return new self(self::ERROR, $description, $descriptionParameters, $linkToDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,6 +119,17 @@ class SetupResult implements \JsonSerializable {
|
|||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the description parameters for the setup check result
|
||||
*
|
||||
* If this returns null, description must not be treated as rich text
|
||||
*
|
||||
* @since 28.0.2
|
||||
*/
|
||||
public function getDescriptionParameters(): ?array {
|
||||
return $this->descriptionParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the name for the setup check
|
||||
*
|
||||
|
|
@ -150,6 +167,7 @@ class SetupResult implements \JsonSerializable {
|
|||
'name' => $this->name,
|
||||
'severity' => $this->severity,
|
||||
'description' => $this->description,
|
||||
'descriptionParameters' => $this->descriptionParameters,
|
||||
'linkToDoc' => $this->linkToDoc,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue