Skip to content

Commit 66fb882

Browse files
feat(setup-check): add JSignPdfSetupCheck
Adds JSignPdfSetupCheck to verify JSignPdf binary, integrity, Java dependency and version. Related issue: #6590 Type: Feature Checklist: - [x] Implement ISetupCheck interface - [x] Use SetupCheckUtils trait - [x] Verify JSignPdf path is configured and exists - [x] Verify Java is available - [x] Check JSignPdf version against required version - [x] Return SetupResult with appropriate severity and translated messages - [x] Add unit tests covering all scenarios
1 parent 75a87aa commit 66fb882

2 files changed

Lines changed: 458 additions & 0 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Libresign\SetupCheck;
10+
11+
use OCA\Libresign\Helper\JavaHelper;
12+
use OCA\Libresign\AppInfo\Application;
13+
use OCA\Libresign\Handler\SignEngine\JSignPdfHandler;
14+
use OCA\Libresign\Service\Install\SignSetupService;
15+
use OCA\Libresign\Service\Install\InstallService;
16+
use OCP\IL10N;
17+
use OCP\IAppConfig;
18+
use OCP\IURLGenerator;
19+
use OCP\App\IAppManager;
20+
use OCP\SetupCheck\ISetupCheck;
21+
use OCP\SetupCheck\SetupResult;
22+
use OCP\IConfig;
23+
use Psr\Log\LoggerInterface;
24+
25+
class JSignPdfSetupCheck implements ISetupCheck
26+
{
27+
use SetupCheckUtils;
28+
29+
private IL10N $l10n;
30+
private IAppConfig $appConfig;
31+
private JSignPdfHandler $jSignPdfHandler;
32+
private IConfig $systemConfig;
33+
private JavaHelper $javaHelper;
34+
35+
private SignSetupService $signSetupService;
36+
private IURLGenerator $urlGenerator;
37+
private IAppManager $appManager;
38+
private LoggerInterface $logger;
39+
40+
public function __construct(
41+
IL10N $l10n,
42+
IAppConfig $appConfig,
43+
JSignPdfHandler $jSignPdfHandler,
44+
SignSetupService $signSetupService,
45+
IURLGenerator $urlGenerator,
46+
IAppManager $appManager,
47+
LoggerInterface $logger,
48+
IConfig $systemConfig,
49+
JavaHelper $javaHelper
50+
) {
51+
$this->l10n = $l10n;
52+
$this->appConfig = $appConfig;
53+
$this->jSignPdfHandler = $jSignPdfHandler;
54+
$this->signSetupService = $signSetupService;
55+
$this->urlGenerator = $urlGenerator;
56+
$this->appManager = $appManager;
57+
$this->logger = $logger;
58+
$this->systemConfig = $systemConfig;
59+
$this->javaHelper = $javaHelper;
60+
}
61+
62+
public function getName(): string
63+
{
64+
return $this->l10n->t('JSignPdf');
65+
}
66+
67+
public function getCategory(): string
68+
{
69+
return 'system';
70+
}
71+
72+
public function run(): SetupResult
73+
{
74+
$debugEnabled = $this->systemConfig->getSystemValueBool('debug', false);
75+
$jsignpdfJarPath = $this->appConfig->getValueString(Application::APP_ID, 'jsignpdf_jar_path');
76+
77+
if (!$jsignpdfJarPath) {
78+
return SetupResult::error(
79+
$this->l10n->t('JSignPdf not found'),
80+
$this->l10n->t('Run occ libresign:install --jsignpdf')
81+
);
82+
}
83+
84+
$verifyResult = $this->verifyResourceIntegrity('jsignpdf', $debugEnabled);
85+
if (!empty($verifyResult)) {
86+
[$errorMsg, $tip] = $this->getErrorAndTipFromVerify($verifyResult, 'jsignpdf', $debugEnabled, $this->l10n);
87+
return SetupResult::error($errorMsg, $tip);
88+
}
89+
90+
if (!file_exists($jsignpdfJarPath)) {
91+
return SetupResult::error(
92+
$this->l10n->t('JSignPdf binary not found: %s', [$jsignpdfJarPath]),
93+
$this->l10n->t('Run occ libresign:install --jsignpdf')
94+
);
95+
}
96+
97+
$javaPath = $this->javaHelper->getJavaPath();
98+
if (!$javaPath || !file_exists($javaPath)) {
99+
return SetupResult::error(
100+
$this->l10n->t('Necessary Java to run JSignPdf'),
101+
$this->l10n->t('Run occ libresign:install --java')
102+
);
103+
}
104+
105+
$jsignPdf = $this->jSignPdfHandler->getJSignPdf();
106+
$jsignPdf->setParam($this->jSignPdfHandler->getJSignParam());
107+
$currentVersion = $jsignPdf->getVersion();
108+
109+
if (!$currentVersion) {
110+
$msg = $this->l10n->t('Necessary install the version %s', [InstallService::JSIGNPDF_VERSION]);
111+
return SetupResult::error($msg, $this->l10n->t('Run occ libresign:install --jsignpdf'));
112+
}
113+
114+
if (version_compare($currentVersion, InstallService::JSIGNPDF_VERSION, '<')) {
115+
$msg = $this->l10n->t('Necessary bump JSignPdf version from %s to %s', [$currentVersion, InstallService::JSIGNPDF_VERSION]);
116+
return SetupResult::error($msg, $this->l10n->t('Run occ libresign:install --jsignpdf'));
117+
}
118+
119+
if (version_compare($currentVersion, InstallService::JSIGNPDF_VERSION, '>')) {
120+
return SetupResult::error(
121+
$this->l10n->t('Necessary downgrade JSignPdf version from %s to %s', [$currentVersion, InstallService::JSIGNPDF_VERSION]),
122+
$this->l10n->t('Run occ libresign:install --jsignpdf')
123+
);
124+
}
125+
126+
$messages = [
127+
$this->l10n->t('JSignPdf version: %s', [$currentVersion]),
128+
$this->l10n->t('JSignPdf path: %s', [$jsignpdfJarPath])
129+
];
130+
131+
return SetupResult::success(implode("\n", $messages));
132+
}
133+
}

0 commit comments

Comments
 (0)