Passed
Push — master ( 12ed5c...f4135c )
by Julius
17:07 queued 12s
created
core/Migrations/Version13000Date20170718121200.php 1 patch
Indentation   +949 added lines, -949 removed lines patch added patch discarded remove patch
@@ -40,857 +40,857 @@  discard block
 block discarded – undo
40 40
 
41 41
 class Version13000Date20170718121200 extends SimpleMigrationStep {
42 42
 
43
-	/** @var IDBConnection */
44
-	private $connection;
43
+    /** @var IDBConnection */
44
+    private $connection;
45 45
 
46
-	public function __construct(IDBConnection $connection) {
47
-		$this->connection = $connection;
48
-	}
46
+    public function __construct(IDBConnection $connection) {
47
+        $this->connection = $connection;
48
+    }
49 49
 
50
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
-		/** @var ISchemaWrapper $schema */
52
-		$schema = $schemaClosure();
50
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
+        /** @var ISchemaWrapper $schema */
52
+        $schema = $schemaClosure();
53 53
 
54
-		if (!$schema->hasTable('properties')) {
55
-			return;
56
-		}
57
-		// in case we have a properties table from oc we drop it since we will only migrate
58
-		// the dav_properties values in the postSchemaChange step
59
-		$table = $schema->getTable('properties');
60
-		if ($table->hasColumn('fileid')) {
61
-			$qb = $this->connection->getQueryBuilder();
62
-			$qb->delete('properties');
63
-			$qb->execute();
64
-		}
65
-	}
54
+        if (!$schema->hasTable('properties')) {
55
+            return;
56
+        }
57
+        // in case we have a properties table from oc we drop it since we will only migrate
58
+        // the dav_properties values in the postSchemaChange step
59
+        $table = $schema->getTable('properties');
60
+        if ($table->hasColumn('fileid')) {
61
+            $qb = $this->connection->getQueryBuilder();
62
+            $qb->delete('properties');
63
+            $qb->execute();
64
+        }
65
+    }
66 66
 
67 67
 
68
-	/**
69
-	 * @param IOutput $output
70
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
71
-	 * @param array $options
72
-	 * @return null|ISchemaWrapper
73
-	 * @since 13.0.0
74
-	 */
75
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
76
-		/** @var ISchemaWrapper $schema */
77
-		$schema = $schemaClosure();
68
+    /**
69
+     * @param IOutput $output
70
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
71
+     * @param array $options
72
+     * @return null|ISchemaWrapper
73
+     * @since 13.0.0
74
+     */
75
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
76
+        /** @var ISchemaWrapper $schema */
77
+        $schema = $schemaClosure();
78 78
 
79
-		if (!$schema->hasTable('appconfig')) {
80
-			$table = $schema->createTable('appconfig');
81
-			$table->addColumn('appid', 'string', [
82
-				'notnull' => true,
83
-				'length' => 32,
84
-				'default' => '',
85
-			]);
86
-			$table->addColumn('configkey', 'string', [
87
-				'notnull' => true,
88
-				'length' => 64,
89
-				'default' => '',
90
-			]);
91
-			$table->addColumn('configvalue', 'text', [
92
-				'notnull' => false,
93
-			]);
94
-			$table->setPrimaryKey(['appid', 'configkey']);
95
-			$table->addIndex(['configkey'], 'appconfig_config_key_index');
96
-			$table->addIndex(['appid'], 'appconfig_appid_key');
97
-		}
79
+        if (!$schema->hasTable('appconfig')) {
80
+            $table = $schema->createTable('appconfig');
81
+            $table->addColumn('appid', 'string', [
82
+                'notnull' => true,
83
+                'length' => 32,
84
+                'default' => '',
85
+            ]);
86
+            $table->addColumn('configkey', 'string', [
87
+                'notnull' => true,
88
+                'length' => 64,
89
+                'default' => '',
90
+            ]);
91
+            $table->addColumn('configvalue', 'text', [
92
+                'notnull' => false,
93
+            ]);
94
+            $table->setPrimaryKey(['appid', 'configkey']);
95
+            $table->addIndex(['configkey'], 'appconfig_config_key_index');
96
+            $table->addIndex(['appid'], 'appconfig_appid_key');
97
+        }
98 98
 
99
-		if (!$schema->hasTable('storages')) {
100
-			$table = $schema->createTable('storages');
101
-			$table->addColumn('id', 'string', [
102
-				'notnull' => false,
103
-				'length' => 64,
104
-			]);
105
-			$table->addColumn('numeric_id', Types::BIGINT, [
106
-				'autoincrement' => true,
107
-				'notnull' => true,
108
-				'length' => 20,
109
-			]);
110
-			$table->addColumn('available', 'integer', [
111
-				'notnull' => true,
112
-				'default' => 1,
113
-			]);
114
-			$table->addColumn('last_checked', 'integer', [
115
-				'notnull' => false,
116
-			]);
117
-			$table->setPrimaryKey(['numeric_id']);
118
-			$table->addUniqueIndex(['id'], 'storages_id_index');
119
-		}
99
+        if (!$schema->hasTable('storages')) {
100
+            $table = $schema->createTable('storages');
101
+            $table->addColumn('id', 'string', [
102
+                'notnull' => false,
103
+                'length' => 64,
104
+            ]);
105
+            $table->addColumn('numeric_id', Types::BIGINT, [
106
+                'autoincrement' => true,
107
+                'notnull' => true,
108
+                'length' => 20,
109
+            ]);
110
+            $table->addColumn('available', 'integer', [
111
+                'notnull' => true,
112
+                'default' => 1,
113
+            ]);
114
+            $table->addColumn('last_checked', 'integer', [
115
+                'notnull' => false,
116
+            ]);
117
+            $table->setPrimaryKey(['numeric_id']);
118
+            $table->addUniqueIndex(['id'], 'storages_id_index');
119
+        }
120 120
 
121
-		if (!$schema->hasTable('mounts')) {
122
-			$table = $schema->createTable('mounts');
123
-			$table->addColumn('id', 'integer', [
124
-				'autoincrement' => true,
125
-				'notnull' => true,
126
-				'length' => 4,
127
-			]);
128
-			$table->addColumn('storage_id', Types::BIGINT, [
129
-				'notnull' => true,
130
-				'length' => 20,
131
-			]);
132
-			$table->addColumn('root_id', Types::BIGINT, [
133
-				'notnull' => true,
134
-				'length' => 20,
135
-			]);
136
-			$table->addColumn('user_id', 'string', [
137
-				'notnull' => true,
138
-				'length' => 64,
139
-			]);
140
-			$table->addColumn('mount_point', 'string', [
141
-				'notnull' => true,
142
-				'length' => 4000,
143
-			]);
144
-			$table->addColumn('mount_id', Types::BIGINT, [
145
-				'notnull' => false,
146
-				'length' => 20,
147
-			]);
148
-			$table->setPrimaryKey(['id']);
149
-			$table->addIndex(['user_id'], 'mounts_user_index');
150
-			$table->addIndex(['storage_id'], 'mounts_storage_index');
151
-			$table->addIndex(['root_id'], 'mounts_root_index');
152
-			$table->addIndex(['mount_id'], 'mounts_mount_id_index');
153
-			$table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
154
-		} else {
155
-			$table = $schema->getTable('mounts');
156
-			$table->addColumn('mount_id', Types::BIGINT, [
157
-				'notnull' => false,
158
-				'length' => 20,
159
-			]);
160
-			if (!$table->hasIndex('mounts_mount_id_index')) {
161
-				$table->addIndex(['mount_id'], 'mounts_mount_id_index');
162
-			}
163
-		}
121
+        if (!$schema->hasTable('mounts')) {
122
+            $table = $schema->createTable('mounts');
123
+            $table->addColumn('id', 'integer', [
124
+                'autoincrement' => true,
125
+                'notnull' => true,
126
+                'length' => 4,
127
+            ]);
128
+            $table->addColumn('storage_id', Types::BIGINT, [
129
+                'notnull' => true,
130
+                'length' => 20,
131
+            ]);
132
+            $table->addColumn('root_id', Types::BIGINT, [
133
+                'notnull' => true,
134
+                'length' => 20,
135
+            ]);
136
+            $table->addColumn('user_id', 'string', [
137
+                'notnull' => true,
138
+                'length' => 64,
139
+            ]);
140
+            $table->addColumn('mount_point', 'string', [
141
+                'notnull' => true,
142
+                'length' => 4000,
143
+            ]);
144
+            $table->addColumn('mount_id', Types::BIGINT, [
145
+                'notnull' => false,
146
+                'length' => 20,
147
+            ]);
148
+            $table->setPrimaryKey(['id']);
149
+            $table->addIndex(['user_id'], 'mounts_user_index');
150
+            $table->addIndex(['storage_id'], 'mounts_storage_index');
151
+            $table->addIndex(['root_id'], 'mounts_root_index');
152
+            $table->addIndex(['mount_id'], 'mounts_mount_id_index');
153
+            $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
154
+        } else {
155
+            $table = $schema->getTable('mounts');
156
+            $table->addColumn('mount_id', Types::BIGINT, [
157
+                'notnull' => false,
158
+                'length' => 20,
159
+            ]);
160
+            if (!$table->hasIndex('mounts_mount_id_index')) {
161
+                $table->addIndex(['mount_id'], 'mounts_mount_id_index');
162
+            }
163
+        }
164 164
 
165
-		if (!$schema->hasTable('mimetypes')) {
166
-			$table = $schema->createTable('mimetypes');
167
-			$table->addColumn('id', Types::BIGINT, [
168
-				'autoincrement' => true,
169
-				'notnull' => true,
170
-				'length' => 20,
171
-			]);
172
-			$table->addColumn('mimetype', 'string', [
173
-				'notnull' => true,
174
-				'length' => 255,
175
-				'default' => '',
176
-			]);
177
-			$table->setPrimaryKey(['id']);
178
-			$table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
179
-		}
165
+        if (!$schema->hasTable('mimetypes')) {
166
+            $table = $schema->createTable('mimetypes');
167
+            $table->addColumn('id', Types::BIGINT, [
168
+                'autoincrement' => true,
169
+                'notnull' => true,
170
+                'length' => 20,
171
+            ]);
172
+            $table->addColumn('mimetype', 'string', [
173
+                'notnull' => true,
174
+                'length' => 255,
175
+                'default' => '',
176
+            ]);
177
+            $table->setPrimaryKey(['id']);
178
+            $table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
179
+        }
180 180
 
181
-		if (!$schema->hasTable('filecache')) {
182
-			$table = $schema->createTable('filecache');
183
-			$table->addColumn('fileid', Types::BIGINT, [
184
-				'autoincrement' => true,
185
-				'notnull' => true,
186
-				'length' => 20,
187
-			]);
188
-			$table->addColumn('storage', Types::BIGINT, [
189
-				'notnull' => true,
190
-				'length' => 20,
191
-				'default' => 0,
192
-			]);
193
-			$table->addColumn('path', 'string', [
194
-				'notnull' => false,
195
-				'length' => 4000,
196
-			]);
197
-			$table->addColumn('path_hash', 'string', [
198
-				'notnull' => true,
199
-				'length' => 32,
200
-				'default' => '',
201
-			]);
202
-			$table->addColumn('parent', Types::BIGINT, [
203
-				'notnull' => true,
204
-				'length' => 20,
205
-				'default' => 0,
206
-			]);
207
-			$table->addColumn('name', 'string', [
208
-				'notnull' => false,
209
-				'length' => 250,
210
-			]);
211
-			$table->addColumn('mimetype', Types::BIGINT, [
212
-				'notnull' => true,
213
-				'length' => 20,
214
-				'default' => 0,
215
-			]);
216
-			$table->addColumn('mimepart', Types::BIGINT, [
217
-				'notnull' => true,
218
-				'length' => 20,
219
-				'default' => 0,
220
-			]);
221
-			$table->addColumn('size', 'bigint', [
222
-				'notnull' => true,
223
-				'length' => 8,
224
-				'default' => 0,
225
-			]);
226
-			$table->addColumn('mtime', Types::BIGINT, [
227
-				'notnull' => true,
228
-				'length' => 20,
229
-				'default' => 0,
230
-			]);
231
-			$table->addColumn('storage_mtime', Types::BIGINT, [
232
-				'notnull' => true,
233
-				'length' => 20,
234
-				'default' => 0,
235
-			]);
236
-			$table->addColumn('encrypted', 'integer', [
237
-				'notnull' => true,
238
-				'length' => 4,
239
-				'default' => 0,
240
-			]);
241
-			$table->addColumn('unencrypted_size', 'bigint', [
242
-				'notnull' => true,
243
-				'length' => 8,
244
-				'default' => 0,
245
-			]);
246
-			$table->addColumn('etag', 'string', [
247
-				'notnull' => false,
248
-				'length' => 40,
249
-			]);
250
-			$table->addColumn('permissions', 'integer', [
251
-				'notnull' => false,
252
-				'length' => 4,
253
-				'default' => 0,
254
-			]);
255
-			$table->addColumn('checksum', 'string', [
256
-				'notnull' => false,
257
-				'length' => 255,
258
-			]);
259
-			$table->setPrimaryKey(['fileid']);
260
-			$table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
261
-			$table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
262
-			$table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
263
-			$table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
264
-			$table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
265
-			$table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
266
-			$table->addIndex(['mtime'], 'fs_mtime');
267
-			$table->addIndex(['size'], 'fs_size');
268
-			if (!$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
269
-				$table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
270
-			}
271
-		}
181
+        if (!$schema->hasTable('filecache')) {
182
+            $table = $schema->createTable('filecache');
183
+            $table->addColumn('fileid', Types::BIGINT, [
184
+                'autoincrement' => true,
185
+                'notnull' => true,
186
+                'length' => 20,
187
+            ]);
188
+            $table->addColumn('storage', Types::BIGINT, [
189
+                'notnull' => true,
190
+                'length' => 20,
191
+                'default' => 0,
192
+            ]);
193
+            $table->addColumn('path', 'string', [
194
+                'notnull' => false,
195
+                'length' => 4000,
196
+            ]);
197
+            $table->addColumn('path_hash', 'string', [
198
+                'notnull' => true,
199
+                'length' => 32,
200
+                'default' => '',
201
+            ]);
202
+            $table->addColumn('parent', Types::BIGINT, [
203
+                'notnull' => true,
204
+                'length' => 20,
205
+                'default' => 0,
206
+            ]);
207
+            $table->addColumn('name', 'string', [
208
+                'notnull' => false,
209
+                'length' => 250,
210
+            ]);
211
+            $table->addColumn('mimetype', Types::BIGINT, [
212
+                'notnull' => true,
213
+                'length' => 20,
214
+                'default' => 0,
215
+            ]);
216
+            $table->addColumn('mimepart', Types::BIGINT, [
217
+                'notnull' => true,
218
+                'length' => 20,
219
+                'default' => 0,
220
+            ]);
221
+            $table->addColumn('size', 'bigint', [
222
+                'notnull' => true,
223
+                'length' => 8,
224
+                'default' => 0,
225
+            ]);
226
+            $table->addColumn('mtime', Types::BIGINT, [
227
+                'notnull' => true,
228
+                'length' => 20,
229
+                'default' => 0,
230
+            ]);
231
+            $table->addColumn('storage_mtime', Types::BIGINT, [
232
+                'notnull' => true,
233
+                'length' => 20,
234
+                'default' => 0,
235
+            ]);
236
+            $table->addColumn('encrypted', 'integer', [
237
+                'notnull' => true,
238
+                'length' => 4,
239
+                'default' => 0,
240
+            ]);
241
+            $table->addColumn('unencrypted_size', 'bigint', [
242
+                'notnull' => true,
243
+                'length' => 8,
244
+                'default' => 0,
245
+            ]);
246
+            $table->addColumn('etag', 'string', [
247
+                'notnull' => false,
248
+                'length' => 40,
249
+            ]);
250
+            $table->addColumn('permissions', 'integer', [
251
+                'notnull' => false,
252
+                'length' => 4,
253
+                'default' => 0,
254
+            ]);
255
+            $table->addColumn('checksum', 'string', [
256
+                'notnull' => false,
257
+                'length' => 255,
258
+            ]);
259
+            $table->setPrimaryKey(['fileid']);
260
+            $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
261
+            $table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
262
+            $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
263
+            $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
264
+            $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
265
+            $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
266
+            $table->addIndex(['mtime'], 'fs_mtime');
267
+            $table->addIndex(['size'], 'fs_size');
268
+            if (!$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
269
+                $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
270
+            }
271
+        }
272 272
 
273
-		if (!$schema->hasTable('group_user')) {
274
-			$table = $schema->createTable('group_user');
275
-			$table->addColumn('gid', 'string', [
276
-				'notnull' => true,
277
-				'length' => 64,
278
-				'default' => '',
279
-			]);
280
-			$table->addColumn('uid', 'string', [
281
-				'notnull' => true,
282
-				'length' => 64,
283
-				'default' => '',
284
-			]);
285
-			$table->setPrimaryKey(['gid', 'uid']);
286
-			$table->addIndex(['uid'], 'gu_uid_index');
287
-		}
273
+        if (!$schema->hasTable('group_user')) {
274
+            $table = $schema->createTable('group_user');
275
+            $table->addColumn('gid', 'string', [
276
+                'notnull' => true,
277
+                'length' => 64,
278
+                'default' => '',
279
+            ]);
280
+            $table->addColumn('uid', 'string', [
281
+                'notnull' => true,
282
+                'length' => 64,
283
+                'default' => '',
284
+            ]);
285
+            $table->setPrimaryKey(['gid', 'uid']);
286
+            $table->addIndex(['uid'], 'gu_uid_index');
287
+        }
288 288
 
