2023-10-24 08:42:26 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-24 17:43:47 +00:00
|
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2023-10-24 08:42:26 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace OC\Core\Command;
|
|
|
|
|
|
2024-09-17 11:57:33 +00:00
|
|
|
|
use OCP\RichObjectStrings\IRichTextFormatter;
|
2023-10-24 08:42:26 +00:00
|
|
|
|
use OCP\SetupCheck\ISetupCheckManager;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class SetupChecks extends Base {
|
|
|
|
|
public function __construct(
|
|
|
|
|
private ISetupCheckManager $setupCheckManager,
|
2024-09-17 11:57:33 +00:00
|
|
|
|
private IRichTextFormatter $richTextFormatter,
|
2023-10-24 08:42:26 +00:00
|
|
|
|
) {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configure(): void {
|
|
|
|
|
parent::configure();
|
|
|
|
|
|
|
|
|
|
$this
|
|
|
|
|
->setName('setupchecks')
|
|
|
|
|
->setDescription('Run setup checks and output the results')
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
|
|
|
|
$results = $this->setupCheckManager->runAll();
|
|
|
|
|
switch ($input->getOption('output')) {
|
|
|
|
|
case self::OUTPUT_FORMAT_JSON:
|
|
|
|
|
case self::OUTPUT_FORMAT_JSON_PRETTY:
|
|
|
|
|
$this->writeArrayInOutputFormat($input, $output, $results);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
foreach ($results as $category => $checks) {
|
|
|
|
|
$output->writeln("\t{$category}:");
|
2023-11-06 15:21:15 +00:00
|
|
|
|
foreach ($checks as $check) {
|
2023-10-24 08:42:26 +00:00
|
|
|
|
$styleTag = match ($check->getSeverity()) {
|
|
|
|
|
'success' => 'info',
|
|
|
|
|
'error' => 'error',
|
2023-11-06 14:28:51 +00:00
|
|
|
|
'warning' => 'comment',
|
|
|
|
|
default => null,
|
2023-10-24 08:42:26 +00:00
|
|
|
|
};
|
|
|
|
|
$emoji = match ($check->getSeverity()) {
|
|
|
|
|
'success' => '✓',
|
2023-10-26 14:10:49 +00:00
|
|
|
|
'error' => '✗',
|
2023-10-26 10:01:52 +00:00
|
|
|
|
'warning' => '⚠',
|
2023-10-24 08:42:26 +00:00
|
|
|
|
default => 'ℹ',
|
|
|
|
|
};
|
2023-10-24 14:55:45 +00:00
|
|
|
|
$verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL);
|
|
|
|
|
$description = $check->getDescription();
|
2024-01-04 15:27:18 +00:00
|
|
|
|
$descriptionParameters = $check->getDescriptionParameters();
|
2024-01-09 15:27:23 +00:00
|
|
|
|
if ($description !== null && $descriptionParameters !== null) {
|
2024-09-17 11:57:33 +00:00
|
|
|
|
$description = $this->richTextFormatter->richToParsed($description, $descriptionParameters);
|
2024-01-04 15:27:18 +00:00
|
|
|
|
}
|
2023-10-24 08:42:26 +00:00
|
|
|
|
$output->writeln(
|
2023-11-06 14:28:51 +00:00
|
|
|
|
"\t\t" .
|
|
|
|
|
($styleTag !== null ? "<{$styleTag}>" : '') .
|
2023-10-24 08:42:26 +00:00
|
|
|
|
"{$emoji} " .
|
2023-11-06 15:21:15 +00:00
|
|
|
|
($check->getName() ?? $check::class) .
|
2023-10-24 14:55:45 +00:00
|
|
|
|
($description !== null ? ': ' . $description : '') .
|
2023-11-06 14:28:51 +00:00
|
|
|
|
($styleTag !== null ? "</{$styleTag}>" : ''),
|
2023-10-24 14:55:45 +00:00
|
|
|
|
$verbosity
|
2023-10-24 08:42:26 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ($results as $category => $checks) {
|
2023-11-06 15:21:15 +00:00
|
|
|
|
foreach ($checks as $check) {
|
2023-10-24 08:42:26 +00:00
|
|
|
|
if ($check->getSeverity() !== 'success') {
|
2023-10-24 14:55:45 +00:00
|
|
|
|
return self::FAILURE;
|
2023-10-24 08:42:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-24 14:55:45 +00:00
|
|
|
|
return self::SUCCESS;
|
2023-10-24 08:42:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|