Skip to content

Commit beb8860

Browse files
committed
feat(migration): migrate legacy signature_flow policy keys
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 9ccc906 commit beb8860

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Migration;
10+
11+
use Closure;
12+
use OCA\Libresign\AppInfo\Application;
13+
use OCA\Libresign\Service\Policy\Provider\Signature\SignatureFlowPolicy;
14+
use OCP\DB\ISchemaWrapper;
15+
use OCP\IAppConfig;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
19+
class Version18001Date20260320000000 extends SimpleMigrationStep {
20+
private const LEGACY_SYSTEM_KEY = SignatureFlowPolicy::KEY;
21+
private const LEGACY_ALLOW_CHILD_OVERRIDE_KEY = SignatureFlowPolicy::KEY . '.allow_child_override';
22+
private const SYSTEM_ALLOW_CHILD_OVERRIDE_SUFFIX = '.allow_child_override';
23+
24+
public function __construct(
25+
private IAppConfig $appConfig,
26+
) {
27+
}
28+
29+
#[\Override]
30+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
31+
$newSystemKey = SignatureFlowPolicy::SYSTEM_APP_CONFIG_KEY;
32+
$newAllowChildOverrideKey = $newSystemKey . self::SYSTEM_ALLOW_CHILD_OVERRIDE_SUFFIX;
33+
34+
$legacySystemValue = $this->appConfig->getValueString(Application::APP_ID, self::LEGACY_SYSTEM_KEY, '');
35+
$newSystemValue = $this->appConfig->getValueString(Application::APP_ID, $newSystemKey, '');
36+
if ($legacySystemValue !== '' && $newSystemValue === '') {
37+
$this->appConfig->setValueString(Application::APP_ID, $newSystemKey, $legacySystemValue);
38+
}
39+
40+
$legacyAllowOverrideValue = $this->appConfig->getValueString(Application::APP_ID, self::LEGACY_ALLOW_CHILD_OVERRIDE_KEY, '');
41+
$newAllowOverrideValue = $this->appConfig->getValueString(Application::APP_ID, $newAllowChildOverrideKey, '');
42+
if ($legacyAllowOverrideValue !== '' && $newAllowOverrideValue === '') {
43+
$this->appConfig->setValueString(Application::APP_ID, $newAllowChildOverrideKey, $legacyAllowOverrideValue);
44+
}
45+
46+
$this->appConfig->deleteKey(Application::APP_ID, self::LEGACY_SYSTEM_KEY);
47+
$this->appConfig->deleteKey(Application::APP_ID, self::LEGACY_ALLOW_CHILD_OVERRIDE_KEY);
48+
}
49+
50+
#[\Override]
51+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
52+
return null;
53+
}
54+
}

0 commit comments

Comments
 (0)