feat(config): return whether a user config was actually deleted

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2025-07-16 12:24:25 +02:00
parent e22914b5ff
commit 9b1c404ba3
No known key found for this signature in database
GPG key ID: CC42AC2A7F0E56D8
3 changed files with 11 additions and 4 deletions

View file

@ -1539,10 +1539,11 @@ class UserConfig implements IUserConfig {
* @param string $userId id of the user
* @param string $app id of the app
* @param string $key config key
* @return bool whether the value was deleted
*
* @since 31.0.0
*/
public function deleteUserConfig(string $userId, string $app, string $key): void {
public function deleteUserConfig(string $userId, string $app, string $key): bool {
$this->assertParams($userId, $app, $key);
$this->matchAndApplyLexiconDefinition($userId, $app, $key);
@ -1551,11 +1552,13 @@ class UserConfig implements IUserConfig {
->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId)))
->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter($app)))
->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key)));
$qb->executeStatement();
$affectedRows = $qb->executeStatement();
unset($this->lazyCache[$userId][$app][$key]);
unset($this->fastCache[$userId][$app][$key]);
unset($this->valueDetails[$userId][$app][$key]);
return $affectedRows > 0;
}
/**

View file

@ -687,10 +687,11 @@ interface IUserConfig {
* @param string $userId id of the user
* @param string $app id of the app
* @param string $key config key
* @return bool whether the value was deleted
*
* @experimental 31.0.0
*/
public function deleteUserConfig(string $userId, string $app, string $key): void;
public function deleteUserConfig(string $userId, string $app, string $key): bool;
/**
* Delete config values from all users linked to a specific config keys

View file

@ -1704,7 +1704,10 @@ class UserConfigTest extends TestCase {
$userConfig = $this->generateUserConfig($preload ?? []);
$this->assertEquals(true, $userConfig->hasKey($userId, $app, $key, $lazy));
$userConfig->deleteUserConfig($userId, $app, $key);
$deleted = $userConfig->deleteUserConfig($userId, $app, $key);
self::assertTrue($deleted, 'user config was deleted');
$deletedAgain = $userConfig->deleteUserConfig($userId, $app, $key);
self::assertFalse($deletedAgain, 'user config can not be deleted twice');
$this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, $lazy));
$userConfig = $this->generateUserConfig($preload ?? []);
$this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, $lazy));