289
-		if (!$schema->hasTable('group_admin')) {
290
-			$table = $schema->createTable('group_admin');
291
-			$table->addColumn('gid', 'string', [
292
-				'notnull' => true,
293
-				'length' => 64,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('uid', 'string', [
297
-				'notnull' => true,
298
-				'length' => 64,
299
-				'default' => '',
300
-			]);
301
-			$table->setPrimaryKey(['gid', 'uid']);
302
-			$table->addIndex(['uid'], 'group_admin_uid');
303
-		}
289
+        if (!$schema->hasTable('group_admin')) {
290
+            $table = $schema->createTable('group_admin');
291
+            $table->addColumn('gid', 'string', [
292
+                'notnull' => true,
293
+                'length' => 64,
294
+                'default' => '',
295
+            ]);
296
+            $table->addColumn('uid', 'string', [
297
+                'notnull' => true,
298
+                'length' => 64,
299
+                'default' => '',
300
+            ]);
301
+            $table->setPrimaryKey(['gid', 'uid']);
302
+            $table->addIndex(['uid'], 'group_admin_uid');
303
+        }
304 304
 
305
-		if (!$schema->hasTable('groups')) {
306
-			$table = $schema->createTable('groups');
307
-			$table->addColumn('gid', 'string', [
308
-				'notnull' => true,
309
-				'length' => 64,
310
-				'default' => '',
311
-			]);
312
-			$table->setPrimaryKey(['gid']);
313
-		}
305
+        if (!$schema->hasTable('groups')) {
306
+            $table = $schema->createTable('groups');
307
+            $table->addColumn('gid', 'string', [
308
+                'notnull' => true,
309
+                'length' => 64,
310
+                'default' => '',
311
+            ]);
312
+            $table->setPrimaryKey(['gid']);
313
+        }
314 314
 
315
-		if (!$schema->hasTable('preferences')) {
316
-			$table = $schema->createTable('preferences');
317
-			$table->addColumn('userid', 'string', [
318
-				'notnull' => true,
319
-				'length' => 64,
320
-				'default' => '',
321
-			]);
322
-			$table->addColumn('appid', 'string', [
323
-				'notnull' => true,
324
-				'length' => 32,
325
-				'default' => '',
326
-			]);
327
-			$table->addColumn('configkey', 'string', [
328
-				'notnull' => true,
329
-				'length' => 64,
330
-				'default' => '',
331
-			]);
332
-			$table->addColumn('configvalue', 'text', [
333
-				'notnull' => false,
334
-			]);
335
-			$table->setPrimaryKey(['userid', 'appid', 'configkey']);
336
-			$table->addIndex(['appid', 'configkey'], 'preferences_app_key');
337
-		}
315
+        if (!$schema->hasTable('preferences')) {
316
+            $table = $schema->createTable('preferences');
317
+            $table->addColumn('userid', 'string', [
318
+                'notnull' => true,
319
+                'length' => 64,
320
+                'default' => '',
321
+            ]);
322
+            $table->addColumn('appid', 'string', [
323
+                'notnull' => true,
324
+                'length' => 32,
325
+                'default' => '',
326
+            ]);
327
+            $table->addColumn('configkey', 'string', [
328
+                'notnull' => true,
329
+                'length' => 64,
330
+                'default' => '',
331
+            ]);
332
+            $table->addColumn('configvalue', 'text', [
333
+                'notnull' => false,
334
+            ]);
335
+            $table->setPrimaryKey(['userid', 'appid', 'configkey']);
336
+            $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
337
+        }
338 338
 
339
-		if (!$schema->hasTable('properties')) {
340
-			$table = $schema->createTable('properties');
341
-			$table->addColumn('id', 'integer', [
342
-				'autoincrement' => true,
343
-				'notnull' => true,
344
-				'length' => 4,
345
-			]);
346
-			$table->addColumn('userid', 'string', [
347
-				'notnull' => true,
348
-				'length' => 64,
349
-				'default' => '',
350
-			]);
351
-			$table->addColumn('propertypath', 'string', [
352
-				'notnull' => true,
353
-				'length' => 255,
354
-				'default' => '',
355
-			]);
356
-			$table->addColumn('propertyname', 'string', [
357
-				'notnull' => true,
358
-				'length' => 255,
359
-				'default' => '',
360
-			]);
361
-			$table->addColumn('propertyvalue', 'text', [
362
-				'notnull' => true,
363
-			]);
364
-			$table->setPrimaryKey(['id']);
365
-			$table->addIndex(['userid'], 'property_index');
366
-			$table->addIndex(['userid', 'propertypath'], 'properties_path_index');
367
-			$table->addIndex(['propertypath'], 'properties_pathonly_index');
368
-		} else {
369
-			$table = $schema->getTable('properties');
370
-			if ($table->hasColumn('propertytype')) {
371
-				$table->dropColumn('propertytype');
372
-			}
373
-			if ($table->hasColumn('fileid')) {
374
-				$table->dropColumn('fileid');
375
-			}
376
-			if (!$table->hasColumn('propertypath')) {
377
-				$table->addColumn('propertypath', 'string', [
378
-					'notnull' => true,
379
-					'length' => 255,
380
-				]);
381
-			}
382
-			if (!$table->hasColumn('userid')) {
383
-				$table->addColumn('userid', 'string', [
384
-					'notnull' => false,
385
-					'length' => 64,
386
-					'default' => '',
387
-				]);
388
-			}
389
-		}
339
+        if (!$schema->hasTable('properties')) {
340
+            $table = $schema->createTable('properties');
341
+            $table->addColumn('id', 'integer', [
342
+                'autoincrement' => true,
343
+                'notnull' => true,
344
+                'length' => 4,
345
+            ]);
346
+            $table->addColumn('userid', 'string', [
347
+                'notnull' => true,
348
+                'length' => 64,
349
+                'default' => '',
350
+            ]);
351
+            $table->addColumn('propertypath', 'string', [
352
+                'notnull' => true,
353
+                'length' => 255,
354
+                'default' => '',
355
+            ]);
356
+            $table->addColumn('propertyname', 'string', [
357
+                'notnull' => true,
358
+                'length' => 255,
359
+                'default' => '',
360
+            ]);
361
+            $table->addColumn('propertyvalue', 'text', [
362
+                'notnull' => true,
363
+            ]);
364
+            $table->setPrimaryKey(['id']);
365
+            $table->addIndex(['userid'], 'property_index');
366
+            $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
367
+            $table->addIndex(['propertypath'], 'properties_pathonly_index');
368
+        } else {
369
+            $table = $schema->getTable('properties');
370
+            if ($table->hasColumn('propertytype')) {
371
+                $table->dropColumn('propertytype');
372
+            }
373
+            if ($table->hasColumn('fileid')) {
374
+                $table->dropColumn('fileid');
375
+            }
376
+            if (!$table->hasColumn('propertypath')) {
377
+                $table->addColumn('propertypath', 'string', [
378
+                    'notnull' => true,
379
+                    'length' => 255,
380
+                ]);
381
+            }
382
+            if (!$table->hasColumn('userid')) {
383
+                $table->addColumn('userid', 'string', [
384
+                    'notnull' => false,
385
+                    'length' => 64,
386
+                    'default' => '',
387
+                ]);
388
+            }
389
+        }
390 390
 
391
-		if (!$schema->hasTable('share')) {
392
-			$table = $schema->createTable('share');
393
-			$table->addColumn('id', 'integer', [
394
-				'autoincrement' => true,
395
-				'notnull' => true,
396
-				'length' => 4,
397
-			]);
398
-			$table->addColumn('share_type', 'smallint', [
399
-				'notnull' => true,
400
-				'length' => 1,
401
-				'default' => 0,
402
-			]);
403
-			$table->addColumn('share_with', 'string', [
404
-				'notnull' => false,
405
-				'length' => 255,
406
-			]);
407
-			$table->addColumn('password', 'string', [
408
-				'notnull' => false,
409
-				'length' => 255,
410
-			]);
411
-			$table->addColumn('uid_owner', 'string', [
412
-				'notnull' => true,
413
-				'length' => 64,
414
-				'default' => '',
415
-			]);
416
-			$table->addColumn('uid_initiator', 'string', [
417
-				'notnull' => false,
418
-				'length' => 64,
419
-			]);
420
-			$table->addColumn('parent', 'integer', [
421
-				'notnull' => false,
422
-				'length' => 4,
423
-			]);
424
-			$table->addColumn('item_type', 'string', [
425
-				'notnull' => true,
426
-				'length' => 64,
427
-				'default' => '',
428
-			]);
429
-			$table->addColumn('item_source', 'string', [
430
-				'notnull' => false,
431
-				'length' => 255,
432
-			]);
433
-			$table->addColumn('item_target', 'string', [
434
-				'notnull' => false,
435
-				'length' => 255,
436
-			]);
437
-			$table->addColumn('file_source', 'integer', [
438
-				'notnull' => false,
439
-				'length' => 4,
440
-			]);
441
-			$table->addColumn('file_target', 'string', [
442
-				'notnull' => false,
443
-				'length' => 512,
444
-			]);
445
-			$table->addColumn('permissions', 'smallint', [
446
-				'notnull' => true,
447
-				'length' => 1,
448
-				'default' => 0,
449
-			]);
450
-			$table->addColumn('stime', 'bigint', [
451
-				'notnull' => true,
452
-				'length' => 8,
453
-				'default' => 0,
454
-			]);
455
-			$table->addColumn('accepted', 'smallint', [
456
-				'notnull' => true,
457
-				'length' => 1,
458
-				'default' => 0,
459
-			]);
460
-			$table->addColumn('expiration', 'datetime', [
461
-				'notnull' => false,
462
-			]);
463
-			$table->addColumn('token', 'string', [
464
-				'notnull' => false,
465
-				'length' => 32,
466
-			]);
467
-			$table->addColumn('mail_send', 'smallint', [
468
-				'notnull' => true,
469
-				'length' => 1,
470
-				'default' => 0,
471
-			]);
472
-			$table->addColumn('share_name', 'string', [
473
-				'notnull' => false,
474
-				'length' => 64,
475
-			]);
476
-			$table->setPrimaryKey(['id']);
477
-			$table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
478
-			$table->addIndex(['file_source'], 'file_source_index');
479
-			$table->addIndex(['token'], 'token_index');
480
-			$table->addIndex(['share_with'], 'share_with_index');
481
-			$table->addIndex(['parent'], 'parent_index');
482
-			$table->addIndex(['uid_owner'], 'owner_index');
483
-			$table->addIndex(['uid_initiator'], 'initiator_index');
484
-		} else {
485
-			$table = $schema->getTable('share');
486
-			if (!$table->hasColumn('password')) {
487
-				$table->addColumn('password', 'string', [
488
-					'notnull' => false,
489
-					'length' => 255,
490
-				]);
491
-			}
492
-		}
391
+        if (!$schema->hasTable('share')) {
392
+            $table = $schema->createTable('share');
393
+            $table->addColumn('id', 'integer', [
394
+                'autoincrement' => true,
395
+                'notnull' => true,
396
+                'length' => 4,
397
+            ]);
398
+            $table->addColumn('share_type', 'smallint', [
399
+                'notnull' => true,
400
+                'length' => 1,
401
+                'default' => 0,
402
+            ]);
403
+            $table->addColumn('share_with', 'string', [
404
+                'notnull' => false,
405
+                'length' => 255,
406
+            ]);
407
+            $table->addColumn('password', 'string', [
408
+                'notnull' => false,
409
+                'length' => 255,
410
+            ]);
411
+            $table->addColumn('uid_owner', 'string', [
412
+                'notnull' => true,
413
+                'length' => 64,
414
+                'default' => '',
415
+            ]);
416
+            $table->addColumn('uid_initiator', 'string', [
417
+                'notnull' => false,
418
+                'length' => 64,
419
+            ]);
420
+            $table->addColumn('parent', 'integer', [
421
+                'notnull' => false,
422
+                'length' => 4,
423
+            ]);
424
+            $table->addColumn('item_type', 'string', [
425
+                'notnull' => true,
426
+                'length' => 64,
427
+                'default' => '',
428
+            ]);
429
+            $table->addColumn('item_source', 'string', [
430
+                'notnull' => false,
431
+                'length' => 255,
432
+            ]);
433
+            $table->addColumn('item_target', 'string', [
434
+                'notnull' => false,
435
+                'length' => 255,
436
+            ]);
437
+            $table->addColumn('file_source', 'integer', [
438
+                'notnull' => false,
439
+                'length' => 4,
440
+            ]);
441
+            $table->addColumn('file_target', 'string', [
442
+                'notnull' => false,
443
+                'length' => 512,
444
+            ]);
445
+            $table->addColumn('permissions', 'smallint', [
446
+                'notnull' => true,
447
+                'length' => 1,
448
+                'default' => 0,
449
+            ]);
450
+            $table->addColumn('stime', 'bigint', [
451
+                'notnull' => true,
452
+                'length' => 8,
453
+                'default' => 0,
454
+            ]);
455
+            $table->addColumn('accepted', 'smallint', [
456
+                'notnull' => true,
457
+                'length' => 1,
458
+                'default' => 0,
459
+            ]);
460
+            $table->addColumn('expiration', 'datetime', [
461
+                'notnull' => false,
462
+            ]);
463
+            $table->addColumn('token', 'string', [
464
+                'notnull' => false,
465
+                'length' => 32,
466
+            ]);
467
+            $table->addColumn('mail_send', 'smallint', [
468
+                'notnull' => true,
469
+                'length' => 1,
470
+                'default' => 0,
471
+            ]);
472
+            $table->addColumn('share_name', 'string', [
473
+                'notnull' => false,
474
+                'length' => 64,
475
+            ]);
476
+            $table->setPrimaryKey(['id']);
477
+            $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
478
+            $table->addIndex(['file_source'], 'file_source_index');
479
+            $table->addIndex(['token'], 'token_index');
480
+            $table->addIndex(['share_with'], 'share_with_index');
481
+            $table->addIndex(['parent'], 'parent_index');
482
+            $table->addIndex(['uid_owner'], 'owner_index');
483
+            $table->addIndex(['uid_initiator'], 'initiator_index');
484
+        } else {
485
+            $table = $schema->getTable('share');
486
+            if (!$table->hasColumn('password')) {
487
+                $table->addColumn('password', 'string', [
488
+                    'notnull' => false,
489
+                    'length' => 255,
490
+                ]);
491
+            }
492
+        }
493 493
 
494
-		if (!$schema->hasTable('jobs')) {
495
-			$table = $schema->createTable('jobs');
496
-			$table->addColumn('id', 'integer', [
497
-				'autoincrement' => true,
498
-				'notnull' => true,
499
-				'length' => 4,
500
-				'unsigned' => true,
501
-			]);
502
-			$table->addColumn('class', 'string', [
503
-				'notnull' => true,
504
-				'length' => 255,
505
-				'default' => '',
506
-			]);
507
-			$table->addColumn('argument', 'string', [
508
-				'notnull' => true,
509
-				'length' => 4000,
510
-				'default' => '',
511
-			]);
512
-			$table->addColumn('last_run', 'integer', [
513
-				'notnull' => false,
514
-				'default' => 0,
515
-			]);
516
-			$table->addColumn('last_checked', 'integer', [
517
-				'notnull' => false,
518
-				'default' => 0,
519
-			]);
520
-			$table->addColumn('reserved_at', 'integer', [
521
-				'notnull' => false,
522
-				'default' => 0,
523
-			]);
524
-			$table->addColumn('execution_duration', 'integer', [
525
-				'notnull' => true,
526
-				'default' => 0,
527
-			]);
528
-			$table->setPrimaryKey(['id']);
529
-			$table->addIndex(['class'], 'job_class_index');
530
-			$table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
531
-		}
494
+        if (!$schema->hasTable('jobs')) {
495
+            $table = $schema->createTable('jobs');
496
+            $table->addColumn('id', 'integer', [
497
+                'autoincrement' => true,
498
+                'notnull' => true,
499
+                'length' => 4,
500
+                'unsigned' => true,
501
+            ]);
502
+            $table->addColumn('class', 'string', [
503
+                'notnull' => true,
504
+                'length' => 255,
505
+                'default' => '',
506
+            ]);
507
+            $table->addColumn('argument', 'string', [
508
+                'notnull' => true,
509
+                'length' => 4000,
510
+                'default' => '',
511
+            ]);
512
+            $table->addColumn('last_run', 'integer', [
513
+                'notnull' => false,
514
+                'default' => 0,
515
+            ]);
516
+            $table->addColumn('last_checked', 'integer', [
517
+                'notnull' => false,
518
+                'default' => 0,
519
+            ]);
520
+            $table->addColumn('reserved_at', 'integer', [
521
+                'notnull' => false,
522
+                'default' => 0,
523
+            ]);
524
+            $table->addColumn('execution_duration', 'integer', [
525
+                'notnull' => true,
526
+                'default' => 0,
527
+            ]);
528
+            $table->setPrimaryKey(['id']);
529
+            $table->addIndex(['class'], 'job_class_index');
530
+            $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
531
+        }
532 532
 
533
-		if (!$schema->hasTable('users')) {
534
-			$table = $schema->createTable('users');
535
-			$table->addColumn('uid', 'string', [
536
-				'notnull' => true,
537
-				'length' => 64,
538
-				'default' => '',
539
-			]);
540
-			$table->addColumn('displayname', 'string', [
541
-				'notnull' => false,
542
-				'length' => 64,
543
-			]);
544
-			$table->addColumn('password', 'string', [
545
-				'notnull' => true,
546
-				'length' => 255,
547
-				'default' => '',
548
-			]);
549
-			$table->setPrimaryKey(['uid']);
550
-		}
533
+        if (!$schema->hasTable('users')) {
534
+            $table = $schema->createTable('users');
535
+            $table->addColumn('uid', 'string', [
536
+                'notnull' => true,
537
+                'length' => 64,
538
+                'default' => '',
539
+            ]);
540
+            $table->addColumn('displayname', 'string', [
541
+                'notnull' => false,
542
+                'length' => 64,
543
+            ]);
544
+            $table->addColumn('password', 'string', [
545
+                'notnull' => true,
546
+                'length' => 255,
547
+                'default' => '',
548
+            ]);
549
+            $table->setPrimaryKey(['uid']);
550
+        }
551 551
 
552
-		if (!$schema->hasTable('authtoken')) {
553
-			$table = $schema->createTable('authtoken');
554
-			$table->addColumn('id', 'integer', [
555
-				'autoincrement' => true,
556
-				'notnull' => true,
557
-				'length' => 4,
558
-				'unsigned' => true,
559
-			]);
560
-			$table->addColumn('uid', 'string', [
561
-				'notnull' => true,
562
-				'length' => 64,
563
-				'default' => '',
564
-			]);
565
-			$table->addColumn('login_name', 'string', [
566
-				'notnull' => true,
567
-				'length' => 64,
568
-				'default' => '',
569
-			]);
570
-			$table->addColumn('password', 'text', [
571
-				'notnull' => false,
572
-			]);
573
-			$table->addColumn('name', 'text', [
574
-				'notnull' => true,
575
-				'default' => '',
576
-			]);
577
-			$table->addColumn('token', 'string', [
578
-				'notnull' => true,
579
-				'length' => 200,
580
-				'default' => '',
581
-			]);
582
-			$table->addColumn('type', 'smallint', [
583
-				'notnull' => false,
584
-				'length' => 2,
585
-				'default' => 0,
586
-				'unsigned' => true,
587
-			]);
588
-			$table->addColumn('remember', 'smallint', [
589
-				'notnull' => false,
590
-				'length' => 1,
591
-				'default' => 0,
592
-				'unsigned' => true,
593
-			]);
594
-			$table->addColumn('last_activity', 'integer', [
595
-				'notnull' => false,
596
-				'length' => 4,
597
-				'default' => 0,
598
-				'unsigned' => true,
599
-			]);
600
-			$table->addColumn('last_check', 'integer', [
601
-				'notnull' => false,
602
-				'length' => 4,
603
-				'default' => 0,
604
-				'unsigned' => true,
605
-			]);
606
-			$table->addColumn('scope', 'text', [
607
-				'notnull' => false,
608
-			]);
609
-			$table->setPrimaryKey(['id']);
610
-			$table->addUniqueIndex(['token'], 'authtoken_token_index');
611
-			$table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
612
-		} else {
613
-			$table = $schema->getTable('authtoken');
614
-			$table->addColumn('scope', 'text', [
615
-				'notnull' => false,
616
-			]);
617
-		}
552
+        if (!$schema->hasTable('authtoken')) {
553
+            $table = $schema->createTable('authtoken');
554
+            $table->addColumn('id', 'integer', [
555
+                'autoincrement' => true,
556
+                'notnull' => true,
557
+                'length' => 4,
558
+                'unsigned' => true,
559
+            ]);
560
+            $table->addColumn('uid', 'string', [
561
+                'notnull' => true,
562
+                'length' => 64,
563
+                'default' => '',
564
+            ]);
565
+            $table->addColumn('login_name', 'string', [
566
+                'notnull' => true,
567
+                'length' => 64,
568
+                'default' => '',
569
+            ]);
570
+            $table->addColumn('password', 'text', [
571
+                'notnull' => false,
572
+            ]);
573
+            $table->addColumn('name', 'text', [
574
+                'notnull' => true,
575
+                'default' => '',
576
+            ]);
577
+            $table->addColumn('token', 'string', [
578
+                'notnull' => true,
579
+                'length' => 200,
580
+                'default' => '',
581
+            ]);
582
+            $table->addColumn('type', 'smallint', [
583
+                'notnull' => false,
584
+                'length' => 2,
585
+                'default' => 0,
586
+                'unsigned' => true,
587
+            ]);
588
+            $table->addColumn('remember', 'smallint', [
589
+                'notnull' => false,
590
+                'length' => 1,
591
+                'default' => 0,
592
+                'unsigned' => true,
593
+            ]);
594
+            $table->addColumn('last_activity', 'integer', [
595
+                'notnull' => false,
596
+                'length' => 4,
597
+                'default' => 0,
598
+                'unsigned' => true,
599
+            ]);
600
+            $table->addColumn('last_check', 'integer', [
601
+                'notnull' => false,
602
+                'length' => 4,
603
+                'default' => 0,
604
+                'unsigned' => true,
605
+            ]);
606
+            $table->addColumn('scope', 'text', [
607
+                'notnull' => false,
608
+            ]);
609
+            $table->setPrimaryKey(['id']);
610
+            $table->addUniqueIndex(['token'], 'authtoken_token_index');
611
+            $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
612
+        } else {
613
+            $table = $schema->getTable('authtoken');
614
+            $table->addColumn('scope', 'text', [
615
+                'notnull' => false,
616
+            ]);
617
+        }
618 618
 
619
-		if (!$schema->hasTable('bruteforce_attempts')) {
620
-			$table = $schema->createTable('bruteforce_attempts');
621
-			$table->addColumn('id', 'integer', [
622
-				'autoincrement' => true,
623
-				'notnull' => true,
624
-				'length' => 4,
625
-				'unsigned' => true,
626
-			]);
627
-			$table->addColumn('action', 'string', [
628
-				'notnull' => true,
629
-				'length' => 64,
630
-				'default' => '',
631
-			]);
632
-			$table->addColumn('occurred', 'integer', [
633
-				'notnull' => true,
634
-				'length' => 4,
635
-				'default' => 0,
636
-				'unsigned' => true,
637
-			]);
638
-			$table->addColumn('ip', 'string', [
639
-				'notnull' => true,
640
-				'length' => 255,
641
-				'default' => '',
642
-			]);
643
-			$table->addColumn('subnet', 'string', [
644
-				'notnull' => true,
645
-				'length' => 255,
646
-				'default' => '',
647
-			]);
648
-			$table->addColumn('metadata', 'string', [
649
-				'notnull' => true,
650
-				'length' => 255,
651
-				'default' => '',
652
-			]);
653
-			$table->setPrimaryKey(['id']);
654
-			$table->addIndex(['ip'], 'bruteforce_attempts_ip');
655
-			$table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
656
-		}
619
+        if (!$schema->hasTable('bruteforce_attempts')) {
620
+            $table = $schema->createTable('bruteforce_attempts');
621
+            $table->addColumn('id', 'integer', [
622
+                'autoincrement' => true,
623
+                'notnull' => true,
624
+                'length' => 4,
625
+                'unsigned' => true,
626
+            ]);
627
+            $table->addColumn('action', 'string', [
628
+                'notnull' => true,
629
+                'length' => 64,
630
+                'default' => '',
631
+            ]);
632
+            $table->addColumn('occurred', 'integer', [
633
+                'notnull' => true,
634
+                'length' => 4,
635
+                'default' => 0,
636
+                'unsigned' => true,
637
+            ]);
638
+            $table->addColumn('ip', 'string', [
639
+                'notnull' => true,
640
+                'length' => 255,
641
+                'default' => '',
642
+            ]);
643
+            $table->addColumn('subnet', 'string', [
644
+                'notnull' => true,
645
+                'length' => 255,
646
+                'default' => '',
647
+            ]);
648
+            $table->addColumn('metadata', 'string', [
649
+                'notnull' => true,
650
+                'length' => 255,
651
+                'default' => '',
652
+            ]);
653
+            $table->setPrimaryKey(['id']);
654
+            $table->addIndex(['ip'], 'bruteforce_attempts_ip');
655
+            $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
656
+        }
657 657
 
658
-		if (!$schema->hasTable('vcategory')) {
659
-			$table = $schema->createTable('vcategory');
660
-			$table->addColumn('id', 'integer', [
661
-				'autoincrement' => true,
662
-				'notnull' => true,
663
-				'length' => 4,
664
-				'unsigned' => true,
665
-			]);
666
-			$table->addColumn('uid', 'string', [
667
-				'notnull' => true,
668
-				'length' => 64,
669
-				'default' => '',
670
-			]);
671
-			$table->addColumn('type', 'string', [
672
-				'notnull' => true,
673
-				'length' => 64,
674
-				'default' => '',
675
-			]);
676
-			$table->addColumn('category', 'string', [
677
-				'notnull' => true,
678
-				'length' => 255,
679
-				'default' => '',
680
-			]);
681
-			$table->setPrimaryKey(['id']);
682
-			$table->addIndex(['uid'], 'uid_index');
683
-			$table->addIndex(['type'], 'type_index');
684
-			$table->addIndex(['category'], 'category_index');
685
-		}
658
+        if (!$schema->hasTable('vcategory')) {
659
+            $table = $schema->createTable('vcategory');
660
+            $table->addColumn('id', 'integer', [
661
+                'autoincrement' => true,
662
+                'notnull' => true,
663
+                'length' => 4,
664
+                'unsigned' => true,
665
+            ]);
666
+            $table->addColumn('uid', 'string', [
667
+                'notnull' => true,
668
+                'length' => 64,
669
+                'default' => '',
670
+            ]);
671
+            $table->addColumn('type', 'string', [
672
+                'notnull' => true,
673
+                'length' => 64,
674
+                'default' => '',
675
+            ]);
676
+            $table->addColumn('category', 'string', [
677
+                'notnull' => true,
678
+                'length' => 255,
679
+                'default' => '',
680
+            ]);
681
+            $table->setPrimaryKey(['id']);
682
+            $table->addIndex(['uid'], 'uid_index');
683
+            $table->addIndex(['type'], 'type_index');
684
+            $table->addIndex(['category'], 'category_index');
685
+        }
686 686
 
687
-		if (!$schema->hasTable('vcategory_to_object')) {
688
-			$table = $schema->createTable('vcategory_to_object');
689
-			$table->addColumn('objid', 'integer', [
690
-				'notnull' => true,
691
-				'length' => 4,
692
-				'default' => 0,
693
-				'unsigned' => true,
694
-			]);
695
-			$table->addColumn('categoryid', 'integer', [
696
-				'notnull' => true,
697
-				'length' => 4,
698
-				'default' => 0,
699
-				'unsigned' => true,
700
-			]);
701
-			$table->addColumn('type', 'string', [
702
-				'notnull' => true,
703
-				'length' => 64,
704
-				'default' => '',
705
-			]);
706
-			$table->setPrimaryKey(['categoryid', 'objid', 'type']);
707
-			$table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
708
-		}
687
+        if (!$schema->hasTable('vcategory_to_object')) {
688
+            $table = $schema->createTable('vcategory_to_object');
689
+            $table->addColumn('objid', 'integer', [
690
+                'notnull' => true,
691
+                'length' => 4,
692
+                'default' => 0,
693
+                'unsigned' => true,
694
+            ]);
695
+            $table->addColumn('categoryid', 'integer', [
696
+                'notnull' => true,
697
+                'length' => 4,
698
+                'default' => 0,
699
+                'unsigned' => true,
700
+            ]);
701
+            $table->addColumn('type', 'string', [
702
+                'notnull' => true,
703
+                'length' => 64,
704
+                'default' => '',
705
+            ]);
706
+            $table->setPrimaryKey(['categoryid', 'objid', 'type']);
707
+            $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
708
+        }
709 709
 
710
-		if (!$schema->hasTable('systemtag')) {
711
-			$table = $schema->createTable('systemtag');
712
-			$table->addColumn('id', 'integer', [
713
-				'autoincrement' => true,
714
-				'notnull' => true,
715
-				'length' => 4,
716
-				'unsigned' => true,
717
-			]);
718
-			$table->addColumn('name', 'string', [
719
-				'notnull' => true,
720
-				'length' => 64,
721
-				'default' => '',
722
-			]);
723
-			$table->addColumn('visibility', 'smallint', [
724
-				'notnull' => true,
725
-				'length' => 1,
726
-				'default' => 1,
727
-			]);
728
-			$table->addColumn('editable', 'smallint', [
729
-				'notnull' => true,
730
-				'length' => 1,
731
-				'default' => 1,
732
-			]);
733
-			$table->setPrimaryKey(['id']);
734
-			$table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
735
-		}
710
+        if (!$schema->hasTable('systemtag')) {
711
+            $table = $schema->createTable('systemtag');
712
+            $table->addColumn('id', 'integer', [
713
+                'autoincrement' => true,
714
+                'notnull' => true,
715
+                'length' => 4,
716
+                'unsigned' => true,
717
+            ]);
718
+            $table->addColumn('name', 'string', [
719
+                'notnull' => true,
720
+                'length' => 64,
721
+                'default' => '',
722
+            ]);
723
+            $table->addColumn('visibility', 'smallint', [
724
+                'notnull' => true,
725
+                'length' => 1,
726
+                'default' => 1,
727
+            ]);
728
+            $table->addColumn('editable', 'smallint', [
729
+                'notnull' => true,
730
+                'length' => 1,
731
+                'default' => 1,
732
+            ]);
733
+            $table->setPrimaryKey(['id']);
734
+            $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
735
+        }
736 736
 
737
-		if (!$schema->hasTable('systemtag_object_mapping')) {
738
-			$table = $schema->createTable('systemtag_object_mapping');
739
-			$table->addColumn('objectid', 'string', [
740
-				'notnull' => true,
741
-				'length' => 64,
742
-				'default' => '',
743
-			]);
744
-			$table->addColumn('objecttype', 'string', [
745
-				'notnull' => true,
746
-				'length' => 64,
747
-				'default' => '',
748
-			]);
749
-			$table->addColumn('systemtagid', 'integer', [
750
-				'notnull' => true,
751
-				'length' => 4,
752
-				'default' => 0,
753
-				'unsigned' => true,
754
-			]);
755
-			$table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
737
+        if (!$schema->hasTable('systemtag_object_mapping')) {
738
+            $table = $schema->createTable('systemtag_object_mapping');
739
+            $table->addColumn('objectid', 'string', [
740
+                'notnull' => true,
741
+                'length' => 64,
742
+                'default' => '',
743
+            ]);
744
+            $table->addColumn('objecttype', 'string', [
745
+                'notnull' => true,
746
+                'length' => 64,
747
+                'default' => '',
748
+            ]);
749
+            $table->addColumn('systemtagid', 'integer', [
750
+                'notnull' => true,
751
+                'length' => 4,
752
+                'default' => 0,
753
+                'unsigned' => true,
754
+            ]);
755
+            $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
756 756
 //			$table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
757
-		}
757
+        }
758 758
 
759
-		if (!$schema->hasTable('systemtag_group')) {
760
-			$table = $schema->createTable('systemtag_group');
761
-			$table->addColumn('systemtagid', 'integer', [
762
-				'notnull' => true,
763
-				'length' => 4,
764
-				'default' => 0,
765
-				'unsigned' => true,
766
-			]);
767
-			$table->addColumn('gid', 'string', [
768
-				'notnull' => true,
769
-			]);
770
-			$table->setPrimaryKey(['gid', 'systemtagid']);
771
-		}
759
+        if (!$schema->hasTable('systemtag_group')) {
760
+            $table = $schema->createTable('systemtag_group');
761
+            $table->addColumn('systemtagid', 'integer', [
762
+                'notnull' => true,
763
+                'length' => 4,
764
+                'default' => 0,
765
+                'unsigned' => true,
766
+            ]);
767
+            $table->addColumn('gid', 'string', [
768
+                'notnull' => true,
769
+            ]);
770
+            $table->setPrimaryKey(['gid', 'systemtagid']);
771
+        }
772 772
 
773
-		if (!$schema->hasTable('file_locks')) {
774
-			$table = $schema->createTable('file_locks');
775
-			$table->addColumn('id', 'integer', [
776
-				'autoincrement' => true,
777
-				'notnull' => true,
778
-				'length' => 4,
779
-				'unsigned' => true,
780
-			]);
781
-			$table->addColumn('lock', 'integer', [
782
-				'notnull' => true,
783
-				'length' => 4,
784
-				'default' => 0,
785
-			]);
786
-			$table->addColumn('key', 'string', [
787
-				'notnull' => true,
788
-				'length' => 64,
789
-			]);
790
-			$table->addColumn('ttl', 'integer', [
791
-				'notnull' => true,
792
-				'length' => 4,
793
-				'default' => -1,
794
-			]);
795
-			$table->setPrimaryKey(['id']);
796
-			$table->addUniqueIndex(['key'], 'lock_key_index');
797
-			$table->addIndex(['ttl'], 'lock_ttl_index');
798
-		}
773
+        if (!$schema->hasTable('file_locks')) {
774
+            $table = $schema->createTable('file_locks');
775
+            $table->addColumn('id', 'integer', [
776
+                'autoincrement' => true,
777
+                'notnull' => true,
778
+                'length' => 4,
779
+                'unsigned' => true,
780
+            ]);
781
+            $table->addColumn('lock', 'integer', [
782
+                'notnull' => true,
783
+                'length' => 4,
784
+                'default' => 0,
785
+            ]);
786
+            $table->addColumn('key', 'string', [
787
+                'notnull' => true,
788
+                'length' => 64,
789
+            ]);
790
+            $table->addColumn('ttl', 'integer', [
791
+                'notnull' => true,
792
+                'length' => 4,
793
+                'default' => -1,
794
+            ]);
795
+            $table->setPrimaryKey(['id']);
796
+            $table->addUniqueIndex(['key'], 'lock_key_index');
797
+            $table->addIndex(['ttl'], 'lock_ttl_index');
798
+        }
799 799
 
800
-		if (!$schema->hasTable('comments')) {
801
-			$table = $schema->createTable('comments');
802
-			$table->addColumn('id', 'integer', [
803
-				'autoincrement' => true,
804
-				'notnull' => true,
805
-				'length' => 4,
806
-				'unsigned' => true,
807
-			]);
808
-			$table->addColumn('parent_id', 'integer', [
809
-				'notnull' => true,
810
-				'length' => 4,
811
-				'default' => 0,
812
-				'unsigned' => true,
813
-			]);
814
-			$table->addColumn('topmost_parent_id', 'integer', [
815
-				'notnull' => true,
816
-				'length' => 4,
817
-				'default' => 0,
818
-				'unsigned' => true,
819
-			]);
820
-			$table->addColumn('children_count', 'integer', [
821
-				'notnull' => true,
822
-				'length' => 4,
823
-				'default' => 0,
824
-				'unsigned' => true,
825
-			]);
826
-			$table->addColumn('actor_type', 'string', [
827
-				'notnull' => true,
828
-				'length' => 64,
829
-				'default' => '',
830
-			]);
831
-			$table->addColumn('actor_id', 'string', [
832
-				'notnull' => true,
833
-				'length' => 64,
834
-				'default' => '',
835
-			]);
836
-			$table->addColumn('message', 'text', [
837
-				'notnull' => false,
838
-			]);
839
-			$table->addColumn('verb', 'string', [
840
-				'notnull' => false,
841
-				'length' => 64,
842
-			]);
843
-			$table->addColumn('creation_timestamp', 'datetime', [
844
-				'notnull' => false,
845
-			]);
846
-			$table->addColumn('latest_child_timestamp', 'datetime', [
847
-				'notnull' => false,
848
-			]);
849
-			$table->addColumn('object_type', 'string', [
850
-				'notnull' => true,
851
-				'length' => 64,
852
-				'default' => '',
853
-			]);
854
-			$table->addColumn('object_id', 'string', [
855
-				'notnull' => true,
856
-				'length' => 64,
857
-				'default' => '',
858
-			]);
859
-			$table->addColumn('reference_id', 'string', [
860
-				'notnull' => false,
861
-				'length' => 64,
862
-			]);
863
-			$table->setPrimaryKey(['id']);
864
-			$table->addIndex(['parent_id'], 'comments_parent_id_index');
865
-			$table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
866
-			$table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
867
-			$table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
868
-		}
800
+        if (!$schema->hasTable('comments')) {
801
+            $table = $schema->createTable('comments');
802
+            $table->addColumn('id', 'integer', [
803
+                'autoincrement' => true,
804
+                'notnull' => true,
805
+                'length' => 4,
806
+                'unsigned' => true,
807
+            ]);
808
+            $table->addColumn('parent_id', 'integer', [
809
+                'notnull' => true,
810
+                'length' => 4,
811
+                'default' => 0,
812
+                'unsigned' => true,
813
+            ]);
814
+            $table->addColumn('topmost_parent_id', 'integer', [
815
+                'notnull' => true,
816
+                'length' => 4,
817
+                'default' => 0,
818
+                'unsigned' => true,
819
+            ]);
820
+            $table->addColumn('children_count', 'integer', [
821
+                'notnull' => true,
822
+                'length' => 4,
823
+                'default' => 0,
824
+                'unsigned' => true,
825
+            ]);
826
+            $table->addColumn('actor_type', 'string', [
827
+                'notnull' => true,
828
+                'length' => 64,
829
+                'default' => '',
830
+            ]);
831
+            $table->addColumn('actor_id', 'string', [
832
+                'notnull' => true,
833
+                'length' => 64,
834
+                'default' => '',
835
+            ]);
836
+            $table->addColumn('message', 'text', [
837
+                'notnull' => false,
838
+            ]);
839
+            $table->addColumn('verb', 'string', [
840
+                'notnull' => false,
841
+                'length' => 64,
842
+            ]);
843
+            $table->addColumn('creation_timestamp', 'datetime', [
844
+                'notnull' => false,
845
+            ]);
846
+            $table->addColumn('latest_child_timestamp', 'datetime', [
847
+                'notnull' => false,
848
+            ]);
849
+            $table->addColumn('object_type', 'string', [
850
+                'notnull' => true,
851
+                'length' => 64,
852
+                'default' => '',
853
+            ]);
854
+            $table->addColumn('object_id', 'string', [
855
+                'notnull' => true,
856
+                'length' => 64,
857
+                'default' => '',
858
+            ]);
859
+            $table->addColumn('reference_id', 'string', [
860
+                'notnull' => false,
861
+                'length' => 64,
862
+            ]);
863
+            $table->setPrimaryKey(['id']);
864
+            $table->addIndex(['parent_id'], 'comments_parent_id_index');
865
+            $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
866
+            $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
867
+            $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
868
+        }
869 869
 
870
-		if (!$schema->hasTable('comments_read_markers')) {
871
-			$table = $schema->createTable('comments_read_markers');
872
-			$table->addColumn('user_id', 'string', [
873
-				'notnull' => true,
874
-				'length' => 64,
875
-				'default' => '',
876
-			]);
877
-			$table->addColumn('marker_datetime', 'datetime', [
878
-				'notnull' => false,
879
-			]);
880
-			$table->addColumn('object_type', 'string', [
881
-				'notnull' => true,
882
-				'length' => 64,
883
-				'default' => '',
884
-			]);
885
-			$table->addColumn('object_id', 'string', [
886
-				'notnull' => true,
887
-				'length' => 64,
888
-				'default' => '',
889
-			]);
890
-			$table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
891
-			$table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
870
+        if (!$schema->hasTable('comments_read_markers')) {
871
+            $table = $schema->createTable('comments_read_markers');
872
+            $table->addColumn('user_id', 'string', [
873
+                'notnull' => true,
874
+                'length' => 64,
875
+                'default' => '',
876
+            ]);
877
+            $table->addColumn('marker_datetime', 'datetime', [
878
+                'notnull' => false,
879
+            ]);
880
+            $table->addColumn('object_type', 'string', [
881
+                'notnull' => true,
882
+                'length' => 64,
883
+                'default' => '',
884
+            ]);
885
+            $table->addColumn('object_id', 'string', [
886
+                'notnull' => true,
887
+                'length' => 64,
888
+                'default' => '',
889
+            ]);
890
+            $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
891
+            $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
892 892
 //			$table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
893
-		}
893
+        }
894 894
 
895 895
 //		if (!$schema->hasTable('credentials')) {
896 896
 //			$table = $schema->createTable('credentials');
@@ -909,139 +909,139 @@  discard block
 block discarded – undo
909 909
 //			$table->addIndex(['user'], 'credentials_user');
910 910
 //		}
911 911
 
912
-		if (!$schema->hasTable('admin_sections')) {
913
-			$table = $schema->createTable('admin_sections');
914
-			$table->addColumn('id', 'string', [
915
-				'notnull' => true,
916
-				'length' => 64,
917
-			]);
918
-			$table->addColumn('class', 'string', [
919
-				'notnull' => true,
920
-				'length' => 255,
921
-				'default' => '',
922
-			]);
923
-			$table->addColumn('priority', 'smallint', [
924
-				'notnull' => true,
925
-				'length' => 1,
926
-				'default' => 0,
927
-			]);
928
-			$table->setPrimaryKey(['id']);
929
-			$table->addUniqueIndex(['class'], 'admin_sections_class');
930
-		}
912
+        if (!$schema->hasTable('admin_sections')) {
913
+            $table = $schema->createTable('admin_sections');
914
+            $table->addColumn('id', 'string', [
915
+                'notnull' => true,
916
+                'length' => 64,
917
+            ]);
918
+            $table->addColumn('class', 'string', [
919
+                'notnull' => true,
920
+                'length' => 255,
921
+                'default' => '',
922
+            ]);
923
+            $table->addColumn('priority', 'smallint', [
924
+                'notnull' => true,
925
+                'length' => 1,
926
+                'default' => 0,
927
+            ]);
928
+            $table->setPrimaryKey(['id']);
929
+            $table->addUniqueIndex(['class'], 'admin_sections_class');
930
+        }
931 931
 
932
-		if (!$schema->hasTable('admin_settings')) {
933
-			$table = $schema->createTable('admin_settings');
934
-			$table->addColumn('id', 'integer', [
935
-				'autoincrement' => true,
936
-				'notnull' => true,
937
-				'length' => 4,
938
-			]);
939
-			$table->addColumn('class', 'string', [
940
-				'notnull' => true,
941
-				'length' => 255,
942
-				'default' => '',
943
-			]);
944
-			$table->addColumn('section', 'string', [
945
-				'notnull' => false,
946
-				'length' => 64,
947
-			]);
948
-			$table->addColumn('priority', 'smallint', [
949
-				'notnull' => true,
950
-				'length' => 1,
951
-				'default' => 0,
952
-			]);
953
-			$table->setPrimaryKey(['id']);
954
-			$table->addUniqueIndex(['class'], 'admin_settings_class');
955
-			$table->addIndex(['section'], 'admin_settings_section');
956
-		}
932
+        if (!$schema->hasTable('admin_settings')) {
933
+            $table = $schema->createTable('admin_settings');
934
+            $table->addColumn('id', 'integer', [
935
+                'autoincrement' => true,
936
+                'notnull' => true,
937
+                'length' => 4,
938
+            ]);
939
+            $table->addColumn('class', 'string', [
940
+                'notnull' => true,
941
+                'length' => 255,
942
+                'default' => '',
943
+            ]);
944
+            $table->addColumn('section', 'string', [
945
+                'notnull' => false,
946
+                'length' => 64,
947
+            ]);
948
+            $table->addColumn('priority', 'smallint', [
949
+                'notnull' => true,
950
+                'length' => 1,
951
+                'default' => 0,
952
+            ]);
953
+            $table->setPrimaryKey(['id']);
954
+            $table->addUniqueIndex(['class'], 'admin_settings_class');
955
+            $table->addIndex(['section'], 'admin_settings_section');
956
+        }
957 957
 
958
-		if (!$schema->hasTable('personal_sections')) {
959
-			$table = $schema->createTable('personal_sections');
960
-			$table->addColumn('id', 'string', [
961
-				'notnull' => true,
962
-				'length' => 64,
963
-			]);
964
-			$table->addColumn('class', 'string', [
965
-				'notnull' => true,
966
-				'length' => 255,
967
-				'default' => '',
968
-			]);
969
-			$table->addColumn('priority', 'smallint', [
970
-				'notnull' => true,
971
-				'length' => 1,
972
-				'default' => 0,
973
-			]);
974
-			$table->setPrimaryKey(['id']);
975
-			$table->addUniqueIndex(['class'], 'personal_sections_class');
976
-		}
958
+        if (!$schema->hasTable('personal_sections')) {
959
+            $table = $schema->createTable('personal_sections');
960
+            $table->addColumn('id', 'string', [
961
+                'notnull' => true,
962
+                'length' => 64,
963
+            ]);
964
+            $table->addColumn('class', 'string', [
965
+                'notnull' => true,
966
+                'length' => 255,
967
+                'default' => '',
968
+            ]);
969
+            $table->addColumn('priority', 'smallint', [
970
+                'notnull' => true,
971
+                'length' => 1,
972
+                'default' => 0,
973
+            ]);
974
+            $table->setPrimaryKey(['id']);
975
+            $table->addUniqueIndex(['class'], 'personal_sections_class');
976
+        }
977 977
 
978
-		if (!$schema->hasTable('personal_settings')) {
979
-			$table = $schema->createTable('personal_settings');
980
-			$table->addColumn('id', 'integer', [
981
-				'autoincrement' => true,
982
-				'notnull' => true,
983
-				'length' => 4,
984
-			]);
985
-			$table->addColumn('class', 'string', [
986
-				'notnull' => true,
987
-				'length' => 255,
988
-				'default' => '',
989
-			]);
990
-			$table->addColumn('section', 'string', [
991
-				'notnull' => false,
992
-				'length' => 64,
993
-			]);
994
-			$table->addColumn('priority', 'smallint', [
995
-				'notnull' => true,
996
-				'length' => 1,
997
-				'default' => 0,
998
-			]);
999
-			$table->setPrimaryKey(['id']);
1000
-			$table->addUniqueIndex(['class'], 'personal_settings_class');
1001
-			$table->addIndex(['section'], 'personal_settings_section');
1002
-		}
978
+        if (!$schema->hasTable('personal_settings')) {
979
+            $table = $schema->createTable('personal_settings');
980
+            $table->addColumn('id', 'integer', [
981
+                'autoincrement' => true,
982
+                'notnull' => true,
983
+                'length' => 4,
984
+            ]);
985
+            $table->addColumn('class', 'string', [
986
+                'notnull' => true,
987
+                'length' => 255,
988
+                'default' => '',
989
+            ]);
990
+            $table->addColumn('section', 'string', [
991
+                'notnull' => false,
992
+                'length' => 64,
993
+            ]);
994
+            $table->addColumn('priority', 'smallint', [
995
+                'notnull' => true,
996
+                'length' => 1,
997
+                'default' => 0,
998
+            ]);
999
+            $table->setPrimaryKey(['id']);
1000
+            $table->addUniqueIndex(['class'], 'personal_settings_class');
1001
+            $table->addIndex(['section'], 'personal_settings_section');
1002
+        }
1003 1003
 
1004
-		if (!$schema->hasTable('accounts')) {
1005
-			$table = $schema->createTable('accounts');
1006
-			$table->addColumn('uid', 'string', [
1007
-				'notnull' => true,
1008
-				'length' => 64,
1009
-				'default' => '',
1010
-			]);
1011
-			$table->addColumn('data', 'text', [
1012
-				'notnull' => true,
1013
-				'default' => '',
1014
-			]);
1015
-			$table->setPrimaryKey(['uid']);
1016
-		}
1017
-		return $schema;
1018
-	}
1004
+        if (!$schema->hasTable('accounts')) {
1005
+            $table = $schema->createTable('accounts');
1006
+            $table->addColumn('uid', 'string', [
1007
+                'notnull' => true,
1008
+                'length' => 64,
1009
+                'default' => '',
1010
+            ]);
1011
+            $table->addColumn('data', 'text', [
1012
+                'notnull' => true,
1013
+                'default' => '',
1014
+            ]);
1015
+            $table->setPrimaryKey(['uid']);
1016
+        }
1017
+        return $schema;
1018
+    }
1019 1019
 
