mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-17 21:12:16 +01:00
92 lines
2.3 KiB
PHP
92 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OCA\Libresign\Command\Configure;
|
|
|
|
use OC\Core\Command\Base;
|
|
use OCA\Libresign\Service\Install\ConfigureCheckService;
|
|
use OCP\IConfig;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Symfony\Component\Console\Helper\TableCell;
|
|
use Symfony\Component\Console\Helper\TableCellStyle;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class Check extends Base {
|
|
private ConfigureCheckService $configureCheckService;
|
|
|
|
public function __construct(
|
|
ConfigureCheckService $configureCheckService,
|
|
private IConfig $config,
|
|
) {
|
|
parent::__construct();
|
|
$this->configureCheckService = $configureCheckService;
|
|
}
|
|
|
|
protected function configure(): void {
|
|
$this
|
|
->setName('libresign:configure:check')
|
|
->setDescription('Check configure')
|
|
->addOption(
|
|
name: 'sign',
|
|
shortcut: 's',
|
|
mode: InputOption::VALUE_NONE,
|
|
description: 'Check requirements to sign document'
|
|
)
|
|
->addOption(
|
|
name: 'certificate',
|
|
shortcut: 'c',
|
|
mode: InputOption::VALUE_NONE,
|
|
description: 'Check requirements to use root certificate'
|
|
);
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
|
$sign = $input->getOption('sign');
|
|
$certificate = $input->getOption('certificate');
|
|
$all = (!$sign && !$certificate);
|
|
|
|
$result = [];
|
|
if ($all) {
|
|
$result = $this->configureCheckService->checkAll();
|
|
} else {
|
|
if ($sign) {
|
|
$result = array_merge($result, $this->configureCheckService->checkSign());
|
|
}
|
|
if ($certificate) {
|
|
$result = array_merge($result, $this->configureCheckService->checkCertificate());
|
|
}
|
|
}
|
|
|
|
if (count($result)) {
|
|
$table = new Table($output);
|
|
foreach ($result as $row) {
|
|
$table->addRow([
|
|
new TableCell($row->getStatus(), ['style' => new TableCellStyle([
|
|
'bg' => $row->getStatus() === 'success' ? 'green' : 'red',
|
|
'align' => 'center',
|
|
])]),
|
|
$row->getResource(),
|
|
$row->getMessage(),
|
|
$row->getTip(),
|
|
]);
|
|
}
|
|
$table
|
|
->setHeaders([
|
|
'Status',
|
|
'Resource',
|
|
'Message',
|
|
'Tip',
|
|
])
|
|
->setStyle('symfony-style-guide')
|
|
->render();
|
|
}
|
|
return 0;
|
|
}
|
|
}
|