Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Run setup checks by category or class #49978

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion core/Command/SetupChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\SetupCheck\ISetupCheckManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -28,11 +29,41 @@ protected function configure(): void {
$this
->setName('setupchecks')
->setDescription('Run setup checks and output the results')
->addArgument(
'type',
InputArgument::OPTIONAL,
'Category (or class) of setup checks to run ' . "\n" . '(e.g. "network" to run all the network-related checks or "OCA\\Settings\\SetupChecks\\InternetConnectivity" to run only the InternetConnectivity check)',
'all'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$results = $this->setupCheckManager->runAll();
$limit = $input->getArgument('type');

if (!is_string($limit)) {
$output->writeln('<error>Invalid type specified</error>');
return self::FAILURE;
}

switch ($limit) {
case 'all': // run all checks (the default)
$results = $this->setupCheckManager->runAll();
break;

default: // limit checks to a specific category or class
if (substr_count($limit, '\\') > 1) {
$results = $this->setupCheckManager->runClass($limit);
} else {
$results = $this->setupCheckManager->runCategory($limit);
}

if (empty($results)) {
$output->writeln('<error>Invalid type specified (or no results for that type)</error>');
return self::FAILURE;
}
}

switch ($input->getOption('output')) {
case self::OUTPUT_FORMAT_JSON:
case self::OUTPUT_FORMAT_JSON_PRETTY:
Expand Down
20 changes: 19 additions & 1 deletion lib/private/SetupCheck/SetupCheckManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,31 @@ public function __construct(
private LoggerInterface $logger,
) {
}


public function runClass(string $limitClass): array {
if (str_starts_with($limitClass, '\\')) {
$limitClass = substr($limitClass, 1);
}
return $this->run($limitClass);
}

public function runCategory(string $limitCategory): array {
return $this->run($limitCategory);
}

public function runAll(): array {
return $this->run();
}

private function run(?string $limit = null): array {
$results = [];
$setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks();
foreach ($setupChecks as $setupCheck) {
/** @var ISetupCheck $setupCheckObject */
$setupCheckObject = Server::get($setupCheck->getService());
if (isset($limit) && $limit !== $setupCheckObject->getCategory() && $limit !== get_class($setupCheckObject)) {
continue;
}
$this->logger->debug('Running check ' . get_class($setupCheckObject));
try {
$setupResult = $setupCheckObject->run();
Expand Down
11 changes: 11 additions & 0 deletions lib/public/SetupCheck/ISetupCheckManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ interface ISetupCheckManager {
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
*/
public function runAll(): array;
/**
* @since 31.0.0
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
*/
public function runClass(string $limitClass): array;
/**
* @since 31.0.0
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
*/
public function runCategory(string $limitCategory): array;

}
Loading