1020
-	public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
1021
-		/** @var ISchemaWrapper $schema */
1022
-		$schema = $schemaClosure();
1023
-		if (!$schema->hasTable('dav_properties')) {
1024
-			return;
1025
-		}
1026
-		$query = $this->connection->getQueryBuilder();
1027
-		$query->select('*')
1028
-			->from('dav_properties');
1020
+    public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
1021
+        /** @var ISchemaWrapper $schema */
1022
+        $schema = $schemaClosure();
1023
+        if (!$schema->hasTable('dav_properties')) {
1024
+            return;
1025
+        }
1026
+        $query = $this->connection->getQueryBuilder();
1027
+        $query->select('*')
1028
+            ->from('dav_properties');
1029 1029
 
1030
-		$insert = $this->connection->getQueryBuilder();
1031
-		$insert->insert('properties')
1032
-			->setValue('propertypath', $insert->createParameter('propertypath'))
1033
-			->setValue('propertyname', $insert->createParameter('propertyname'))
1034
-			->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
1035
-			->setValue('userid', $insert->createParameter('userid'));
1030
+        $insert = $this->connection->getQueryBuilder();
1031
+        $insert->insert('properties')
1032
+            ->setValue('propertypath', $insert->createParameter('propertypath'))
1033
+            ->setValue('propertyname', $insert->createParameter('propertyname'))
1034
+            ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
1035
+            ->setValue('userid', $insert->createParameter('userid'));
1036 1036
 
