99namespace OCA \Libresign \Migration ;
1010
1111use OCA \Libresign \AppInfo \Application ;
12+ use OCP \DB \QueryBuilder \IQueryBuilder ;
1213use OCP \IAppConfig ;
14+ use OCP \IConfig ;
15+ use OCP \IDBConnection ;
1316use OCP \Migration \IOutput ;
1417use OCP \Migration \SimpleMigrationStep ;
1518
2023 * - telegram → telegramToken
2124 * - whatsapp → whatsappToken
2225 * - xmpp → xmppToken
26+ *
27+ * Also migrate files list config keys to use prefixed naming:
28+ * - grid_view → files_list_grid_view
29+ * - signer_identify_tab → files_list_signer_identify_tab
30+ * - sorting_mode → files_list_sorting_mode
31+ * - sorting_direction → files_list_sorting_direction
32+ * - filter_modified → files_list_filter_modified
33+ * - filter_status → files_list_filter_status
2334 */
2435class Version17001Date20260210000000 extends SimpleMigrationStep {
2536 private const LEGACY_MAPPING = [
@@ -30,8 +41,19 @@ class Version17001Date20260210000000 extends SimpleMigrationStep {
3041 'xmpp ' => 'xmppToken ' ,
3142 ];
3243
44+ private const USER_CONFIG_MIGRATIONS = [
45+ 'grid_view ' => 'files_list_grid_view ' ,
46+ 'signer_identify_tab ' => 'files_list_signer_identify_tab ' ,
47+ 'sorting_mode ' => 'files_list_sorting_mode ' ,
48+ 'sorting_direction ' => 'files_list_sorting_direction ' ,
49+ 'filter_modified ' => 'files_list_filter_modified ' ,
50+ 'filter_status ' => 'files_list_filter_status ' ,
51+ ];
52+
3353 public function __construct (
3454 private IAppConfig $ appConfig ,
55+ private IConfig $ config ,
56+ private IDBConnection $ db ,
3557 ) {
3658 }
3759
@@ -91,5 +113,47 @@ function ($methodName) use (&$updated) {
91113 $ this ->appConfig ->setValueArray (Application::APP_ID , 'identify_methods ' , $ identifyMethods );
92114 $ output ->info ('Updated signature method names to new format with Token suffix ' );
93115 }
116+
117+ $ this ->migrateUserConfigs ($ output );
118+ }
119+
120+ private function migrateUserConfigs (IOutput $ output ): void {
121+ $ oldKeys = array_keys (self ::USER_CONFIG_MIGRATIONS );
122+ $ query = $ this ->db ->getQueryBuilder ();
123+ $ query ->selectDistinct ('userid ' )
124+ ->from ('preferences ' )
125+ ->where ($ query ->expr ()->eq ('appid ' , $ query ->createNamedParameter (Application::APP_ID )))
126+ ->andWhere ($ query ->expr ()->in ('configkey ' , $ query ->createNamedParameter ($ oldKeys , IQueryBuilder::PARAM_STR_ARRAY )));
127+
128+ $ result = $ query ->executeQuery ();
129+ $ userIds = $ result ->fetchAll (\PDO ::FETCH_COLUMN );
130+
131+ if (empty ($ userIds )) {
132+ return ;
133+ }
134+
135+ $ migratedCount = 0 ;
136+ $ output ->info ('Migrating files list config keys for ' . count ($ userIds ) . ' users... ' );
137+
138+ foreach ($ userIds as $ userId ) {
139+ foreach (self ::USER_CONFIG_MIGRATIONS as $ oldKey => $ newKey ) {
140+ $ oldValue = $ this ->config ->getUserValue ($ userId , Application::APP_ID , $ oldKey , null );
141+ $ newValue = $ this ->config ->getUserValue ($ userId , Application::APP_ID , $ newKey , null );
142+
143+ // If old key has a value and new key is empty, migrate
144+ if ($ oldValue !== null && $ oldValue !== '' && ($ newValue === null || $ newValue === '' )) {
145+ $ this ->config ->setUserValue ($ userId , Application::APP_ID , $ newKey , $ oldValue );
146+ $ this ->config ->deleteUserValue ($ userId , Application::APP_ID , $ oldKey );
147+ $ migratedCount ++;
148+ } elseif ($ oldValue !== null && $ oldValue !== '' && $ newValue !== null && $ newValue !== '' ) {
149+ // Both exist, just delete the old one
150+ $ this ->config ->deleteUserValue ($ userId , Application::APP_ID , $ oldKey );
151+ }
152+ }
153+ }
154+
155+ if ($ migratedCount > 0 ) {
156+ $ output ->info ("Migrated $ migratedCount config keys to new prefixed format " );
157+ }
94158 }
95159}
0 commit comments