diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-01-04 16:27:18 +0100 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-01-11 14:03:55 +0100 |
commit | f34865eb4eb2cebc6379ebb0479c2b2e997a2301 (patch) | |
tree | 95adc4c5c670f29a489e97af2040d3339b57c048 /core | |
parent | 67fba0a574a3740976c84bb6498011e8d2cef0f1 (diff) | |
download | nextcloud-server-f34865eb4eb2cebc6379ebb0479c2b2e997a2301.tar.gz nextcloud-server-f34865eb4eb2cebc6379ebb0479c2b2e997a2301.zip |
Add RichObject support for SetupChecks descriptions
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/SetupChecks.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index bd76a9d1e65..0940a139617 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -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}>" : ''). |