1313use OC \Installer ;
1414use OCP \App \AppPathNotFoundException ;
1515use OCP \App \IAppManager ;
16+ use OCP \Config \IUserConfig ;
1617use OCP \Config \Lexicon \Preset ;
1718use OCP \Exceptions \AppConfigUnknownKeyException ;
1819use OCP \IAppConfig ;
@@ -65,7 +66,7 @@ public function getLexiconPreset(): Preset {
6566 *
6667 * **Warning** This method MUST be considered resource-needy!
6768 *
68- * @return array<string, list<array{defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>>
69+ * @return array<string, list<array{config: string, defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>>
6970 */
7071 public function retrieveLexiconPreset (?string $ appId = null ): array {
7172 if ($ appId === null ) {
@@ -77,17 +78,41 @@ public function retrieveLexiconPreset(?string $appId = null): array {
7778 return $ apps ;
7879 }
7980
80- /** @var AppConfig|null $appConfig */
81- $ appConfig = Server::get (IAppConfig::class);
82- $ lexicon = $ appConfig ->getConfigDetailsFromLexicon ($ appId );
81+ return [
82+ $ appId => array_merge (
83+ $ this ->extractLexiconPresetFromConfigClass ($ appId , 'app ' , Server::get (IAppConfig::class)),
84+ $ this ->extractLexiconPresetFromConfigClass ($ appId , 'user ' , Server::get (IUserConfig::class))
85+ ),
86+ ];
87+ }
88+
89+ /**
90+ * @param string $appId
91+ *
92+ * @return list<array{config: string, defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>
93+ */
94+ private function extractLexiconPresetFromConfigClass (
95+ string $ appId ,
96+ string $ configType ,
97+ AppConfig |UserConfig $ config ,
98+ ): array {
8399 $ presets = [];
100+ $ lexicon = $ config ->getConfigDetailsFromLexicon ($ appId );
84101 foreach ($ lexicon ['entries ' ] as $ entry ) {
85102 $ defaults = [];
86103 foreach (Preset::cases () as $ case ) {
87104 // for each case, we need to use a fresh IAppConfig with clear cache
88105 // cloning to avoid conflict while emulating preset
89- $ newConfig = clone $ appConfig ;
90- $ newConfig ->clearCache (); // needed to ignore cache and rebuild default
106+ $ newConfig = clone $ config ;
107+ if ($ newConfig instanceof AppConfig) {
108+ // needed to ignore cache and rebuild default
109+ $ newConfig ->clearCache ();
110+ }
111+ if ($ newConfig instanceof UserConfig) {
112+ // in the case of IUserConfig, clear all users' cache
113+ $ newConfig ->clearCacheAll ();
114+ }
115+
91116 $ newLexicon = $ newConfig ->getLexiconEntry ($ appId , $ entry ->getKey ());
92117 $ defaults [$ case ->name ] = $ newLexicon ?->getDefault($ case );
93118 }
@@ -99,6 +124,7 @@ public function retrieveLexiconPreset(?string $appId = null): array {
99124 }
100125
101126 $ details = [
127+ 'config ' => $ configType ,
102128 'entry ' => [
103129 'key ' => $ entry ->getKey (),
104130 'type ' => $ entry ->getValueType ()->name ,
@@ -111,14 +137,17 @@ public function retrieveLexiconPreset(?string $appId = null): array {
111137 ];
112138
113139 try {
114- $ details ['value ' ] = $ appConfig ->getDetails ($ appId , $ entry ->getKey ())['value ' ];
140+ // not interested if a users config value is already set
141+ if ($ config instanceof AppConfig) {
142+ $ details ['value ' ] = $ config ->getDetails ($ appId , $ entry ->getKey ())['value ' ];
143+ }
115144 } catch (AppConfigUnknownKeyException ) {
116145 }
117146
118147 $ presets [] = $ details ;
119148 }
120149
121- return [ $ appId => $ presets] ;
150+ return $ presets ;
122151 }
123152
124153 /**
0 commit comments