1037
-		$result = $query->execute();
1038
-		while ($row = $result->fetch()) {
1039
-			preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
1040
-			$insert->setParameter('propertypath', (string) $row['propertypath'])
1041
-				->setParameter('propertyname', (string) $row['propertyname'])
1042
-				->setParameter('propertyvalue', (string) $row['propertyvalue'])
1043
-				->setParameter('userid', ($match[2] ?? ''));
1044
-			$insert->execute();
1045
-		}
1046
-	}
1037
+        $result = $query->execute();
1038
+        while ($row = $result->fetch()) {
1039
+            preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
1040
+            $insert->setParameter('propertypath', (string) $row['propertypath'])
1041
+                ->setParameter('propertyname', (string) $row['propertyname'])
1042
+                ->setParameter('propertyvalue', (string) $row['propertyvalue'])
1043
+                ->setParameter('userid', ($match[2] ?? ''));
1044
+            $insert->execute();
1045
+        }
1046
+    }
1047 1047
 }
Please login to merge, or discard this patch.
core/Command/Db/AddMissingIndices.php 1 patch
Indentation   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -54,402 +54,402 @@
 block discarded – undo
54 54
  */
55 55
 class AddMissingIndices extends Command {
56 56
 
57
-	/** @var Connection */
58
-	private $connection;
59
-
60
-	/** @var EventDispatcherInterface */
61
-	private $dispatcher;
62
-
63
-	public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
64
-		parent::__construct();
65
-
66
-		$this->connection = $connection;
67
-		$this->dispatcher = $dispatcher;
68
-	}
69
-
70
-	protected function configure() {
71
-		$this
72
-			->setName('db:add-missing-indices')
73
-			->setDescription('Add missing indices to the database tables')
74
-			->addOption('dry-run', null, InputOption::VALUE_NONE, "Output the SQL queries instead of running them.");
75
-	}
76
-
77
-	protected function execute(InputInterface $input, OutputInterface $output): int {
78
-		$this->addCoreIndexes($output, $input->getOption('dry-run'));
79
-
80
-		// Dispatch event so apps can also update indexes if needed
81
-		$event = new GenericEvent($output);
82
-		$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
83
-		return 0;
84
-	}
85
-
86
-	/**
87
-	 * add missing indices to the share table
88
-	 *
89
-	 * @param OutputInterface $output
90
-	 * @param bool $dryRun If true, will return the sql queries instead of running them.
91
-	 * @throws \Doctrine\DBAL\Schema\SchemaException
92
-	 */
93
-	private function addCoreIndexes(OutputInterface $output, bool $dryRun): void {
94
-		$output->writeln('<info>Check indices of the share table.</info>');
95
-
96
-		$schema = new SchemaWrapper($this->connection);
97
-		$updated = false;
98
-
99
-		if ($schema->hasTable('share')) {
100
-			$table = $schema->getTable('share');
101
-			if (!$table->hasIndex('share_with_index')) {
102
-				$output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
103
-				$table->addIndex(['share_with'], 'share_with_index');
104
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
105
-				if ($dryRun && $sqlQueries !== null) {
106
-					$output->writeln($sqlQueries);
107
-				}
108
-				$updated = true;
109
-				$output->writeln('<info>Share table updated successfully.</info>');
110
-			}
111
-
112
-			if (!$table->hasIndex('parent_index')) {
113
-				$output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
114
-				$table->addIndex(['parent'], 'parent_index');
115
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
116
-				if ($dryRun && $sqlQueries !== null) {
117
-					$output->writeln($sqlQueries);
118
-				}
119
-				$updated = true;
120
-				$output->writeln('<info>Share table updated successfully.</info>');
121
-			}
122
-
123
-			if (!$table->hasIndex('owner_index')) {
124
-				$output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
125
-				$table->addIndex(['uid_owner'], 'owner_index');
126
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
127
-				if ($dryRun && $sqlQueries !== null) {
128
-					$output->writeln($sqlQueries);
129
-				}
130
-				$updated = true;
131
-				$output->writeln('<info>Share table updated successfully.</info>');
132
-			}
133
-
134
-			if (!$table->hasIndex('initiator_index')) {
135
-				$output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
136
-				$table->addIndex(['uid_initiator'], 'initiator_index');
137
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
138
-				if ($dryRun && $sqlQueries !== null) {
139
-					$output->writeln($sqlQueries);
140
-				}
141
-				$updated = true;
142
-				$output->writeln('<info>Share table updated successfully.</info>');
143
-			}
144
-		}
145
-
146
-		$output->writeln('<info>Check indices of the filecache table.</info>');
147
-		if ($schema->hasTable('filecache')) {
148
-			$table = $schema->getTable('filecache');
149
-			if (!$table->hasIndex('fs_mtime')) {
150
-				$output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
151
-				$table->addIndex(['mtime'], 'fs_mtime');
152
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
153
-				if ($dryRun && $sqlQueries !== null) {
154
-					$output->writeln($sqlQueries);
155
-				}
156
-				$updated = true;
157
-				$output->writeln('<info>Filecache table updated successfully.</info>');
158
-			}
159
-			if (!$table->hasIndex('fs_size')) {
160
-				$output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
161
-				$table->addIndex(['size'], 'fs_size');
162
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
163
-				if ($dryRun && $sqlQueries !== null) {
164
-					$output->writeln($sqlQueries);
165
-				}
166
-				$updated = true;
167
-				$output->writeln('<info>Filecache table updated successfully.</info>');
168
-			}
169
-			if (!$table->hasIndex('fs_id_storage_size')) {
170
-				$output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
171
-				$table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
172
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
173
-				if ($dryRun && $sqlQueries !== null) {
174
-					$output->writeln($sqlQueries);
175
-				}
176
-				$updated = true;
177
-				$output->writeln('<info>Filecache table updated successfully.</info>');
178
-			}
179
-			if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
180
-				$output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>');
181
-				$table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
182
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
183
-				if ($dryRun && $sqlQueries !== null) {
184
-					$output->writeln($sqlQueries);
185
-				}
186
-				$updated = true;
187
-				$output->writeln('<info>Filecache table updated successfully.</info>');
188
-			}
189
-		}
190
-
191
-		$output->writeln('<info>Check indices of the twofactor_providers table.</info>');
192
-		if ($schema->hasTable('twofactor_providers')) {
193
-			$table = $schema->getTable('twofactor_providers');
194
-			if (!$table->hasIndex('twofactor_providers_uid')) {
195
-				$output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
196
-				$table->addIndex(['uid'], 'twofactor_providers_uid');
197
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
198
-				if ($dryRun && $sqlQueries !== null) {
199
-					$output->writeln($sqlQueries);
200
-				}
201
-				$updated = true;
202
-				$output->writeln('<info>Twofactor_providers table updated successfully.</info>');
203
-			}
204
-		}
205
-
206
-		$output->writeln('<info>Check indices of the login_flow_v2 table.</info>');
207
-		if ($schema->hasTable('login_flow_v2')) {
208
-			$table = $schema->getTable('login_flow_v2');
209
-			if (!$table->hasIndex('poll_token')) {
210
-				$output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>');
211
-
212
-				foreach ($table->getIndexes() as $index) {
213
-					$columns = $index->getColumns();
214
-					if ($columns === ['poll_token'] ||
215
-						$columns === ['login_token'] ||
216
-						$columns === ['timestamp']) {
217
-						$table->dropIndex($index->getName());
218
-					}
219
-				}
220
-
221
-				$table->addUniqueIndex(['poll_token'], 'poll_token');
222
-				$table->addUniqueIndex(['login_token'], 'login_token');
223
-				$table->addIndex(['timestamp'], 'timestamp');
224
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
225
-				if ($dryRun && $sqlQueries !== null) {
226
-					$output->writeln($sqlQueries);
227
-				}
228
-				$updated = true;
229
-				$output->writeln('<info>login_flow_v2 table updated successfully.</info>');
230
-			}
231
-		}
232
-
233
-		$output->writeln('<info>Check indices of the whats_new table.</info>');
234
-		if ($schema->hasTable('whats_new')) {
235
-			$table = $schema->getTable('whats_new');
236
-			if (!$table->hasIndex('version')) {
237
-				$output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>');
238
-
239
-				foreach ($table->getIndexes() as $index) {
240
-					if ($index->getColumns() === ['version']) {
241
-						$table->dropIndex($index->getName());
242
-					}
243
-				}
244
-
245
-				$table->addUniqueIndex(['version'], 'version');
246
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
247
-				if ($dryRun && $sqlQueries !== null) {
248
-					$output->writeln($sqlQueries);
249
-				}
250
-				$updated = true;
251
-				$output->writeln('<info>whats_new table updated successfully.</info>');
252
-			}
253
-		}
254
-
255
-		$output->writeln('<info>Check indices of the cards table.</info>');
256
-		$cardsUpdated = false;
257
-		if ($schema->hasTable('cards')) {
258
-			$table = $schema->getTable('cards');
259
-
260
-			if ($table->hasIndex('addressbookid_uri_index')) {
261
-				if ($table->hasIndex('cards_abiduri')) {
262
-					$table->dropIndex('addressbookid_uri_index');
263
-				} else {
264
-					$output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>');
265
-
266
-					foreach ($table->getIndexes() as $index) {
267
-						if ($index->getColumns() === ['addressbookid', 'uri']) {
268
-							$table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
269
-						}
270
-					}
271
-				}
272
-
273
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
274
-				if ($dryRun && $sqlQueries !== null) {
275
-					$output->writeln($sqlQueries);
276
-				}
277
-				$cardsUpdated = true;
278
-			}
279
-
280
-			if (!$table->hasIndex('cards_abid')) {
281
-				$output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
282
-
283
-				foreach ($table->getIndexes() as $index) {
284
-					if ($index->getColumns() === ['addressbookid']) {
285
-						$table->dropIndex($index->getName());
286
-					}
287
-				}
288
-
289
-				$table->addIndex(['addressbookid'], 'cards_abid');
290
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
291
-				if ($dryRun && $sqlQueries !== null) {
292
-					$output->writeln($sqlQueries);
293
-				}
294
-				$cardsUpdated = true;
295
-			}
296
-
297
-			if (!$table->hasIndex('cards_abiduri')) {
298
-				$output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
299
-
300
-				foreach ($table->getIndexes() as $index) {
301
-					if ($index->getColumns() === ['addressbookid', 'uri']) {
302
-						$table->dropIndex($index->getName());
303
-					}
304
-				}
305
-
306
-				$table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
307
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
308
-				if ($dryRun && $sqlQueries !== null) {
309
-					$output->writeln($sqlQueries);
310
-				}
311
-				$cardsUpdated = true;
312
-			}
313
-
314
-			if ($cardsUpdated) {
315
-				$updated = true;
316
-				$output->writeln('<info>cards table updated successfully.</info>');
317
-			}
318
-		}
319
-
320
-		$output->writeln('<info>Check indices of the cards_properties table.</info>');
321
-		if ($schema->hasTable('cards_properties')) {
322
-			$table = $schema->getTable('cards_properties');
323
-			if (!$table->hasIndex('cards_prop_abid')) {
324
-				$output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>');
325
-
326
-				foreach ($table->getIndexes() as $index) {
327
-					if ($index->getColumns() === ['addressbookid']) {
328
-						$table->dropIndex($index->getName());
329
-					}
330
-				}
331
-
332
-				$table->addIndex(['addressbookid'], 'cards_prop_abid');
333
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
334
-				if ($dryRun && $sqlQueries !== null) {
335
-					$output->writeln($sqlQueries);
336
-				}
337
-				$updated = true;
338
-				$output->writeln('<info>cards_properties table updated successfully.</info>');
339
-			}
340
-		}
341
-
342
-		$output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
343
-		if ($schema->hasTable('calendarobjects_props')) {
344
-			$table = $schema->getTable('calendarobjects_props');
345
-			if (!$table->hasIndex('calendarobject_calid_index')) {
346
-				$output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
347
-
348
-				$table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
349
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
350
-				if ($dryRun && $sqlQueries !== null) {
351
-					$output->writeln($sqlQueries);
352
-				}
353
-				$updated = true;
354
-				$output->writeln('<info>calendarobjects_props table updated successfully.</info>');
355
-			}
356
-		}
357
-
358
-		$output->writeln('<info>Check indices of the schedulingobjects table.</info>');
359
-		if ($schema->hasTable('schedulingobjects')) {
360
-			$table = $schema->getTable('schedulingobjects');
361
-			if (!$table->hasIndex('schedulobj_principuri_index')) {
362
-				$output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
363
-
364
-				$table->addIndex(['principaluri'], 'schedulobj_principuri_index');
365
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
366
-				if ($dryRun && $sqlQueries !== null) {
367
-					$output->writeln($sqlQueries);
368
-				}
369
-				$updated = true;
370
-				$output->writeln('<info>schedulingobjects table updated successfully.</info>');
371
-			}
372
-		}
373
-
374
-		$output->writeln('<info>Check indices of the oc_properties table.</info>');
375
-		if ($schema->hasTable('properties')) {
376
-			$table = $schema->getTable('properties');
377
-			$propertiesUpdated = false;
378
-
379
-			if (!$table->hasIndex('properties_path_index')) {
380
-				$output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
381
-
382
-				$table->addIndex(['userid', 'propertypath'], 'properties_path_index');
383
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
384
-				if ($dryRun && $sqlQueries !== null) {
385
-					$output->writeln($sqlQueries);
386
-				}
387
-				$propertiesUpdated = true;
388
-			}
389
-			if (!$table->hasIndex('properties_pathonly_index')) {
390
-				$output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>');
391
-
392
-				$table->addIndex(['propertypath'], 'properties_pathonly_index');
393
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
394
-				if ($dryRun && $sqlQueries !== null) {
395
-					$output->writeln($sqlQueries);
396
-				}
397
-				$propertiesUpdated = true;
398
-			}
399
-
400
-			if ($propertiesUpdated) {
401
-				$updated = true;
402
-				$output->writeln('<info>oc_properties table updated successfully.</info>');
403
-			}
404
-		}
405
-
406
-		$output->writeln('<info>Check indices of the oc_jobs table.</info>');
407
-		if ($schema->hasTable('jobs')) {
408
-			$table = $schema->getTable('jobs');
409
-			if (!$table->hasIndex('job_lastcheck_reserved')) {
410
-				$output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>');
411
-
412
-				$table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
413
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
414
-				if ($dryRun && $sqlQueries !== null) {
415
-					$output->writeln($sqlQueries);
416
-				}
417
-				$updated = true;
418
-				$output->writeln('<info>oc_properties table updated successfully.</info>');
419
-			}
420
-		}
421
-
422
-		$output->writeln('<info>Check indices of the oc_direct_edit table.</info>');
423
-		if ($schema->hasTable('direct_edit')) {
424
-			$table = $schema->getTable('direct_edit');
425
-			if (!$table->hasIndex('direct_edit_timestamp')) {
426
-				$output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>');
427
-
428
-				$table->addIndex(['timestamp'], 'direct_edit_timestamp');
429
-				$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
430
-				if ($dryRun && $sqlQueries !== null) {
431
-					$output->writeln($sqlQueries);
432
-				}
433
-				$updated = true;
434
-				$output->writeln('<info>oc_direct_edit table updated successfully.</info>');
435
-			}
436
-		}
437
-
438
-		$output->writeln('<info>Check indices of the oc_preferences table.</info>');
439
-		if ($schema->hasTable('preferences')) {
440
-			$table = $schema->getTable('preferences');
441
-			if (!$table->hasIndex('preferences_app_key')) {
442
-				$output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>');
443
-
444
-				$table->addIndex(['appid', 'configkey'], 'preferences_app_key');
445
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
446
-				$updated = true;
447
-				$output->writeln('<info>oc_properties table updated successfully.</info>');
448
-			}
449
-		}
450
-
451
-		if (!$updated) {
452
-			$output->writeln('<info>Done.</info>');
453
-		}
454
-	}
57
+    /** @var Connection */
58
+    private $connection;
59
+
60
+    /** @var EventDispatcherInterface */
61
+    private $dispatcher;
62
+
63
+    public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
64
+        parent::__construct();
65
+
66
+        $this->connection = $connection;
67
+        $this->dispatcher = $dispatcher;
68
+    }
69
+
70
+    protected function configure() {
71
+        $this
72
+            ->setName('db:add-missing-indices')
73
+            ->setDescription('Add missing indices to the database tables')
74
+            ->addOption('dry-run', null, InputOption::VALUE_NONE, "Output the SQL queries instead of running them.");
75
+    }
76
+
77
+    protected function execute(InputInterface $input, OutputInterface $output): int {
78
+        $this->addCoreIndexes($output, $input->getOption('dry-run'));
79
+
80
+        // Dispatch event so apps can also update indexes if needed
81
+        $event = new GenericEvent($output);
82
+        $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
83
+        return 0;
84
+    }
85
+
86
+    /**
87
+     * add missing indices to the share table
88
+     *
89
+     * @param OutputInterface $output
90
+     * @param bool $dryRun If true, will return the sql queries instead of running them.
91
+     * @throws \Doctrine\DBAL\Schema\SchemaException
92
+     */
93
+    private function addCoreIndexes(OutputInterface $output, bool $dryRun): void {
94
+        $output->writeln('<info>Check indices of the share table.</info>');
95
+
96
+        $schema = new SchemaWrapper($this->connection);
97
+        $updated = false;
98
+
99
+        if ($schema->hasTable('share')) {
100
+            $table = $schema->getTable('share');
101
+            if (!$table->hasIndex('share_with_index')) {
102
+                $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
103
+                $table->addIndex(['share_with'], 'share_with_index');
104
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
105
+                if ($dryRun && $sqlQueries !== null) {
106
+                    $output->writeln($sqlQueries);
107
+                }
108
+                $updated = true;
109
+                $output->writeln('<info>Share table updated successfully.</info>');
110
+            }
111
+
112
+            if (!$table->hasIndex('parent_index')) {
113
+                $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
114
+                $table->addIndex(['parent'], 'parent_index');
115
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
116
+                if ($dryRun && $sqlQueries !== null) {
117
+                    $output->writeln($sqlQueries);
118
+                }
119
+                $updated = true;
120
+                $output->writeln('<info>Share table updated successfully.</info>');
121
+            }
122
+
123
+            if (!$table->hasIndex('owner_index')) {
124
+                $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
125
+                $table->addIndex(['uid_owner'], 'owner_index');
126
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
127
+                if ($dryRun && $sqlQueries !== null) {
128
+                    $output->writeln($sqlQueries);
129
+                }
130
+                $updated = true;
131
+                $output->writeln('<info>Share table updated successfully.</info>');
132
+            }
133
+
134
+            if (!$table->hasIndex('initiator_index')) {
135
+                $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
136
+                $table->addIndex(['uid_initiator'], 'initiator_index');
137
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
138
+                if ($dryRun && $sqlQueries !== null) {
139
+                    $output->writeln($sqlQueries);
140
+                }
141
+                $updated = true;
142
+                $output->writeln('<info>Share table updated successfully.</info>');
143
+            }
144
+        }
145
+
146
+        $output->writeln('<info>Check indices of the filecache table.</info>');
147
+        if ($schema->hasTable('filecache')) {
148
+            $table = $schema->getTable('filecache');
149
+            if (!$table->hasIndex('fs_mtime')) {
150
+                $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
151
+                $table->addIndex(['mtime'], 'fs_mtime');
152
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
153
+                if ($dryRun && $sqlQueries !== null) {
154
+                    $output->writeln($sqlQueries);
155
+                }
156
+                $updated = true;
157
+                $output->writeln('<info>Filecache table updated successfully.</info>');
158
+            }
159
+            if (!$table->hasIndex('fs_size')) {
160
+                $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
161
+                $table->addIndex(['size'], 'fs_size');
162
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
163
+                if ($dryRun && $sqlQueries !== null) {
164
+                    $output->writeln($sqlQueries);
165
+                }
166
+                $updated = true;
167
+                $output->writeln('<info>Filecache table updated successfully.</info>');
168
+            }
169
+            if (!$table->hasIndex('fs_id_storage_size')) {
170
+                $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
171
+                $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
172
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
173
+                if ($dryRun && $sqlQueries !== null) {
174
+                    $output->writeln($sqlQueries);
175
+                }
176
+                $updated = true;
177
+                $output->writeln('<info>Filecache table updated successfully.</info>');
178
+            }
179
+            if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
180
+                $output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>');
181
+                $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
182
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
183
+                if ($dryRun && $sqlQueries !== null) {
184
+                    $output->writeln($sqlQueries);
185
+                }
186
+                $updated = true;
187
+                $output->writeln('<info>Filecache table updated successfully.</info>');
188
+            }
189
+        }
190
+
191
+        $output->writeln('<info>Check indices of the twofactor_providers table.</info>');
192
+        if ($schema->hasTable('twofactor_providers')) {
193
+            $table = $schema->getTable('twofactor_providers');
194
+            if (!$table->hasIndex('twofactor_providers_uid')) {
195
+                $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
196
+                $table->addIndex(['uid'], 'twofactor_providers_uid');
197
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
198
+                if ($dryRun && $sqlQueries !== null) {
199
+                    $output->writeln($sqlQueries);
200
+                }
201
+                $updated = true;
202
+                $output->writeln('<info>Twofactor_providers table updated successfully.</info>');
203
+            }
204
+        }
205
+
206
+        $output->writeln('<info>Check indices of the login_flow_v2 table.</info>');
207
+        if ($schema->hasTable('login_flow_v2')) {
208
+            $table = $schema->getTable('login_flow_v2');
209
+            if (!$table->hasIndex('poll_token')) {
210
+                $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>');
211
+
212
+                foreach ($table->getIndexes() as $index) {
213
+                    $columns = $index->getColumns();
214
+                    if ($columns === ['poll_token'] ||
215
+                        $columns === ['login_token'] ||
216
+                        $columns === ['timestamp']) {
217
+                        $table->dropIndex($index->getName());
218
+                    }
219
+                }
220
+
221
+                $table->addUniqueIndex(['poll_token'], 'poll_token');
222
+                $table->addUniqueIndex(['login_token'], 'login_token');
223
+                $table->addIndex(['timestamp'], 'timestamp');
224
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
225
+                if ($dryRun && $sqlQueries !== null) {
226
+                    $output->writeln($sqlQueries);
227
+                }
228
+                $updated = true;
229
+                $output->writeln('<info>login_flow_v2 table updated successfully.</info>');
230
+            }
231
+        }
232
+
233
+        $output->writeln('<info>Check indices of the whats_new table.</info>');
234
+        if ($schema->hasTable('whats_new')) {
235
+            $table = $schema->getTable('whats_new');
236
+            if (!$table->hasIndex('version')) {
237
+                $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>');
238
+
239
+                foreach ($table->getIndexes() as $index) {
240
+                    if ($index->getColumns() === ['version']) {
241
+                        $table->dropIndex($index->getName());
242
+                    }
243
+                }
244
+
245
+                $table->addUniqueIndex(['version'], 'version');
246
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
247
+                if ($dryRun && $sqlQueries !== null) {
248
+                    $output->writeln($sqlQueries);
249
+                }
250
+                $updated = true;
251
+                $output->writeln('<info>whats_new table updated successfully.</info>');
252
+            }
253
+        }
254
+
255
+        $output->writeln('<info>Check indices of the cards table.</info>');
256
+        $cardsUpdated = false;
257
+        if ($schema->hasTable('cards')) {
258
+            $table = $schema->getTable('cards');
259
+
260
+            if ($table->hasIndex('addressbookid_uri_index')) {
261
+                if ($table->hasIndex('cards_abiduri')) {
262
+                    $table->dropIndex('addressbookid_uri_index');
263
+                } else {
264
+                    $output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>');
265
+
266
+                    foreach ($table->getIndexes() as $index) {
267
+                        if ($index->getColumns() === ['addressbookid', 'uri']) {
268
+                            $table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
269
+                        }
270
+                    }
271
+                }
272
+
273
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
274
+                if ($dryRun && $sqlQueries !== null) {
275
+                    $output->writeln($sqlQueries);
276
+                }
277
+                $cardsUpdated = true;
278
+            }
279
+
280
+            if (!$table->hasIndex('cards_abid')) {
281
+                $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
282
+
283
+                foreach ($table->getIndexes() as $index) {
284
+                    if ($index->getColumns() === ['addressbookid']) {
285
+                        $table->dropIndex($index->getName());
286
+                    }
287
+                }
288
+
289
+                $table->addIndex(['addressbookid'], 'cards_abid');
290
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
291
+                if ($dryRun && $sqlQueries !== null) {
292
+                    $output->writeln($sqlQueries);
293
+                }
294
+                $cardsUpdated = true;
295
+            }
296
+
297
+            if (!$table->hasIndex('cards_abiduri')) {
298
+                $output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
299
+
300
+                foreach ($table->getIndexes() as $index) {
301
+                    if ($index->getColumns() === ['addressbookid', 'uri']) {
302
+                        $table->dropIndex($index->getName());
303
+                    }
304
+                }
305
+
306
+                $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
307
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
308
+                if ($dryRun && $sqlQueries !== null) {
309
+                    $output->writeln($sqlQueries);
310
+                }
311
+                $cardsUpdated = true;
312
+            }
313
+
314
+            if ($cardsUpdated) {
315
+                $updated = true;
316
+                $output->writeln('<info>cards table updated successfully.</info>');
317
+            }
318
+        }
319
+
320
+        $output->writeln('<info>Check indices of the cards_properties table.</info>');
321
+        if ($schema->hasTable('cards_properties')) {
322
+            $table = $schema->getTable('cards_properties');
323
+            if (!$table->hasIndex('cards_prop_abid')) {
324
+                $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>');
325
+
326
+                foreach ($table->getIndexes() as $index) {
327
+                    if ($index->getColumns() === ['addressbookid']) {
328
+                        $table->dropIndex($index->getName());
329
+                    }
330
+                }
331
+
332
+                $table->addIndex(['addressbookid'], 'cards_prop_abid');
333
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
334
+                if ($dryRun && $sqlQueries !== null) {
335
+                    $output->writeln($sqlQueries);
336
+                }
337
+                $updated = true;
338
+                $output->writeln('<info>cards_properties table updated successfully.</info>');
339
+            }
340
+        }
341
+
342
+        $output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
343
+        if ($schema->hasTable('calendarobjects_props')) {
344
+            $table = $schema->getTable('calendarobjects_props');
345
+            if (!$table->hasIndex('calendarobject_calid_index')) {
346
+                $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
347
+
348
+                $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
349
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
350
+                if ($dryRun && $sqlQueries !== null) {
351
+                    $output->writeln($sqlQueries);
352
+                }
353
+                $updated = true;
354
+                $output->writeln('<info>calendarobjects_props table updated successfully.</info>');
355
+            }
356
+        }
357
+
358
+        $output->writeln('<info>Check indices of the schedulingobjects table.</info>');
359
+        if ($schema->hasTable('schedulingobjects')) {
360
+            $table = $schema->getTable('schedulingobjects');
361
+            if (!$table->hasIndex('schedulobj_principuri_index')) {
362
+                $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
363
+
364
+                $table->addIndex(['principaluri'], 'schedulobj_principuri_index');
365
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
366
+                if ($dryRun && $sqlQueries !== null) {
367
+                    $output->writeln($sqlQueries);
368
+                }
369
+                $updated = true;
370
+                $output->writeln('<info>schedulingobjects table updated successfully.</info>');
371
+            }
372
+        }
373
+
374
+        $output->writeln('<info>Check indices of the oc_properties table.</info>');
375
+        if ($schema->hasTable('properties')) {
376
+            $table = $schema->getTable('properties');
377
+            $propertiesUpdated = false;
378
+
379
+            if (!$table->hasIndex('properties_path_index')) {
380
+                $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
381
+
382
+                $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
383
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
384
+                if ($dryRun && $sqlQueries !== null) {
385
+                    $output->writeln($sqlQueries);
386
+                }
387
+                $propertiesUpdated = true;
388
+            }
389
+            if (!$table->hasIndex('properties_pathonly_index')) {
390
+                $output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>');
391
+
392
+                $table->addIndex(['propertypath'], 'properties_pathonly_index');
393
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
394
+                if ($dryRun && $sqlQueries !== null) {
395
+                    $output->writeln($sqlQueries);
396
+                }
397
+                $propertiesUpdated = true;
398
+            }
399
+
400
+            if ($propertiesUpdated) {
401
+                $updated = true;
402
+                $output->writeln('<info>oc_properties table updated successfully.</info>');
403
+            }
404
+        }
405
+
406
+        $output->writeln('<info>Check indices of the oc_jobs table.</info>');
407
+        if ($schema->hasTable('jobs')) {
408
+            $table = $schema->getTable('jobs');
409
+            if (!$table->hasIndex('job_lastcheck_reserved')) {
410
+                $output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>');
411
+
412
+                $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
413
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
414
+                if ($dryRun && $sqlQueries !== null) {
415
+                    $output->writeln($sqlQueries);
416
+                }
417
+                $updated = true;
418
+                $output->writeln('<info>oc_properties table updated successfully.</info>');
419
+            }
420
+        }
421
+
422
+        $output->writeln('<info>Check indices of the oc_direct_edit table.</info>');
423
+        if ($schema->hasTable('direct_edit')) {
424
+            $table = $schema->getTable('direct_edit');
425
+            if (!$table->hasIndex('direct_edit_timestamp')) {
426
+                $output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>');
427
+
428
+                $table->addIndex(['timestamp'], 'direct_edit_timestamp');
429
+                $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
430
+                if ($dryRun && $sqlQueries !== null) {
431
+                    $output->writeln($sqlQueries);
432
+                }
433
+                $updated = true;
434
+                $output->writeln('<info>oc_direct_edit table updated successfully.</info>');
435
+            }
436
+        }
437
+
438
+        $output->writeln('<info>Check indices of the oc_preferences table.</info>');
439
+        if ($schema->hasTable('preferences')) {
440
+            $table = $schema->getTable('preferences');
441
+            if (!$table->hasIndex('preferences_app_key')) {
442
+                $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>');
443
+
444
+                $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
445
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
446
+                $updated = true;
447
+                $output->writeln('<info>oc_properties table updated successfully.</info>');
448
+            }
449
+        }
450
+
451
+        if (!$updated) {
452
+            $output->writeln('<info>Done.</info>');
453
+        }
454
+    }
455 455
 }
