diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3680b84bad..05a0aab2c1 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -12,6 +12,7 @@ use OCA\Circles\Events\CircleDestroyedEvent; use OCA\Circles\Events\EditingCircleEvent; use OCA\Collectives\CacheListener; +use OCA\Collectives\ConfigLexicon; use OCA\Collectives\Dashboard\RecentPagesWidget; use OCA\Collectives\Db\CollectiveMapper; use OCA\Collectives\Db\CollectiveVersionMapper; @@ -86,6 +87,8 @@ public function register(IRegistrationContext $context): void { $context->registerMiddleware(PublicOCSMiddleware::class); + $context->registerConfigLexicon(ConfigLexicon::class); + $context->registerService(MountProvider::class, fn (ContainerInterface $c) => new MountProvider( $c->get(CollectiveHelper::class), $c->get(CollectiveFolderManager::class), diff --git a/lib/ConfigLexicon.php b/lib/ConfigLexicon.php new file mode 100644 index 0000000000..b8fe4f09a2 --- /dev/null +++ b/lib/ConfigLexicon.php @@ -0,0 +1,97 @@ +appConfig->getValueString('collectives', 'default_user_folder', ''); + $defaultUserFolder = $this->appConfig->getValueString('collectives', ConfigLexicon::DEFAULT_USER_FOLDER, ''); // Get collectives user folder from settings and default to translated 'Collectives' - $userCollectivesPath = $this->userConfig->getValueString($userId, 'collectives', 'user_folder', $defaultUserFolder); + $userCollectivesPath = $this->userConfig->getValueString($userId, 'collectives', ConfigLexicon::USER_FOLDER, $defaultUserFolder); if ($userCollectivesPath === '') { $user = $this->userManager->get($userId); $userLang = $this->l10nFactory->getUserLanguage($user); $l10n = $this->l10nFactory->get('collectives', $userLang); $userCollectivesPath = DIRECTORY_SEPARATOR . '.' . $l10n->t('Collectives'); - $this->userConfig->setValueString($userId, 'collectives', 'user_folder', $userCollectivesPath); + $this->userConfig->setValueString($userId, 'collectives', ConfigLexicon::USER_FOLDER, $userCollectivesPath); } return $userCollectivesPath; diff --git a/lib/Service/CollectiveGarbageCollector.php b/lib/Service/CollectiveGarbageCollector.php index 88f1ad744e..c9b6fc64ba 100644 --- a/lib/Service/CollectiveGarbageCollector.php +++ b/lib/Service/CollectiveGarbageCollector.php @@ -9,6 +9,7 @@ namespace OCA\Collectives\Service; +use OCA\Collectives\ConfigLexicon; use OCA\Collectives\Db\Collective; use OCA\Collectives\Db\CollectiveMapper; use OCP\AppFramework\Utility\ITimeFactory; @@ -16,7 +17,6 @@ use Psr\Log\LoggerInterface; class CollectiveGarbageCollector { - private const CONFIG_KEY = 'orphaned_collectives'; // Collectives need to be orphaned for at least a week before they get purged public const GRACE_PERIOD = 60 * 60 * 24 * 7; @@ -58,7 +58,7 @@ public function purgeOrphanedCollectives(): int { } /** @var array $previouslyOrphaned */ - $previouslyOrphaned = $this->appConfig->getValueArray('collectives', self::CONFIG_KEY, lazy: true); + $previouslyOrphaned = $this->appConfig->getValueArray('collectives', ConfigLexicon::ORPHANED_COLLECTIVES, lazy: true); $now = $this->timeFactory->getTime(); $stillOrphaned = []; $purgeCount = 0; @@ -85,7 +85,7 @@ public function purgeOrphanedCollectives(): int { } // Only keep collectives that were orphaned in this run - $this->appConfig->setValueArray('collectives', self::CONFIG_KEY, $stillOrphaned, lazy: true); + $this->appConfig->setValueArray('collectives', ConfigLexicon::ORPHANED_COLLECTIVES, $stillOrphaned, lazy: true); return $purgeCount; } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 0344b496d8..c50a53d483 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -10,6 +10,7 @@ namespace OCA\Collectives\Settings; use OCA\Collectives\AppInfo\Application; +use OCA\Collectives\ConfigLexicon; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\IAppConfig; @@ -25,7 +26,7 @@ public function __construct( public function getForm(): TemplateResponse { $parameters = [ - 'default_user_folder' => $this->appConfig->getValueString('collectives', 'default_user_folder', ''), + 'default_user_folder' => $this->appConfig->getValueString('collectives', ConfigLexicon::DEFAULT_USER_FOLDER, ''), ]; $this->initialState->provideInitialState('adminSettings', $parameters); diff --git a/tests/Unit/ConfigLexiconTest.php b/tests/Unit/ConfigLexiconTest.php new file mode 100644 index 0000000000..f8663a721e --- /dev/null +++ b/tests/Unit/ConfigLexiconTest.php @@ -0,0 +1,38 @@ +lexicon = new ConfigLexicon(); + } + + public function testAppConfigKeysAreUnique(): void { + $keys = array_map(static fn (Entry $e) => $e->getKey(), $this->lexicon->getAppConfigs()); + self::assertSame(array_unique($keys), $keys); + } + + public function testUserFolderHasNoLexiconDefault(): void { + $entries = array_filter( + $this->lexicon->getUserConfigs(), + static fn (Entry $e) => $e->getKey() === ConfigLexicon::USER_FOLDER, + ); + self::assertCount(1, $entries); + self::assertNull(array_values($entries)[0]->getDefault(Preset::NONE)); + } +}