Skip to content

Commit 5c52e4f

Browse files
committed
fix: small adjustments
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
1 parent c636917 commit 5c52e4f

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

lib/Migration/Version032002Date20250527174907.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
6262
$qbSelect = $this->connection->getQueryBuilder();
6363
$qbSelect->select(['id', 'configvalue'])
6464
->from('appconfig_ex')
65-
->where($qbSelect->expr()->eq('sensitive', $qbSelect->createNamedParameter(1)));
65+
->where($qbSelect->expr()->eq('sensitive', $qbSelect->createNamedParameter(1, Types::SMALLINT)));
6666
$req = $qbSelect->executeQuery();
6767

6868
while ($row = $req->fetch()) {
@@ -74,7 +74,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
7474
$qbUpdate->update('appconfig_ex')
7575
->set('configvalue', $qbUpdate->createNamedParameter($encryptedValue))
7676
->where(
77-
$qbUpdate->expr()->eq('id', $qbUpdate->createNamedParameter($row['id']))
77+
$qbUpdate->expr()->eq('id', $qbUpdate->createNamedParameter($row['id'], Types::INTEGER))
7878
);
7979
$qbUpdate->executeStatement();
8080
} catch (\Exception $e) {

lib/Service/ExAppConfigService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ public function getAppConfigValues(string $appId, array $configKeys): ?array {
5454

5555
public function setAppConfigValue(string $appId, string $configKey, mixed $configValue, ?int $sensitive = null): ?ExAppConfig {
5656
$appConfigEx = $this->getAppConfig($appId, $configKey);
57-
if ($sensitive) {
57+
if ($configValue !== '' && $sensitive) {
5858
try {
5959
$encryptedValue = $this->crypto->encrypt($configValue);
6060
} catch (\Exception $e) {
6161
$this->logger->error(sprintf('Failed to encrypt sensitive value for app %s, config key %s. Error: %s', $appId, $configKey, $e->getMessage()), ['exception' => $e]);
6262
return null;
6363
}
64+
} else {
65+
$encryptedValue = '';
6466
}
6567
if ($appConfigEx === null) {
6668
try {
6769
$appConfigEx = $this->mapper->insert(new ExAppConfig([
6870
'appid' => $appId,
6971
'configkey' => $configKey,
70-
'configvalue' => $sensitive ? $encryptedValue ?? '' : $configValue ?? '',
72+
'configvalue' => $sensitive ? $encryptedValue : $configValue ?? '',
7173
'sensitive' => $sensitive ?? 0,
7274
]));
7375
} catch (Exception $e) {
@@ -85,6 +87,7 @@ public function setAppConfigValue(string $appId, string $configKey, mixed $confi
8587
}
8688
}
8789
if ($sensitive) {
90+
// setting original unencrypted value for API
8891
$appConfigEx->setConfigvalue($configValue);
8992
}
9093
return $appConfigEx;

lib/Service/ExAppPreferenceService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,23 @@ public function setUserConfigValue(string $userId, string $appId, string $config
3636
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception) {
3737
$exAppPreference = null;
3838
}
39-
if ($sensitive) {
39+
if ($configValue !== '' && $sensitive) {
4040
try {
4141
$encryptedValue = $this->crypto->encrypt($configValue);
4242
} catch (\Exception $e) {
4343
$this->logger->error('Failed to encrypt sensitive value: ' . $e->getMessage(), ['exception' => $e]);
4444
return null;
4545
}
46+
} else {
47+
$encryptedValue = '';
4648
}
4749
if ($exAppPreference === null) {
4850
try {
4951
return $this->mapper->insert(new ExAppPreference([
5052
'userid' => $userId,
5153
'appid' => $appId,
5254
'configkey' => $configKey,
53-
'configvalue' => $sensitive ? $encryptedValue ?? '' : $configValue ?? '',
55+
'configvalue' => $sensitive ? $encryptedValue : $configValue ?? '',
5456
'sensitive' => $sensitive ?? 0,
5557
]));
5658
} catch (Exception $e) {
@@ -73,6 +75,7 @@ public function setUserConfigValue(string $userId, string $appId, string $config
7375
}
7476
}
7577
if ($sensitive) {
78+
// setting original unencrypted value for API
7679
$exAppPreference->setConfigvalue($configValue);
7780
}
7881
return $exAppPreference;

0 commit comments

Comments
 (0)