Please login to merge, or discard this patch.
core/Application.php 1 patch
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -67,261 +67,261 @@
 block discarded – undo
67 67
  * @package OC\Core
68 68
  */
69 69
 class Application extends App {
70
-	public function __construct() {
71
-		parent::__construct('core');
72
-
73
-		$container = $this->getContainer();
74
-
75
-		$container->registerService('defaultMailAddress', function () {
76
-			return Util::getDefaultEmailAddress('lostpassword-noreply');
77
-		});
78
-
79
-		$server = $container->getServer();
80
-		/** @var IEventDispatcher $eventDispatcher */
81
-		$eventDispatcher = $server->query(IEventDispatcher::class);
82
-
83
-		$notificationManager = $server->getNotificationManager();
84
-		$notificationManager->registerNotifierService(CoreNotifier::class);
85
-		$notificationManager->registerNotifierService(AuthenticationNotifier::class);
86
-
87
-		$oldEventDispatcher = $server->getEventDispatcher();
88
-
89
-		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
90
-			function (GenericEvent $event) use ($container) {
91
-				/** @var MissingIndexInformation $subject */
92
-				$subject = $event->getSubject();
93
-
94
-				$schema = new SchemaWrapper($container->query(Connection::class));
95
-
96
-				if ($schema->hasTable('share')) {
97
-					$table = $schema->getTable('share');
98
-
99
-					if (!$table->hasIndex('share_with_index')) {
100
-						$subject->addHintForMissingSubject($table->getName(), 'share_with_index');
101
-					}
102
-					if (!$table->hasIndex('parent_index')) {
103
-						$subject->addHintForMissingSubject($table->getName(), 'parent_index');
104
-					}
105
-					if (!$table->hasIndex('owner_index')) {
106
-						$subject->addHintForMissingSubject($table->getName(), 'owner_index');
107
-					}
108
-					if (!$table->hasIndex('initiator_index')) {
109
-						$subject->addHintForMissingSubject($table->getName(), 'initiator_index');
110
-					}
111
-				}
112
-
113
-				if ($schema->hasTable('filecache')) {
114
-					$table = $schema->getTable('filecache');
115
-
116
-					if (!$table->hasIndex('fs_mtime')) {
117
-						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
118
-					}
119
-
120
-					if (!$table->hasIndex('fs_size')) {
121
-						$subject->addHintForMissingSubject($table->getName(), 'fs_size');
122
-					}
123
-
124
-					if (!$table->hasIndex('fs_id_storage_size')) {
125
-						$subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size');
126
-					}
127
-
128
-					if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
129
-						$subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix');
130
-					}
131
-				}
132
-
133
-				if ($schema->hasTable('twofactor_providers')) {
134
-					$table = $schema->getTable('twofactor_providers');
135
-
136
-					if (!$table->hasIndex('twofactor_providers_uid')) {
137
-						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
138
-					}
139
-				}
140
-
141
-				if ($schema->hasTable('login_flow_v2')) {
142
-					$table = $schema->getTable('login_flow_v2');
143
-
144
-					if (!$table->hasIndex('poll_token')) {
145
-						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
146
-					}
147
-					if (!$table->hasIndex('login_token')) {
148
-						$subject->addHintForMissingSubject($table->getName(), 'login_token');
149
-					}
150
-					if (!$table->hasIndex('timestamp')) {
151
-						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
152
-					}
153
-				}
154
-
155
-				if ($schema->hasTable('whats_new')) {
156
-					$table = $schema->getTable('whats_new');
157
-
158
-					if (!$table->hasIndex('version')) {
159
-						$subject->addHintForMissingSubject($table->getName(), 'version');
160
-					}
161
-				}
162
-
163
-				if ($schema->hasTable('cards')) {
164
-					$table = $schema->getTable('cards');
165
-
166
-					if (!$table->hasIndex('cards_abid')) {
167
-						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
168
-					}
169
-
170
-					if (!$table->hasIndex('cards_abiduri')) {
171
-						$subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
172
-					}
173
-				}
174
-
175
-				if ($schema->hasTable('cards_properties')) {
176
-					$table = $schema->getTable('cards_properties');
177
-
178
-					if (!$table->hasIndex('cards_prop_abid')) {
179
-						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
180
-					}
181
-				}
182
-
183
-				if ($schema->hasTable('calendarobjects_props')) {
184
-					$table = $schema->getTable('calendarobjects_props');
185
-
186
-					if (!$table->hasIndex('calendarobject_calid_index')) {
187
-						$subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
188
-					}
189
-				}
190
-
191
-				if ($schema->hasTable('schedulingobjects')) {
192
-					$table = $schema->getTable('schedulingobjects');
193
-					if (!$table->hasIndex('schedulobj_principuri_index')) {
194
-						$subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
195
-					}
196
-				}
197
-
198
-				if ($schema->hasTable('properties')) {
199
-					$table = $schema->getTable('properties');
200
-					if (!$table->hasIndex('properties_path_index')) {
201
-						$subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
202
-					}
203
-					if (!$table->hasIndex('properties_pathonly_index')) {
204
-						$subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index');
205
-					}
206
-				}
207
-
208
-				if ($schema->hasTable('jobs')) {
209
-					$table = $schema->getTable('jobs');
210
-					if (!$table->hasIndex('job_lastcheck_reserved')) {
211
-						$subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved');
212
-					}
213
-				}
214
-
215
-				if ($schema->hasTable('direct_edit')) {
216
-					$table = $schema->getTable('direct_edit');
217
-					if (!$table->hasIndex('direct_edit_timestamp')) {
218
-						$subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp');
219
-					}
220
-				}
221
-
222
-				if ($schema->hasTable('preferences')) {
223
-					$table = $schema->getTable('preferences');
224
-					if (!$table->hasIndex('preferences_app_key')) {
225
-						$subject->addHintForMissingSubject($table->getName(), 'preferences_app_key');
226
-					}
227
-				}
228
-			}
229
-		);
230
-
231
-		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
232
-			function (GenericEvent $event) use ($container) {
233
-				/** @var MissingPrimaryKeyInformation $subject */
234
-				$subject = $event->getSubject();
235
-
236
-				$schema = new SchemaWrapper($container->query(Connection::class));
237
-
238
-				if ($schema->hasTable('federated_reshares')) {
239
-					$table = $schema->getTable('federated_reshares');
240
-
241
-					if (!$table->hasPrimaryKey()) {
242
-						$subject->addHintForMissingSubject($table->getName());
243
-					}
244
-				}
245
-
246
-				if ($schema->hasTable('systemtag_object_mapping')) {
247
-					$table = $schema->getTable('systemtag_object_mapping');
248
-
249
-					if (!$table->hasPrimaryKey()) {
250
-						$subject->addHintForMissingSubject($table->getName());
251
-					}
252
-				}
253
-
254
-				if ($schema->hasTable('comments_read_markers')) {
255
-					$table = $schema->getTable('comments_read_markers');
256
-
257
-					if (!$table->hasPrimaryKey()) {
258
-						$subject->addHintForMissingSubject($table->getName());
259
-					}
260
-				}
261
-
262
-				if ($schema->hasTable('collres_resources')) {
263
-					$table = $schema->getTable('collres_resources');
264
-
265
-					if (!$table->hasPrimaryKey()) {
266
-						$subject->addHintForMissingSubject($table->getName());
267
-					}
268
-				}
269
-
270
-				if ($schema->hasTable('collres_accesscache')) {
271
-					$table = $schema->getTable('collres_accesscache');
272
-
273
-					if (!$table->hasPrimaryKey()) {
274
-						$subject->addHintForMissingSubject($table->getName());
275
-					}
276
-				}
277
-
278
-				if ($schema->hasTable('filecache_extended')) {
279
-					$table = $schema->getTable('filecache_extended');
280
-
281
-					if (!$table->hasPrimaryKey()) {
282
-						$subject->addHintForMissingSubject($table->getName());
283
-					}
284
-				}
285
-			}
286
-		);
287
-
288
-		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
289
-			function (GenericEvent $event) use ($container) {
290
-				/** @var MissingColumnInformation $subject */
291
-				$subject = $event->getSubject();
292
-
293
-				$schema = new SchemaWrapper($container->query(Connection::class));
294
-
295
-				if ($schema->hasTable('comments')) {
296
-					$table = $schema->getTable('comments');
297
-
298
-					if (!$table->hasColumn('reference_id')) {
299
-						$subject->addHintForMissingColumn($table->getName(), 'reference_id');
300
-					}
301
-				}
302
-			}
303
-		);
304
-
305
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
306
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
307
-		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
308
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
309
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
310
-		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
311
-		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
312
-		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
313
-		$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
314
-		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
315
-		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
316
-
317
-		// Metadata
318
-		/** @var IConfig $config */
319
-		$config = $container->get(IConfig::class);
320
-		if ($config->getSystemValueBool('enable_file_metadata', true)) {
321
-			$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
322
-			$eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
323
-			$eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
324
-			$eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
325
-		}
326
-	}
70
+    public function __construct() {
71
+        parent::__construct('core');
72
+
73
+        $container = $this->getContainer();
74
+
75
+        $container->registerService('defaultMailAddress', function () {
76
+            return Util::getDefaultEmailAddress('lostpassword-noreply');
77
+        });
78
+
79
+        $server = $container->getServer();
80
+        /** @var IEventDispatcher $eventDispatcher */
81
+        $eventDispatcher = $server->query(IEventDispatcher::class);
82
+
83
+        $notificationManager = $server->getNotificationManager();
84
+        $notificationManager->registerNotifierService(CoreNotifier::class);
85
+        $notificationManager->registerNotifierService(AuthenticationNotifier::class);
86
+
87
+        $oldEventDispatcher = $server->getEventDispatcher();
88
+
89
+        $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
90
+            function (GenericEvent $event) use ($container) {
91
+                /** @var MissingIndexInformation $subject */
92
+                $subject = $event->getSubject();
93
+
94
+                $schema = new SchemaWrapper($container->query(Connection::class));
95
+
96
+                if ($schema->hasTable('share')) {
97
+                    $table = $schema->getTable('share');
98
+
99
+                    if (!$table->hasIndex('share_with_index')) {
100
+                        $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
101
+                    }
102
+                    if (!$table->hasIndex('parent_index')) {
103
+                        $subject->addHintForMissingSubject($table->getName(), 'parent_index');
104
+                    }
105
+                    if (!$table->hasIndex('owner_index')) {
106
+                        $subject->addHintForMissingSubject($table->getName(), 'owner_index');
107
+                    }
108
+                    if (!$table->hasIndex('initiator_index')) {
109
+                        $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
110
+                    }
111
+                }
112
+
113
+                if ($schema->hasTable('filecache')) {
114
+                    $table = $schema->getTable('filecache');
115
+
116
+                    if (!$table->hasIndex('fs_mtime')) {
117
+                        $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
118
+                    }
119
+
120
+                    if (!$table->hasIndex('fs_size')) {
121
+                        $subject->addHintForMissingSubject($table->getName(), 'fs_size');
122
+                    }
123
+
124
+                    if (!$table->hasIndex('fs_id_storage_size')) {
125
+                        $subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size');
126
+                    }
127
+
128
+                    if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
129
+                        $subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix');
130
+                    }
131
+                }
132
+
133
+                if ($schema->hasTable('twofactor_providers')) {
134
+                    $table = $schema->getTable('twofactor_providers');
135
+
136
+                    if (!$table->hasIndex('twofactor_providers_uid')) {
137
+                        $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
138
+                    }
139
+                }
140
+
141
+                if ($schema->hasTable('login_flow_v2')) {
142
+                    $table = $schema->getTable('login_flow_v2');
143
+
144
+                    if (!$table->hasIndex('poll_token')) {
145
+                        $subject->addHintForMissingSubject($table->getName(), 'poll_token');
146
+                    }
147
+                    if (!$table->hasIndex('login_token')) {
148
+                        $subject->addHintForMissingSubject($table->getName(), 'login_token');
149
+                    }
150
+                    if (!$table->hasIndex('timestamp')) {
151
+                        $subject->addHintForMissingSubject($table->getName(), 'timestamp');
152
+                    }
153
+                }
154
+
155
+                if ($schema->hasTable('whats_new')) {
156
+                    $table = $schema->getTable('whats_new');
157
+
158
+                    if (!$table->hasIndex('version')) {
159
+                        $subject->addHintForMissingSubject($table->getName(), 'version');
160
+                    }
161
+                }
162
+
163
+                if ($schema->hasTable('cards')) {
164
+                    $table = $schema->getTable('cards');
165
+
166
+                    if (!$table->hasIndex('cards_abid')) {
167
+                        $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
168
+                    }
169
+
170
+                    if (!$table->hasIndex('cards_abiduri')) {
171
+                        $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
172
+                    }
173
+                }
174
+
175
+                if ($schema->hasTable('cards_properties')) {
176
+                    $table = $schema->getTable('cards_properties');
177
+
178
+                    if (!$table->hasIndex('cards_prop_abid')) {
179
+                        $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
180
+                    }
181
+                }
182
+
183
+                if ($schema->hasTable('calendarobjects_props')) {
184
+                    $table = $schema->getTable('calendarobjects_props');
185
+
186
+                    if (!$table->hasIndex('calendarobject_calid_index')) {
187
+                        $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
188
+                    }
189
+                }
190
+
191
+                if ($schema->hasTable('schedulingobjects')) {
192
+                    $table = $schema->getTable('schedulingobjects');
193
+                    if (!$table->hasIndex('schedulobj_principuri_index')) {
194
+                        $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
195
+                    }
196
+                }
197
+
198
+                if ($schema->hasTable('properties')) {
199
+                    $table = $schema->getTable('properties');
200
+                    if (!$table->hasIndex('properties_path_index')) {
201
+                        $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
202
+                    }
203
+                    if (!$table->hasIndex('properties_pathonly_index')) {
204
+                        $subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index');
205
+                    }
206
+                }
207
+
208
+                if ($schema->hasTable('jobs')) {
209
+                    $table = $schema->getTable('jobs');
210
+                    if (!$table->hasIndex('job_lastcheck_reserved')) {
211
+                        $subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved');
212
+                    }
213
+                }
214
+
215
+                if ($schema->hasTable('direct_edit')) {
216
+                    $table = $schema->getTable('direct_edit');
217
+                    if (!$table->hasIndex('direct_edit_timestamp')) {
218
+                        $subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp');
219
+                    }
220
+                }
221
+
222
+                if ($schema->hasTable('preferences')) {
223
+                    $table = $schema->getTable('preferences');
224
+                    if (!$table->hasIndex('preferences_app_key')) {
225
+                        $subject->addHintForMissingSubject($table->getName(), 'preferences_app_key');
226
+                    }
227
+                }
228
+            }
229
+        );
230
+
231
+        $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
232
+            function (GenericEvent $event) use ($container) {
233
+                /** @var MissingPrimaryKeyInformation $subject */
234
+                $subject = $event->getSubject();
235
+
236
+                $schema = new SchemaWrapper($container->query(Connection::class));
237
+
238
+                if ($schema->hasTable('federated_reshares')) {
239
+                    $table = $schema->getTable('federated_reshares');
240
+
241
+                    if (!$table->hasPrimaryKey()) {
242
+                        $subject->addHintForMissingSubject($table->getName());
243
+                    }
244
+                }
245
+
246
+                if ($schema->hasTable('systemtag_object_mapping')) {
247
+                    $table = $schema->getTable('systemtag_object_mapping');
248
+
249
+                    if (!$table->hasPrimaryKey()) {
250
+                        $subject->addHintForMissingSubject($table->getName());
251
+                    }
252
+                }
253
+
254
+                if ($schema->hasTable('comments_read_markers')) {
255
+                    $table = $schema->getTable('comments_read_markers');
256
+
257
+                    if (!$table->hasPrimaryKey()) {
258
+                        $subject->addHintForMissingSubject($table->getName());
259
+                    }
260
+                }
261
+
262
+                if ($schema->hasTable('collres_resources')) {
263
+                    $table = $schema->getTable('collres_resources');
264
+
265
+                    if (!$table->hasPrimaryKey()) {
266
+                        $subject->addHintForMissingSubject($table->getName());
267
+                    }
268
+                }
269
+
270
+                if ($schema->hasTable('collres_accesscache')) {
271
+                    $table = $schema->getTable('collres_accesscache');
272
+
273
+                    if (!$table->hasPrimaryKey()) {
274
+                        $subject->addHintForMissingSubject($table->getName());
275
+                    }
276
+                }
277
+
278
+                if ($schema->hasTable('filecache_extended')) {
279
+                    $table = $schema->getTable('filecache_extended');
280
+
281
+                    if (!$table->hasPrimaryKey()) {
282
+                        $subject->addHintForMissingSubject($table->getName());
283
+                    }
284
+                }
285
+            }
286
+        );
287
+
288
+        $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
289
+            function (GenericEvent $event) use ($container) {
290
+                /** @var MissingColumnInformation $subject */
291
+                $subject = $event->getSubject();
292
+
293
+                $schema = new SchemaWrapper($container->query(Connection::class));
294
+
295
+                if ($schema->hasTable('comments')) {
296
+                    $table = $schema->getTable('comments');
297
+
298
+                    if (!$table->hasColumn('reference_id')) {
299
+                        $subject->addHintForMissingColumn($table->getName(), 'reference_id');
300
+                    }
301
+                }
302
+            }
303
+        );
304
+
305
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
306
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
307
+        $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
308
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
309
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
310
+        $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
311
+        $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
312
+        $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
313
+        $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
314
+        $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
315
+        $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
316
+
317
+        // Metadata
318
+        /** @var IConfig $config */
319
+        $config = $container->get(IConfig::class);
320
+        if ($config->getSystemValueBool('enable_file_metadata', true)) {
321
+            $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
322
+            $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
323
+            $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
324
+            $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
325
+        }
326
+    }
327 327
 }
