Compare commits

...

4 Commits

Author SHA1 Message Date
Josh
622195176d fixup: missed from my local changes
Signed-off-by: Josh <josh.t.richards@gmail.com>
2024-12-28 11:57:34 -05:00
Josh
f4d7620153 chore: Add category/class type parameter to setupchecks cmd
Signed-off-by: Josh <josh.t.richards@gmail.com>
2024-12-28 11:57:34 -05:00
Josh
e72b945cbe chore: update ISetupCheckManager interface for new category/class limit handling
Signed-off-by: Josh <josh.t.richards@gmail.com>
2024-12-28 11:57:34 -05:00
Josh
8852a75563 feat: Run setup checks by category or class
Signed-off-by: Josh <josh.t.richards@gmail.com>
2024-12-28 11:57:34 -05:00
3 changed files with 62 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ namespace OC\Core\Command;
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;
@@ -28,11 +29,41 @@ class SetupChecks extends Base {
$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:

View File

@@ -22,13 +22,31 @@ class SetupCheckManager implements ISetupCheckManager {
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();

View File

@@ -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;
}