Skip to content

Commit 465d754

Browse files
fix(migration): repair corrupted signature dimension values in app config
postSchemaChange reads the stored signature_width and signature_height values and replaces any that are non-finite or below SIGNATURE_DIMENSION_MINIMUM with their respective defaults, emitting a warning message for each replaced value. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent b26cff4 commit 465d754

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\Migration;
11+
12+
use Closure;
13+
use OCA\Libresign\AppInfo\Application;
14+
use OCA\Libresign\Service\SignatureTextService;
15+
use OCP\DB\ISchemaWrapper;
16+
use OCP\IAppConfig;
17+
use OCP\Migration\IOutput;
18+
use OCP\Migration\SimpleMigrationStep;
19+
20+
class Version17003Date20260404000000 extends SimpleMigrationStep {
21+
public function __construct(
22+
private IAppConfig $appConfig,
23+
) {
24+
}
25+
26+
/**
27+
* @param IOutput $output
28+
* @param Closure(): ISchemaWrapper $schemaClosure
29+
* @param array $options
30+
*/
31+
#[\Override]
32+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
33+
$this->sanitizeDimension(
34+
$output,
35+
'signature_width',
36+
SignatureTextService::DEFAULT_SIGNATURE_WIDTH,
37+
);
38+
$this->sanitizeDimension(
39+
$output,
40+
'signature_height',
41+
SignatureTextService::DEFAULT_SIGNATURE_HEIGHT,
42+
);
43+
}
44+
45+
private function sanitizeDimension(IOutput $output, string $key, float $default): void {
46+
$stored = $this->appConfig->getValueFloat(Application::APP_ID, $key, $default);
47+
if (is_finite($stored) && $stored >= SignatureTextService::SIGNATURE_DIMENSION_MINIMUM) {
48+
return;
49+
}
50+
51+
$this->appConfig->setValueFloat(Application::APP_ID, $key, $default);
52+
$output->warning(sprintf(
53+
'Restored invalid "%s" value "%s" to default "%s".',
54+
$key,
55+
(string)$stored,
56+
(string)$default,
57+
));
58+
}
59+
}

0 commit comments

Comments
 (0)