Please login to merge, or discard this patch.
lib/private/AllConfig.php 1 patch
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -40,515 +40,515 @@
 block discarded – undo
40 40
  * Class to combine all the configuration options ownCloud offers
41 41
  */
42 42
 class AllConfig implements \OCP\IConfig {
43
-	/** @var SystemConfig */
44
-	private $systemConfig;
45
-
46
-	/** @var IDBConnection */
47
-	private $connection;
48
-
49
-	/**
50
-	 * 3 dimensional array with the following structure:
51
-	 * [ $userId =>
52
-	 *     [ $appId =>
53
-	 *         [ $key => $value ]
54
-	 *     ]
55
-	 * ]
56
-	 *
57
-	 * database table: preferences
58
-	 *
59
-	 * methods that use this:
60
-	 *   - setUserValue
61
-	 *   - getUserValue
62
-	 *   - getUserKeys
63
-	 *   - deleteUserValue
64
-	 *   - deleteAllUserValues
65
-	 *   - deleteAppFromAllUsers
66
-	 *
67
-	 * @var CappedMemoryCache $userCache
68
-	 */
69
-	private $userCache;
70
-
71
-	/**
72
-	 * @param SystemConfig $systemConfig
73
-	 */
74
-	public function __construct(SystemConfig $systemConfig) {
75
-		$this->userCache = new CappedMemoryCache();
76
-		$this->systemConfig = $systemConfig;
77
-	}
78
-
79
-	/**
80
-	 * TODO - FIXME This fixes an issue with base.php that cause cyclic
81
-	 * dependencies, especially with autoconfig setup
82
-	 *
83
-	 * Replace this by properly injected database connection. Currently the
84
-	 * base.php triggers the getDatabaseConnection too early which causes in
85
-	 * autoconfig setup case a too early distributed database connection and
86
-	 * the autoconfig then needs to reinit all already initialized dependencies
87
-	 * that use the database connection.
88
-	 *
89
-	 * otherwise a SQLite database is created in the wrong directory
90
-	 * because the database connection was created with an uninitialized config
91
-	 */
92
-	private function fixDIInit() {
93
-		if ($this->connection === null) {
94
-			$this->connection = \OC::$server->getDatabaseConnection();
95
-		}
96
-	}
97
-
98
-	/**
99
-	 * Sets and deletes system wide values
100
-	 *
101
-	 * @param array $configs Associative array with `key => value` pairs
102
-	 *                       If value is null, the config key will be deleted
103
-	 */
104
-	public function setSystemValues(array $configs) {
105
-		$this->systemConfig->setValues($configs);
106
-	}
107
-
108
-	/**
109
-	 * Sets a new system wide value
110
-	 *
111
-	 * @param string $key the key of the value, under which will be saved
112
-	 * @param mixed $value the value that should be stored
113
-	 */
114
-	public function setSystemValue($key, $value) {
115
-		$this->systemConfig->setValue($key, $value);
116
-	}
117
-
118
-	/**
119
-	 * Looks up a system wide defined value
120
-	 *
121
-	 * @param string $key the key of the value, under which it was saved
122
-	 * @param mixed $default the default value to be returned if the value isn't set
123
-	 * @return mixed the value or $default
124
-	 */
125
-	public function getSystemValue($key, $default = '') {
126
-		return $this->systemConfig->getValue($key, $default);
127
-	}
128
-
129
-	/**
130
-	 * Looks up a boolean system wide defined value
131
-	 *
132
-	 * @param string $key the key of the value, under which it was saved
133
-	 * @param bool $default the default value to be returned if the value isn't set
134
-	 *
135
-	 * @return bool
136
-	 *
137
-	 * @since 16.0.0
138
-	 */
139
-	public function getSystemValueBool(string $key, bool $default = false): bool {
140
-		return (bool) $this->getSystemValue($key, $default);
141
-	}
142
-
143
-	/**
144
-	 * Looks up an integer system wide defined value
145
-	 *
146
-	 * @param string $key the key of the value, under which it was saved
147
-	 * @param int $default the default value to be returned if the value isn't set
148
-	 *
149
-	 * @return int
150
-	 *
151
-	 * @since 16.0.0
152
-	 */
153
-	public function getSystemValueInt(string $key, int $default = 0): int {
154
-		return (int) $this->getSystemValue($key, $default);
155
-	}
156
-
157
-	/**
158
-	 * Looks up a string system wide defined value
159
-	 *
160
-	 * @param string $key the key of the value, under which it was saved
161
-	 * @param string $default the default value to be returned if the value isn't set
162
-	 *
163
-	 * @return string
164
-	 *
165
-	 * @since 16.0.0
166
-	 */
167
-	public function getSystemValueString(string $key, string $default = ''): string {
168
-		return (string) $this->getSystemValue($key, $default);
169
-	}
170
-
171
-	/**
172
-	 * Looks up a system wide defined value and filters out sensitive data
173
-	 *
174
-	 * @param string $key the key of the value, under which it was saved
175
-	 * @param mixed $default the default value to be returned if the value isn't set
176
-	 * @return mixed the value or $default
177
-	 */
178
-	public function getFilteredSystemValue($key, $default = '') {
179
-		return $this->systemConfig->getFilteredValue($key, $default);
180
-	}
181
-
182
-	/**
183
-	 * Delete a system wide defined value
184
-	 *
185
-	 * @param string $key the key of the value, under which it was saved
186
-	 */
187
-	public function deleteSystemValue($key) {
188
-		$this->systemConfig->deleteValue($key);
189
-	}
190
-
191
-	/**
192
-	 * Get all keys stored for an app
193
-	 *
194
-	 * @param string $appName the appName that we stored the value under
195
-	 * @return string[] the keys stored for the app
196
-	 */
197
-	public function getAppKeys($appName) {
198
-		return \OC::$server->query(\OC\AppConfig::class)->getKeys($appName);
199
-	}
200
-
201
-	/**
202
-	 * Writes a new app wide value
203
-	 *
204
-	 * @param string $appName the appName that we want to store the value under
205
-	 * @param string $key the key of the value, under which will be saved
206
-	 * @param string|float|int $value the value that should be stored
207
-	 */
208
-	public function setAppValue($appName, $key, $value) {
209
-		\OC::$server->query(\OC\AppConfig::class)->setValue($appName, $key, $value);
210
-	}
211
-
212
-	/**
213
-	 * Looks up an app wide defined value
214
-	 *
215
-	 * @param string $appName the appName that we stored the value under
216
-	 * @param string $key the key of the value, under which it was saved
217
-	 * @param string $default the default value to be returned if the value isn't set
218
-	 * @return string the saved value
219
-	 */
220
-	public function getAppValue($appName, $key, $default = '') {
221
-		return \OC::$server->query(\OC\AppConfig::class)->getValue($appName, $key, $default);
222
-	}
223
-
224
-	/**
225
-	 * Delete an app wide defined value
226
-	 *
227
-	 * @param string $appName the appName that we stored the value under
228
-	 * @param string $key the key of the value, under which it was saved
229
-	 */
230
-	public function deleteAppValue($appName, $key) {
231
-		\OC::$server->query(\OC\AppConfig::class)->deleteKey($appName, $key);
232
-	}
233
-
234
-	/**
235
-	 * Removes all keys in appconfig belonging to the app
236
-	 *
237
-	 * @param string $appName the appName the configs are stored under
238
-	 */
239
-	public function deleteAppValues($appName) {
240
-		\OC::$server->query(\OC\AppConfig::class)->deleteApp($appName);
241
-	}
242
-
243
-
244
-	/**
245
-	 * Set a user defined value
246
-	 *
247
-	 * @param string $userId the userId of the user that we want to store the value under
248
-	 * @param string $appName the appName that we want to store the value under
249
-	 * @param string $key the key under which the value is being stored
250
-	 * @param string|float|int $value the value that you want to store
251
-	 * @param string $preCondition only update if the config value was previously the value passed as $preCondition
252
-	 * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
253
-	 * @throws \UnexpectedValueException when trying to store an unexpected value
254
-	 */
255
-	public function setUserValue($userId, $appName, $key, $value, $preCondition = null) {
256
-		if (!is_int($value) && !is_float($value) && !is_string($value)) {
257
-			throw new \UnexpectedValueException('Only integers, floats and strings are allowed as value');
258
-		}
259
-
260
-		// TODO - FIXME
261
-		$this->fixDIInit();
262
-
263
-		if ($appName === 'settings' && $key === 'email') {
264
-			$value = strtolower((string) $value);
265
-		}
266
-
267
-		$prevValue = $this->getUserValue($userId, $appName, $key, null);
268
-
269
-		if ($prevValue !== null) {
270
-			if ($prevValue === (string)$value) {
271
-				return;
272
-			} elseif ($preCondition !== null && $prevValue !== (string)$preCondition) {
273
-				throw new PreConditionNotMetException();
274
-			} else {
275
-				$qb = $this->connection->getQueryBuilder();
276
-				$qb->update('preferences')
277
-					->set('configvalue', $qb->createNamedParameter($value))
278
-					->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId)))
279
-					->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter($appName)))
280
-					->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key)));
281
-				$qb->execute();
282
-
283
-				$this->userCache[$userId][$appName][$key] = (string)$value;
284
-				return;
285
-			}
286
-		}
287
-
288
-		$preconditionArray = [];
289
-		if (isset($preCondition)) {
290
-			$preconditionArray = [
291
-				'configvalue' => $preCondition,
292
-			];
293
-		}
294
-
295
-		$this->connection->setValues('preferences', [
296
-			'userid' => $userId,
297
-			'appid' => $appName,
298
-			'configkey' => $key,
299
-		], [
300
-			'configvalue' => $value,
301
-		], $preconditionArray);
302
-
303
-		// only add to the cache if we already loaded data for the user
304
-		if (isset($this->userCache[$userId])) {
305
-			if (!isset($this->userCache[$userId][$appName])) {
306
-				$this->userCache[$userId][$appName] = [];
307
-			}
308
-			$this->userCache[$userId][$appName][$key] = (string)$value;
309
-		}
310
-	}
311
-
312
-	/**
313
-	 * Getting a user defined value
314
-	 *
315
-	 * @param ?string $userId the userId of the user that we want to store the value under
316
-	 * @param string $appName the appName that we stored the value under
317
-	 * @param string $key the key under which the value is being stored
318
-	 * @param mixed $default the default value to be returned if the value isn't set
319
-	 * @return string
320
-	 */
321
-	public function getUserValue($userId, $appName, $key, $default = '') {
322
-		$data = $this->getAllUserValues($userId);
323
-		if (isset($data[$appName][$key])) {
324
-			return $data[$appName][$key];
325
-		} else {
326
-			return $default;
327
-		}
328
-	}
329
-
330
-	/**
331
-	 * Get the keys of all stored by an app for the user
332
-	 *
333
-	 * @param string $userId the userId of the user that we want to store the value under
334
-	 * @param string $appName the appName that we stored the value under
335
-	 * @return string[]
336
-	 */
337
-	public function getUserKeys($userId, $appName) {
338
-		$data = $this->getAllUserValues($userId);
339
-		if (isset($data[$appName])) {
340
-			return array_keys($data[$appName]);
341
-		} else {
342
-			return [];
343
-		}
344
-	}
345
-
346
-	/**
347
-	 * Delete a user value
348
-	 *
349
-	 * @param string $userId the userId of the user that we want to store the value under
350
-	 * @param string $appName the appName that we stored the value under
351
-	 * @param string $key the key under which the value is being stored
352
-	 */
353
-	public function deleteUserValue($userId, $appName, $key) {
354
-		// TODO - FIXME
355
-		$this->fixDIInit();
356
-
357
-		$sql = 'DELETE FROM `*PREFIX*preferences` '.
358
-				'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
359
-		$this->connection->executeUpdate($sql, [$userId, $appName, $key]);
360
-
361
-		if (isset($this->userCache[$userId][$appName])) {
362
-			unset($this->userCache[$userId][$appName][$key]);
363
-		}
364
-	}
365
-
366
-	/**
367
-	 * Delete all user values
368
-	 *
369
-	 * @param string $userId the userId of the user that we want to remove all values from
370
-	 */
371
-	public function deleteAllUserValues($userId) {
372
-		// TODO - FIXME
373
-		$this->fixDIInit();
374
-
375
-		$sql = 'DELETE FROM `*PREFIX*preferences` '.
376
-			'WHERE `userid` = ?';
377
-		$this->connection->executeUpdate($sql, [$userId]);
378
-
379
-		unset($this->userCache[$userId]);
380
-	}
381
-
382
-	/**
383
-	 * Delete all user related values of one app
384
-	 *
385
-	 * @param string $appName the appName of the app that we want to remove all values from
386
-	 */
387
-	public function deleteAppFromAllUsers($appName) {
388
-		// TODO - FIXME
389
-		$this->fixDIInit();
390
-
391
-		$sql = 'DELETE FROM `*PREFIX*preferences` '.
392
-				'WHERE `appid` = ?';
393
-		$this->connection->executeUpdate($sql, [$appName]);
394
-
395
-		foreach ($this->userCache as &$userCache) {
396
-			unset($userCache[$appName]);
397
-		}
398
-	}
399
-
400
-	/**
401
-	 * Returns all user configs sorted by app of one user
402
-	 *
403
-	 * @param ?string $userId the user ID to get the app configs from
404
-	 * @psalm-return array<string, array<string, string>>
405
-	 * @return array[] - 2 dimensional array with the following structure:
406
-	 *     [ $appId =>
407
-	 *         [ $key => $value ]
408
-	 *     ]
409
-	 */
410
-	public function getAllUserValues(?string $userId): array {
411
-		if (isset($this->userCache[$userId])) {
412
-			return $this->userCache[$userId];
413
-		}
414
-		if ($userId === null || $userId === '') {
415
-			$this->userCache[''] = [];
416
-			return $this->userCache[''];
417
-		}
418
-
419
-		// TODO - FIXME
420
-		$this->fixDIInit();
421
-
422
-		$data = [];
423
-		$query = 'SELECT `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
424
-		$result = $this->connection->executeQuery($query, [$userId]);
425
-		while ($row = $result->fetch()) {
426
-			$appId = $row['appid'];
427
-			if (!isset($data[$appId])) {
428
-				$data[$appId] = [];
429
-			}
430
-			$data[$appId][$row['configkey']] = $row['configvalue'];
431
-		}
432
-		$this->userCache[$userId] = $data;
433
-		return $data;
434
-	}
435
-
436
-	/**
437
-	 * Fetches a mapped list of userId -> value, for a specified app and key and a list of user IDs.
438
-	 *
439
-	 * @param string $appName app to get the value for
440
-	 * @param string $key the key to get the value for
441
-	 * @param array $userIds the user IDs to fetch the values for
442
-	 * @return array Mapped values: userId => value
443
-	 */
444
-	public function getUserValueForUsers($appName, $key, $userIds) {
445
-		// TODO - FIXME
446
-		$this->fixDIInit();
447
-
448
-		if (empty($userIds) || !is_array($userIds)) {
449
-			return [];
450
-		}
451
-
452
-		$chunkedUsers = array_chunk($userIds, 50, true);
453
-		$placeholders50 = implode(',', array_fill(0, 50, '?'));
454
-
455
-		$userValues = [];
456
-		foreach ($chunkedUsers as $chunk) {
457
-			$queryParams = $chunk;
458
-			// create [$app, $key, $chunkedUsers]
459
-			array_unshift($queryParams, $key);
460
-			array_unshift($queryParams, $appName);
461
-
462
-			$placeholders = (count($chunk) === 50) ? $placeholders50 :  implode(',', array_fill(0, count($chunk), '?'));
463
-
464
-			$query = 'SELECT `userid`, `configvalue` ' .
465
-						'FROM `*PREFIX*preferences` ' .
466
-						'WHERE `appid` = ? AND `configkey` = ? ' .
467
-						'AND `userid` IN (' . $placeholders . ')';
468
-			$result = $this->connection->executeQuery($query, $queryParams);
469
-
470
-			while ($row = $result->fetch()) {
471
-				$userValues[$row['userid']] = $row['configvalue'];
472
-			}
473
-		}
474
-
475
-		return $userValues;
476
-	}
477
-
478
-	/**
479
-	 * Determines the users that have the given value set for a specific app-key-pair
480
-	 *
481
-	 * @param string $appName the app to get the user for
482
-	 * @param string $key the key to get the user for
483
-	 * @param string $value the value to get the user for
484
-	 * @return array of user IDs
485
-	 */
486
-	public function getUsersForUserValue($appName, $key, $value) {
487
-		// TODO - FIXME
488
-		$this->fixDIInit();
489
-
490
-		$sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
491
-				'WHERE `appid` = ? AND `configkey` = ? ';
492
-
493
-		if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
494
-			//oracle hack: need to explicitly cast CLOB to CHAR for comparison
495
-			$sql .= 'AND to_char(`configvalue`) = ?';
496
-		} else {
497
-			$sql .= 'AND `configvalue` = ?';
498
-		}
499
-
500
-		$sql .= ' ORDER BY `userid`';
501
-
502
-		$result = $this->connection->executeQuery($sql, [$appName, $key, $value]);
503
-
504
-		$userIDs = [];
505
-		while ($row = $result->fetch()) {
506
-			$userIDs[] = $row['userid'];
507
-		}
508
-
509
-		return $userIDs;
510
-	}
511
-
512
-	/**
513
-	 * Determines the users that have the given value set for a specific app-key-pair
514
-	 *
515
-	 * @param string $appName the app to get the user for
516
-	 * @param string $key the key to get the user for
517
-	 * @param string $value the value to get the user for
518
-	 * @return array of user IDs
519
-	 */
520
-	public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
521
-		// TODO - FIXME
522
-		$this->fixDIInit();
523
-
524
-		if ($appName === 'settings' && $key === 'email') {
525
-			// Email address is always stored lowercase in the database
526
-			return $this->getUsersForUserValue($appName, $key, strtolower($value));
527
-		}
528
-
529
-		$sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
530
-			'WHERE `appid` = ? AND `configkey` = ? ';
531
-
532
-		if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
533
-			//oracle hack: need to explicitly cast CLOB to CHAR for comparison
534
-			$sql .= 'AND LOWER(to_char(`configvalue`)) = ?';
535
-		} else {
536
-			$sql .= 'AND LOWER(`configvalue`) = ?';
537
-		}
538
-
539
-		$sql .= ' ORDER BY `userid`';
540
-
541
-		$result = $this->connection->executeQuery($sql, [$appName, $key, strtolower($value)]);
542
-
543
-		$userIDs = [];
544
-		while ($row = $result->fetch()) {
545
-			$userIDs[] = $row['userid'];
546
-		}
547
-
548
-		return $userIDs;
549
-	}
550
-
551
-	public function getSystemConfig() {
552
-		return $this->systemConfig;
553
-	}
43
+    /** @var SystemConfig */
44
+    private $systemConfig;
45
+
46
+    /** @var IDBConnection */
47
+    private $connection;
48
+
49
+    /**
50
+     * 3 dimensional array with the following structure:
51
+     * [ $userId =>
52
+     *     [ $appId =>
53
+     *         [ $key => $value ]
54
+     *     ]
55
+     * ]
56
+     *
57
+     * database table: preferences
58
+     *
59
+     * methods that use this:
60
+     *   - setUserValue
61
+     *   - getUserValue
62
+     *   - getUserKeys
63
+     *   - deleteUserValue
64
+     *   - deleteAllUserValues
65
+     *   - deleteAppFromAllUsers
66
+     *
67
+     * @var CappedMemoryCache $userCache
68
+     */
69
+    private $userCache;
70
+
71
+    /**
72
+     * @param SystemConfig $systemConfig
73
+     */
74
+    public function __construct(SystemConfig $systemConfig) {
75
+        $this->userCache = new CappedMemoryCache();
76
+        $this->systemConfig = $systemConfig;
77
+    }
78
+
79
+    /**
80
+     * TODO - FIXME This fixes an issue with base.php that cause cyclic
81
+     * dependencies, especially with autoconfig setup
82
+     *
83
+     * Replace this by properly injected database connection. Currently the
84
+     * base.php triggers the getDatabaseConnection too early which causes in
85
+     * autoconfig setup case a too early distributed database connection and
86
+     * the autoconfig then needs to reinit all already initialized dependencies
87
+     * that use the database connection.
88
+     *
89
+     * otherwise a SQLite database is created in the wrong directory
90
+     * because the database connection was created with an uninitialized config
91
+     */
92
+    private function fixDIInit() {
93
+        if ($this->connection === null) {
94
+            $this->connection = \OC::$server->getDatabaseConnection();
95
+        }
96
+    }
97
+
98
+    /**
99
+     * Sets and deletes system wide values
100
+     *
101
+     * @param array $configs Associative array with `key => value` pairs
102
+     *                       If value is null, the config key will be deleted
103
+     */
104
+    public function setSystemValues(array $configs) {
105
+        $this->systemConfig->setValues($configs);
106
+    }
107
+
108
+    /**
109
+     * Sets a new system wide value
110
+     *
111
+     * @param string $key the key of the value, under which will be saved
112
+     * @param mixed $value the value that should be stored
113
+     */
114
+    public function setSystemValue($key, $value) {
115
+        $this->systemConfig->setValue($key, $value);
116
+    }
117
+
118
+    /**
119
+     * Looks up a system wide defined value
120
+     *
121
+     * @param string $key the key of the value, under which it was saved
122
+     * @param mixed $default the default value to be returned if the value isn't set
123
+     * @return mixed the value or $default
124
+     */
125
+    public function getSystemValue($key, $default = '') {
126
+        return $this->systemConfig->getValue($key, $default);
127
+    }
128
+
129
+    /**
130
+     * Looks up a boolean system wide defined value
131
+     *
132
+     * @param string $key the key of the value, under which it was saved
133
+     * @param bool $default the default value to be returned if the value isn't set
134
+     *
135
+     * @return bool
136
+     *
137
+     * @since 16.0.0
138
+     */
139
+    public function getSystemValueBool(string $key, bool $default = false): bool {
140
+        return (bool) $this->getSystemValue($key, $default);
141
+    }
142
+
143
+    /**
144
+     * Looks up an integer system wide defined value
145
+     *
146
+     * @param string $key the key of the value, under which it was saved
147
+     * @param int $default the default value to be returned if the value isn't set
148
+     *
149
+     * @return int
150
+     *
151
+     * @since 16.0.0
152
+     */
153
+    public function getSystemValueInt(string $key, int $default = 0): int {
154
+        return (int) $this->getSystemValue($key, $default);
155
+    }
156
+
157
+    /**
158
+     * Looks up a string system wide defined value
159
+     *
160
+     * @param string $key the key of the value, under which it was saved
161
+     * @param string $default the default value to be returned if the value isn't set
162
+     *
163
+     * @return string
164
+     *
165
+     * @since 16.0.0
166
+     */
167
+    public function getSystemValueString(string $key, string $default = ''): string {
168
+        return (string) $this->getSystemValue($key, $default);
169
+    }
170
+
171
+    /**
172
+     * Looks up a system wide defined value and filters out sensitive data
173
+     *
174
+     * @param string $key the key of the value, under which it was saved
175
+     * @param mixed $default the default value to be returned if the value isn't set
176
+     * @return mixed the value or $default
177
+     */
178
+    public function getFilteredSystemValue($key, $default = '') {
179
+        return $this->systemConfig->getFilteredValue($key, $default);
180
+    }
181
+
182
+    /**
183
+     * Delete a system wide defined value
184
+     *
185
+     * @param string $key the key of the value, under which it was saved
186
+     */
187
+    public function deleteSystemValue($key) {
188
+        $this->systemConfig->deleteValue($key);
189
+    }
190
+
191
+    /**
192
+     * Get all keys stored for an app
193
+     *
194
+     * @param string $appName the appName that we stored the value under
195
+     * @return string[] the keys stored for the app
196
+     */
197
+    public function getAppKeys($appName) {
198
+        return \OC::$server->query(\OC\AppConfig::class)->getKeys($appName);
199
+    }
200
+
201
+    /**
202
+     * Writes a new app wide value
203
+     *
204
+     * @param string $appName the appName that we want to store the value under
205
+     * @param string $key the key of the value, under which will be saved
206
+     * @param string|float|int $value the value that should be stored
207
+     */
208
+    public function setAppValue($appName, $key, $value) {
209
+        \OC::$server->query(\OC\AppConfig::class)->setValue($appName, $key, $value);
210
+    }
211
+
212
+    /**
213
+     * Looks up an app wide defined value
214
+     *
215
+     * @param string $appName the appName that we stored the value under
216
+     * @param string $key the key of the value, under which it was saved
217
+     * @param string $default the default value to be returned if the value isn't set
218
+     * @return string the saved value
219
+     */
220
+    public function getAppValue($appName, $key, $default = '') {
221
+        return \OC::$server->query(\OC\AppConfig::class)->getValue($appName, $key, $default);
222
+    }
223
+
224
+    /**
225
+     * Delete an app wide defined value
226
+     *
227
+     * @param string $appName the appName that we stored the value under
228
+     * @param string $key the key of the value, under which it was saved
229
+     */
230
+    public function deleteAppValue($appName, $key) {
231
+        \OC::$server->query(\OC\AppConfig::class)->deleteKey($appName, $key);
232
+    }
233
+
234
+    /**
235
+     * Removes all keys in appconfig belonging to the app
236
+     *
237
+     * @param string $appName the appName the configs are stored under
238
+     */
239
+    public function deleteAppValues($appName) {
240
+        \OC::$server->query(\OC\AppConfig::class)->deleteApp($appName);
241
+    }
242
+
243
+
244
+    /**
245
+     * Set a user defined value
246
+     *
247
+     * @param string $userId the userId of the user that we want to store the value under
248
+     * @param string $appName the appName that we want to store the value under
249
+     * @param string $key the key under which the value is being stored
250
+     * @param string|float|int $value the value that you want to store
251
+     * @param string $preCondition only update if the config value was previously the value passed as $preCondition
252
+     * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
253
+     * @throws \UnexpectedValueException when trying to store an unexpected value
254
+     */
255
+    public function setUserValue($userId, $appName, $key, $value, $preCondition = null) {
256
+        if (!is_int($value) && !is_float($value) && !is_string($value)) {
257
+            throw new \UnexpectedValueException('Only integers, floats and strings are allowed as value');
258
+        }
259
+
260
+        // TODO - FIXME
261
+        $this->fixDIInit();
262
+
263
+        if ($appName === 'settings' && $key === 'email') {
264
+            $value = strtolower((string) $value);
265
+        }
266
+
267
+        $prevValue = $this->getUserValue($userId, $appName, $key, null);
268
+
269
+        if ($prevValue !== null) {
270
+            if ($prevValue === (string)$value) {
271
+                return;
272
+            } elseif ($preCondition !== null && $prevValue !== (string)$preCondition) {
273
+                throw new PreConditionNotMetException();
274
+            } else {
275
+                $qb = $this->connection->getQueryBuilder();
276
+                $qb->update('preferences')
277
+                    ->set('configvalue', $qb->createNamedParameter($value))
278
+                    ->where($qb->expr()->eq('userid', $qb->createNamedParameter($userId)))
279
+                    ->andWhere($qb->expr()->eq('appid', $qb->createNamedParameter($appName)))
280
+                    ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($key)));
281
+                $qb->execute();
282
+
283
+                $this->userCache[$userId][$appName][$key] = (string)$value;
284
+                return;
285
+            }
286
+        }
287
+
288
+        $preconditionArray = [];
289
+        if (isset($preCondition)) {
290
+            $preconditionArray = [
291
+                'configvalue' => $preCondition,
292
+            ];
293
+        }
294
+
295
+        $this->connection->setValues('preferences', [
296
+            'userid' => $userId,
297
+            'appid' => $appName,
298
+            'configkey' => $key,
299
+        ], [
300
+            'configvalue' => $value,
301
+        ], $preconditionArray);
302
+
303
+        // only add to the cache if we already loaded data for the user
304
+        if (isset($this->userCache[$userId])) {
305
+            if (!isset($this->userCache[$userId][$appName])) {
306
+                $this->userCache[$userId][$appName] = [];
307
+            }
308
+            $this->userCache[$userId][$appName][$key] = (string)$value;
309
+        }
310
+    }
311
+
312
+    /**
313
+     * Getting a user defined value
314
+     *
315
+     * @param ?string $userId the userId of the user that we want to store the value under
316
+     * @param string $appName the appName that we stored the value under
317
+     * @param string $key the key under which the value is being stored
318
+     * @param mixed $default the default value to be returned if the value isn't set
319
+     * @return string
320
+     */
321
+    public function getUserValue($userId, $appName, $key, $default = '') {
322
+        $data = $this->getAllUserValues($userId);
323
+        if (isset($data[$appName][$key])) {
324
+            return $data[$appName][$key];
325
+        } else {
326
+            return $default;
327
+        }
328
+    }
329
+
330
+    /**
331
+     * Get the keys of all stored by an app for the user
332
+     *
333
+     * @param string $userId the userId of the user that we want to store the value under
334
+     * @param string $appName the appName that we stored the value under
335
+     * @return string[]
336
+     */
337
+    public function getUserKeys($userId, $appName) {
338
+        $data = $this->getAllUserValues($userId);
339
+        if (isset($data[$appName])) {
340
+            return array_keys($data[$appName]);
341
+        } else {
342
+            return [];
343
+        }
344
+    }
345
+
346
+    /**
347
+     * Delete a user value
348
+     *
349
+     * @param string $userId the userId of the user that we want to store the value under
350
+     * @param string $appName the appName that we stored the value under
351
+     * @param string $key the key under which the value is being stored
352
+     */
353
+    public function deleteUserValue($userId, $appName, $key) {
354
+        // TODO - FIXME
355
+        $this->fixDIInit();
356
+
357
+        $sql = 'DELETE FROM `*PREFIX*preferences` '.
358
+                'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
359
+        $this->connection->executeUpdate($sql, [$userId, $appName, $key]);
360
+
361
+        if (isset($this->userCache[$userId][$appName])) {
362
+            unset($this->userCache[$userId][$appName][$key]);
363
+        }
364
+    }
365
+
366
+    /**
367
+     * Delete all user values
368
+     *
369
+     * @param string $userId the userId of the user that we want to remove all values from
370
+     */
371
+    public function deleteAllUserValues($userId) {
372
+        // TODO - FIXME
373
+        $this->fixDIInit();
374
+
375
+        $sql = 'DELETE FROM `*PREFIX*preferences` '.
376
+            'WHERE `userid` = ?';
377
+        $this->connection->executeUpdate($sql, [$userId]);
378
+
379
+        unset($this->userCache[$userId]);
380
+    }
381
+
382
+    /**
383
+     * Delete all user related values of one app
384
+     *
385
+     * @param string $appName the appName of the app that we want to remove all values from
386
+     */
387
+    public function deleteAppFromAllUsers($appName) {
388
+        // TODO - FIXME
389
+        $this->fixDIInit();
390
+
391
+        $sql = 'DELETE FROM `*PREFIX*preferences` '.
392
+                'WHERE `appid` = ?';
393
+        $this->connection->executeUpdate($sql, [$appName]);
394
+
395
+        foreach ($this->userCache as &$userCache) {
396
+            unset($userCache[$appName]);
397
+        }
398
+    }
399
+
400
+    /**
401
+     * Returns all user configs sorted by app of one user
402
+     *
403
+     * @param ?string $userId the user ID to get the app configs from
404
+     * @psalm-return array<string, array<string, string>>
405
+     * @return array[] - 2 dimensional array with the following structure:
406
+     *     [ $appId =>
407
+     *         [ $key => $value ]
408
+     *     ]
409
+     */
410
+    public function getAllUserValues(?string $userId): array {
411
+        if (isset($this->userCache[$userId])) {
412
+            return $this->userCache[$userId];
413
+        }
414
+        if ($userId === null || $userId === '') {
415
+            $this->userCache[''] = [];
416
+            return $this->userCache[''];
417
+        }
418
+
419
+        // TODO - FIXME
420
+        $this->fixDIInit();
421
+
422
+        $data = [];
423
+        $query = 'SELECT `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?';
424
+        $result = $this->connection->executeQuery($query, [$userId]);
425
+        while ($row = $result->fetch()) {
426
+            $appId = $row['appid'];
427
+            if (!isset($data[$appId])) {
428
+                $data[$appId] = [];
429
+            }
430
+            $data[$appId][$row['configkey']] = $row['configvalue'];
431
+        }
432
+        $this->userCache[$userId] = $data;
433
+        return $data;
434
+    }
435
+
436
+    /**
437
+     * Fetches a mapped list of userId -> value, for a specified app and key and a list of user IDs.
438
+     *
439
+     * @param string $appName app to get the value for
440
+     * @param string $key the key to get the value for
441
+     * @param array $userIds the user IDs to fetch the values for
442
+     * @return array Mapped values: userId => value
443
+     */
444
+    public function getUserValueForUsers($appName, $key, $userIds) {
445
+        // TODO - FIXME
446
+        $this->fixDIInit();
447
+
448
+        if (empty($userIds) || !is_array($userIds)) {
449
+            return [];
450
+        }
451
+
452
+        $chunkedUsers = array_chunk($userIds, 50, true);
453
+        $placeholders50 = implode(',', array_fill(0, 50, '?'));
454
+
455
+        $userValues = [];
456
+        foreach ($chunkedUsers as $chunk) {
457
+            $queryParams = $chunk;
458
+            // create [$app, $key, $chunkedUsers]
459
+            array_unshift($queryParams, $key);
460
+            array_unshift($queryParams, $appName);
461
+
462
+            $placeholders = (count($chunk) === 50) ? $placeholders50 :  implode(',', array_fill(0, count($chunk), '?'));
463
+
464
+            $query = 'SELECT `userid`, `configvalue` ' .
465
+                        'FROM `*PREFIX*preferences` ' .
466
+                        'WHERE `appid` = ? AND `configkey` = ? ' .
467
+                        'AND `userid` IN (' . $placeholders . ')';
468
+            $result = $this->connection->executeQuery($query, $queryParams);
469
+
470
+            while ($row = $result->fetch()) {
471
+                $userValues[$row['userid']] = $row['configvalue'];
472
+            }
473
+        }
474
+
475
+        return $userValues;
476
+    }
477
+
478
+    /**
479
+     * Determines the users that have the given value set for a specific app-key-pair
480
+     *
481
+     * @param string $appName the app to get the user for
482
+     * @param string $key the key to get the user for
483
+     * @param string $value the value to get the user for
484
+     * @return array of user IDs
485
+     */
486
+    public function getUsersForUserValue($appName, $key, $value) {
487
+        // TODO - FIXME
488
+        $this->fixDIInit();
489
+
490
+        $sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
491
+                'WHERE `appid` = ? AND `configkey` = ? ';
492
+
493
+        if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
494
+            //oracle hack: need to explicitly cast CLOB to CHAR for comparison
495
+            $sql .= 'AND to_char(`configvalue`) = ?';
496
+        } else {
497
+            $sql .= 'AND `configvalue` = ?';
498
+        }
499
+
500
+        $sql .= ' ORDER BY `userid`';
501
+
502
+        $result = $this->connection->executeQuery($sql, [$appName, $key, $value]);
503
+
504
+        $userIDs = [];
505
+        while ($row = $result->fetch()) {
506
+            $userIDs[] = $row['userid'];
507
+        }
508
+
509
+        return $userIDs;
510
+    }
511
+
512
+    /**
513
+     * Determines the users that have the given value set for a specific app-key-pair
514
+     *
515
+     * @param string $appName the app to get the user for
516
+     * @param string $key the key to get the user for
517
+     * @param string $value the value to get the user for
518
+     * @return array of user IDs
519
+     */
520
+    public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
521
+        // TODO - FIXME
522
+        $this->fixDIInit();
523
+
524
+        if ($appName === 'settings' && $key === 'email') {
525
+            // Email address is always stored lowercase in the database
526
+            return $this->getUsersForUserValue($appName, $key, strtolower($value));
527
+        }
528
+
529
+        $sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
530
+            'WHERE `appid` = ? AND `configkey` = ? ';
531
+
532
+        if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
533
+            //oracle hack: need to explicitly cast CLOB to CHAR for comparison
534
+            $sql .= 'AND LOWER(to_char(`configvalue`)) = ?';
535
+        } else {
536
+            $sql .= 'AND LOWER(`configvalue`) = ?';
537
+        }
538
+
539
+        $sql .= ' ORDER BY `userid`';
540
+
541
+        $result = $this->connection->executeQuery($sql, [$appName, $key, strtolower($value)]);
542
+
543
+        $userIDs = [];
544
+        while ($row = $result->fetch()) {
545
+            $userIDs[] = $row['userid'];
546
+        }
547
+
548
+        return $userIDs;
549
+    }
550
+
551
+    public function getSystemConfig() {
552
+        return $this->systemConfig;
553
+    }
554 554
 }
Please login to merge, or discard this patch.