setName('check')
->setDescription('Check Problems')
->setHelp('The problems command allows you display any potential problems with your Grav setup')
;
}
/**
* @return int
*/
protected function serve(): int
{
$io = new SymfonyStyle($this->input, $this->output);
$plugin_dir = realpath(dirname(__DIR__));
$problems_dir = $plugin_dir . '/classes/Problems';
require $plugin_dir . '/vendor/autoload.php';
$checker = new ProblemChecker();
$checker->check($problems_dir);
$problems = $checker->getProblems();
$io->title('Grav Problems');
$table = new Table($this->output);
$table->setStyle('default');
$headers = ['ID', 'Status', 'Level', 'Message'];
$rows = [];
/** @var Problem $problem */
foreach ($problems as $problem) {
$rows[] = new TableSeparator();
$rows[] = [
$problem->getStatus() ? $problem->getId() : '' . $problem->getId() . '' ,
$problem->getStatus() ? 'success' : 'error',
$problem->getLevel() === 'critical' ? '' . $problem->getLevel() . '' : '' .$problem->getLevel() . '',
strip_tags($problem->getMsg()),
];
$details = $problem->getDetails();
if (is_array($details)) {
$errors_row = [];
$success_row = [];
if (isset($details['errors'])) {
foreach ($details['errors'] as $key => $value) {
$errors_row[] = "✗ {$key} → {$value}";
}
}
if (isset($details['success'])) {
foreach ($details['success'] as $key => $value) {
$success_row[] = "✔ {$key} → {$value}";
}
}
foreach($errors_row as $e_row) {
$rows[] = ['', new TableCell($e_row, array('colspan' => 3)), ];
}
foreach($success_row as $e_row) {
$rows[] = ['', new TableCell($e_row, array('colspan' => 3)), ];
}
}
}
if (!empty($rows)) {
$table->setHeaders($headers);
$table->setRows($rows);
$table->render();
} else {
$io->text('did not find anything to check...');
}
return 0;
}
}