Completed
Pull Request — master (#5772)
by Joas
17:17
created
core/Migrations/Version13000Date20170718121200.php 1 patch
Indentation   +914 added lines, -914 removed lines patch added patch discarded remove patch
@@ -10,918 +10,918 @@
 block discarded – undo
10 10
  */
11 11
 class Version13000Date20170718121200 extends SimpleMigrationStep {
12 12
 
13
-	/**
14
-	 * @param IOutput $output
15
-	 * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
16
-	 * @param array $options
17
-	 * @since 13.0.0
18
-	 */
19
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
20
-	}
21
-
22
-	/**
23
-	 * @param IOutput $output
24
-	 * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
25
-	 * @param array $options
26
-	 * @return null|Schema
27
-	 * @since 13.0.0
28
-	 */
29
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
30
-		/** @var Schema $schema */
31
-		$schema = $schemaClosure();
32
-
33
-		if (!$schema->hasTable('appconfig')) {
34
-			$table = $schema->createTable('appconfig');
35
-			$table->addColumn('appid', 'string', [
36
-				'notnull' => true,
37
-				'length' => 32,
38
-				'default' => '',
39
-			]);
40
-			$table->addColumn('configkey', 'string', [
41
-				'notnull' => true,
42
-				'length' => 64,
43
-				'default' => '',
44
-			]);
45
-			$table->addColumn('configvalue', 'text', [
46
-				'notnull' => false,
47
-			]);
48
-			$table->setPrimaryKey(['appid', 'configkey']);
49
-			$table->addIndex(['configkey'], 'appconfig_config_key_index');
50
-			$table->addIndex(['appid'], 'appconfig_appid_key');
51
-		}
52
-
53
-		if (!$schema->hasTable('storages')) {
54
-			$table = $schema->createTable('storages');
55
-			$table->addColumn('id', 'string', [
56
-				'notnull' => false,
57
-				'length' => 64,
58
-			]);
59
-			$table->addColumn('numeric_id', 'integer', [
60
-				'autoincrement' => true,
61
-				'notnull' => true,
62
-				'length' => 4,
63
-			]);
64
-			$table->addColumn('available', 'integer', [
65
-				'notnull' => true,
66
-				'default' => 1,
67
-			]);
68
-			$table->addColumn('last_checked', 'integer', [
69
-				'notnull' => false,
70
-			]);
71
-			$table->setPrimaryKey(['numeric_id']);
72
-			$table->addUniqueIndex(['id'], 'storages_id_index');
73
-		}
74
-
75
-		if (!$schema->hasTable('mounts')) {
76
-			$table = $schema->createTable('mounts');
77
-			$table->addColumn('id', 'integer', [
78
-				'autoincrement' => true,
79
-				'notnull' => true,
80
-				'length' => 4,
81
-			]);
82
-			$table->addColumn('storage_id', 'integer', [
83
-				'notnull' => true,
84
-			]);
85
-			$table->addColumn('root_id', 'integer', [
86
-				'notnull' => true,
87
-			]);
88
-			$table->addColumn('user_id', 'string', [
89
-				'notnull' => true,
90
-				'length' => 64,
91
-			]);
92
-			$table->addColumn('mount_point', 'string', [
93
-				'notnull' => true,
94
-				'length' => 4000,
95
-			]);
96
-			$table->addColumn('mount_id', 'integer', [
97
-				'notnull' => false,
98
-			]);
99
-			$table->setPrimaryKey(['id']);
100
-			$table->addIndex(['user_id'], 'mounts_user_index');
101
-			$table->addIndex(['storage_id'], 'mounts_storage_index');
102
-			$table->addIndex(['root_id'], 'mounts_root_index');
103
-			$table->addIndex(['mount_id'], 'mounts_mount_id_index');
104
-			$table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
105
-		}
106
-
107
-		if (!$schema->hasTable('mimetypes')) {
108
-			$table = $schema->createTable('mimetypes');
109
-			$table->addColumn('id', 'integer', [
110
-				'autoincrement' => true,
111
-				'notnull' => true,
112
-				'length' => 4,
113
-			]);
114
-			$table->addColumn('mimetype', 'string', [
115
-				'notnull' => true,
116
-				'length' => 255,
117
-				'default' => '',
118
-			]);
119
-			$table->setPrimaryKey(['id']);
120
-			$table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
121
-		}
122
-
123
-		if (!$schema->hasTable('filecache')) {
124
-			$table = $schema->createTable('filecache');
125
-			$table->addColumn('fileid', 'integer', [
126
-				'autoincrement' => true,
127
-				'notnull' => true,
128
-				'length' => 4,
129
-			]);
130
-			$table->addColumn('storage', 'integer', [
131
-				'notnull' => true,
132
-				'length' => 4,
133
-				'default' => 0,
134
-			]);
135
-			$table->addColumn('path', 'string', [
136
-				'notnull' => false,
137
-				'length' => 4000,
138
-			]);
139
-			$table->addColumn('path_hash', 'string', [
140
-				'notnull' => true,
141
-				'length' => 32,
142
-				'default' => '',
143
-			]);
144
-			$table->addColumn('parent', 'integer', [
145
-				'notnull' => true,
146
-				'length' => 4,
147
-				'default' => 0,
148
-			]);
149
-			$table->addColumn('name', 'string', [
150
-				'notnull' => false,
151
-				'length' => 250,
152
-			]);
153
-			$table->addColumn('mimetype', 'integer', [
154
-				'notnull' => true,
155
-				'length' => 4,
156
-				'default' => 0,
157
-			]);
158
-			$table->addColumn('mimepart', 'integer', [
159
-				'notnull' => true,
160
-				'length' => 4,
161
-				'default' => 0,
162
-			]);
163
-			$table->addColumn('size', 'bigint', [
164
-				'notnull' => true,
165
-				'length' => 8,
166
-				'default' => 0,
167
-			]);
168
-			$table->addColumn('mtime', 'integer', [
169
-				'notnull' => true,
170
-				'length' => 4,
171
-				'default' => 0,
172
-			]);
173
-			$table->addColumn('storage_mtime', 'integer', [
174
-				'notnull' => true,
175
-				'length' => 4,
176
-				'default' => 0,
177
-			]);
178
-			$table->addColumn('encrypted', 'integer', [
179
-				'notnull' => true,
180
-				'length' => 4,
181
-				'default' => 0,
182
-			]);
183
-			$table->addColumn('unencrypted_size', 'bigint', [
184
-				'notnull' => true,
185
-				'length' => 8,
186
-				'default' => 0,
187
-			]);
188
-			$table->addColumn('etag', 'string', [
189
-				'notnull' => false,
190
-				'length' => 40,
191
-			]);
192
-			$table->addColumn('permissions', 'integer', [
193
-				'notnull' => false,
194
-				'length' => 4,
195
-				'default' => 0,
196
-			]);
197
-			$table->addColumn('checksum', 'string', [
198
-				'notnull' => false,
199
-				'length' => 255,
200
-			]);
201
-			$table->setPrimaryKey(['fileid']);
202
-			$table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
203
-			$table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
204
-			$table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
205
-			$table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
206
-			$table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
207
-		}
208
-
209
-		if (!$schema->hasTable('group_user')) {
210
-			$table = $schema->createTable('group_user');
211
-			$table->addColumn('gid', 'string', [
212
-				'notnull' => true,
213
-				'length' => 64,
214
-				'default' => '',
215
-			]);
216
-			$table->addColumn('uid', 'string', [
217
-				'notnull' => true,
218
-				'length' => 64,
219
-				'default' => '',
220
-			]);
221
-			$table->setPrimaryKey(['gid', 'uid']);
222
-			$table->addIndex(['uid'], 'gu_uid_index');
223
-		}
224
-
225
-		if (!$schema->hasTable('group_admin')) {
226
-			$table = $schema->createTable('group_admin');
227
-			$table->addColumn('gid', 'string', [
228
-				'notnull' => true,
229
-				'length' => 64,
230
-				'default' => '',
231
-			]);
232
-			$table->addColumn('uid', 'string', [
233
-				'notnull' => true,
234
-				'length' => 64,
235
-				'default' => '',
236
-			]);
237
-			$table->setPrimaryKey(['gid', 'uid']);
238
-			$table->addIndex(['uid'], 'group_admin_uid');
239
-		}
240
-
241
-		if (!$schema->hasTable('groups')) {
242
-			$table = $schema->createTable('groups');
243
-			$table->addColumn('gid', 'string', [
244
-				'notnull' => true,
245
-				'length' => 64,
246
-				'default' => '',
247
-			]);
248
-			$table->setPrimaryKey(['gid']);
249
-		}
250
-
251
-		if (!$schema->hasTable('preferences')) {
252
-			$table = $schema->createTable('preferences');
253
-			$table->addColumn('userid', 'string', [
254
-				'notnull' => true,
255
-				'length' => 64,
256
-				'default' => '',
257
-			]);
258
-			$table->addColumn('appid', 'string', [
259
-				'notnull' => true,
260
-				'length' => 32,
261
-				'default' => '',
262
-			]);
263
-			$table->addColumn('configkey', 'string', [
264
-				'notnull' => true,
265
-				'length' => 64,
266
-				'default' => '',
267
-			]);
268
-			$table->addColumn('configvalue', 'text', [
269
-				'notnull' => false,
270
-			]);
271
-			$table->setPrimaryKey(['userid', 'appid', 'configkey']);
272
-		}
273
-
274
-		if (!$schema->hasTable('properties')) {
275
-			$table = $schema->createTable('properties');
276
-			$table->addColumn('id', 'integer', [
277
-				'autoincrement' => true,
278
-				'notnull' => true,
279
-				'length' => 4,
280
-			]);
281
-			$table->addColumn('userid', 'string', [
282
-				'notnull' => true,
283
-				'length' => 64,
284
-				'default' => '',
285
-			]);
286
-			$table->addColumn('propertypath', 'string', [
287
-				'notnull' => true,
288
-				'length' => 255,
289
-				'default' => '',
290
-			]);
291
-			$table->addColumn('propertyname', 'string', [
292
-				'notnull' => true,
293
-				'length' => 255,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('propertyvalue', 'text', [
297
-				'notnull' => true,
298
-			]);
299
-			$table->setPrimaryKey(['id']);
300
-			$table->addIndex(['userid'], 'property_index');
301
-		}
302
-
303
-		if (!$schema->hasTable('share')) {
304
-			$table = $schema->createTable('share');
305
-			$table->addColumn('id', 'integer', [
306
-				'autoincrement' => true,
307
-				'notnull' => true,
308
-				'length' => 4,
309
-			]);
310
-			$table->addColumn('share_type', 'smallint', [
311
-				'notnull' => true,
312
-				'length' => 1,
313
-				'default' => 0,
314
-			]);
315
-			$table->addColumn('share_with', 'string', [
316
-				'notnull' => false,
317
-				'length' => 255,
318
-			]);
319
-			$table->addColumn('password', 'string', [
320
-				'notnull' => false,
321
-				'length' => 255,
322
-			]);
323
-			$table->addColumn('uid_owner', 'string', [
324
-				'notnull' => true,
325
-				'length' => 64,
326
-				'default' => '',
327
-			]);
328
-			$table->addColumn('uid_initiator', 'string', [
329
-				'notnull' => false,
330
-				'length' => 64,
331
-			]);
332
-			$table->addColumn('parent', 'integer', [
333
-				'notnull' => false,
334
-				'length' => 4,
335
-			]);
336
-			$table->addColumn('item_type', 'string', [
337
-				'notnull' => true,
338
-				'length' => 64,
339
-				'default' => '',
340
-			]);
341
-			$table->addColumn('item_source', 'string', [
342
-				'notnull' => false,
343
-				'length' => 255,
344
-			]);
345
-			$table->addColumn('item_target', 'string', [
346
-				'notnull' => false,
347
-				'length' => 255,
348
-			]);
349
-			$table->addColumn('file_source', 'integer', [
350
-				'notnull' => false,
351
-				'length' => 4,
352
-			]);
353
-			$table->addColumn('file_target', 'string', [
354
-				'notnull' => false,
355
-				'length' => 512,
356
-			]);
357
-			$table->addColumn('permissions', 'smallint', [
358
-				'notnull' => true,
359
-				'length' => 1,
360
-				'default' => 0,
361
-			]);
362
-			$table->addColumn('stime', 'bigint', [
363
-				'notnull' => true,
364
-				'length' => 8,
365
-				'default' => 0,
366
-			]);
367
-			$table->addColumn('accepted', 'smallint', [
368
-				'notnull' => true,
369
-				'length' => 1,
370
-				'default' => 0,
371
-			]);
372
-			$table->addColumn('expiration', 'datetime', [
373
-				'notnull' => false,
374
-			]);
375
-			$table->addColumn('token', 'string', [
376
-				'notnull' => false,
377
-				'length' => 32,
378
-			]);
379
-			$table->addColumn('mail_send', 'smallint', [
380
-				'notnull' => true,
381
-				'length' => 1,
382
-				'default' => 0,
383
-			]);
384
-			$table->addColumn('share_name', 'string', [
385
-				'notnull' => false,
386
-				'length' => 64,
387
-			]);
388
-			$table->setPrimaryKey(['id']);
389
-			$table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
390
-			$table->addIndex(['file_source'], 'file_source_index');
391
-			$table->addIndex(['token'], 'token_index');
392
-		}
393
-
394
-		if (!$schema->hasTable('jobs')) {
395
-			$table = $schema->createTable('jobs');
396
-			$table->addColumn('id', 'integer', [
397
-				'autoincrement' => true,
398
-				'notnull' => true,
399
-				'length' => 4,
400
-			]);
401
-			$table->addColumn('class', 'string', [
402
-				'notnull' => true,
403
-				'length' => 255,
404
-				'default' => '',
405
-			]);
406
-			$table->addColumn('argument', 'string', [
407
-				'notnull' => true,
408
-				'length' => 4000,
409
-				'default' => '',
410
-			]);
411
-			$table->addColumn('last_run', 'integer', [
412
-				'notnull' => false,
413
-				'default' => 0,
414
-			]);
415
-			$table->addColumn('last_checked', 'integer', [
416
-				'notnull' => false,
417
-				'default' => 0,
418
-			]);
419
-			$table->addColumn('reserved_at', 'integer', [
420
-				'notnull' => false,
421
-				'default' => 0,
422
-			]);
423
-			$table->addColumn('execution_duration', 'integer', [
424
-				'notnull' => true,
425
-				'default' => 0,
426
-			]);
427
-			$table->setPrimaryKey(['id']);
428
-			$table->addIndex(['class'], 'job_class_index');
429
-		}
430
-
431
-		if (!$schema->hasTable('users')) {
432
-			$table = $schema->createTable('users');
433
-			$table->addColumn('uid', 'string', [
434
-				'notnull' => true,
435
-				'length' => 64,
436
-				'default' => '',
437
-			]);
438
-			$table->addColumn('displayname', 'string', [
439
-				'notnull' => false,
440
-				'length' => 64,
441
-			]);
442
-			$table->addColumn('password', 'string', [
443
-				'notnull' => true,
444
-				'length' => 255,
445
-				'default' => '',
446
-			]);
447
-			$table->setPrimaryKey(['uid']);
448
-		}
449
-
450
-		if (!$schema->hasTable('authtoken')) {
451
-			$table = $schema->createTable('authtoken');
452
-			$table->addColumn('id', 'integer', [
453
-				'autoincrement' => true,
454
-				'notnull' => true,
455
-				'length' => 4,
456
-			]);
457
-			$table->addColumn('uid', 'string', [
458
-				'notnull' => true,
459
-				'length' => 64,
460
-				'default' => '',
461
-			]);
462
-			$table->addColumn('login_name', 'string', [
463
-				'notnull' => true,
464
-				'length' => 64,
465
-				'default' => '',
466
-			]);
467
-			$table->addColumn('password', 'text', [
468
-				'notnull' => false,
469
-			]);
470
-			$table->addColumn('name', 'text', [
471
-				'notnull' => true,
472
-				'default' => '',
473
-			]);
474
-			$table->addColumn('token', 'string', [
475
-				'notnull' => true,
476
-				'length' => 200,
477
-				'default' => '',
478
-			]);
479
-			$table->addColumn('type', 'smallint', [
480
-				'notnull' => true,
481
-				'length' => 2,
482
-				'default' => 0,
483
-			]);
484
-			$table->addColumn('remember', 'smallint', [
485
-				'notnull' => true,
486
-				'length' => 1,
487
-				'default' => 0,
488
-			]);
489
-			$table->addColumn('last_activity', 'integer', [
490
-				'notnull' => true,
491
-				'length' => 4,
492
-				'default' => 0,
493
-			]);
494
-			$table->addColumn('last_check', 'integer', [
495
-				'notnull' => true,
496
-				'length' => 4,
497
-				'default' => 0,
498
-			]);
499
-			$table->addColumn('scope', 'text', [
500
-				'notnull' => false,
501
-			]);
502
-			$table->setPrimaryKey(['id']);
503
-			$table->addUniqueIndex(['token'], 'authtoken_token_index');
504
-			$table->addIndex(['last_activity'], 'authtoken_last_activity_index');
505
-		}
506
-
507
-		if (!$schema->hasTable('bruteforce_attempts')) {
508
-			$table = $schema->createTable('bruteforce_attempts');
509
-			$table->addColumn('id', 'integer', [
510
-				'autoincrement' => true,
511
-				'notnull' => true,
512
-				'length' => 4,
513
-			]);
514
-			$table->addColumn('action', 'string', [
515
-				'notnull' => true,
516
-				'length' => 64,
517
-				'default' => '',
518
-			]);
519
-			$table->addColumn('occurred', 'integer', [
520
-				'notnull' => true,
521
-				'length' => 4,
522
-				'default' => 0,
523
-			]);
524
-			$table->addColumn('ip', 'string', [
525
-				'notnull' => true,
526
-				'length' => 255,
527
-				'default' => '',
528
-			]);
529
-			$table->addColumn('subnet', 'string', [
530
-				'notnull' => true,
531
-				'length' => 255,
532
-				'default' => '',
533
-			]);
534
-			$table->addColumn('metadata', 'string', [
535
-				'notnull' => true,
536
-				'length' => 255,
537
-				'default' => '',
538
-			]);
539
-			$table->setPrimaryKey(['id']);
540
-			$table->addIndex(['ip'], 'bruteforce_attempts_ip');
541
-			$table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
542
-		}
543
-
544
-		if (!$schema->hasTable('vcategory')) {
545
-			$table = $schema->createTable('vcategory');
546
-			$table->addColumn('id', 'integer', [
547
-				'autoincrement' => true,
548
-				'notnull' => true,
549
-				'length' => 4,
550
-			]);
551
-			$table->addColumn('uid', 'string', [
552
-				'notnull' => true,
553
-				'length' => 64,
554
-				'default' => '',
555
-			]);
556
-			$table->addColumn('type', 'string', [
557
-				'notnull' => true,
558
-				'length' => 64,
559
-				'default' => '',
560
-			]);
561
-			$table->addColumn('category', 'string', [
562
-				'notnull' => true,
563
-				'length' => 255,
564
-				'default' => '',
565
-			]);
566
-			$table->setPrimaryKey(['id']);
567
-			$table->addIndex(['uid'], 'uid_index');
568
-			$table->addIndex(['type'], 'type_index');
569
-			$table->addIndex(['category'], 'category_index');
570
-		}
571
-
572
-		if (!$schema->hasTable('vcategory_to_object')) {
573
-			$table = $schema->createTable('vcategory_to_object');
574
-			$table->addColumn('objid', 'integer', [
575
-				'notnull' => true,
576
-				'length' => 4,
577
-				'default' => 0,
578
-			]);
579
-			$table->addColumn('categoryid', 'integer', [
580
-				'notnull' => true,
581
-				'length' => 4,
582
-				'default' => 0,
583
-			]);
584
-			$table->addColumn('type', 'string', [
585
-				'notnull' => true,
586
-				'length' => 64,
587
-				'default' => '',
588
-			]);
589
-			$table->setPrimaryKey(['categoryid', 'objid', 'type']);
590
-			$table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
591
-		}
592
-
593
-		if (!$schema->hasTable('systemtag')) {
594
-			$table = $schema->createTable('systemtag');
595
-			$table->addColumn('id', 'integer', [
596
-				'autoincrement' => true,
597
-				'notnull' => true,
598
-				'length' => 4,
599
-			]);
600
-			$table->addColumn('name', 'string', [
601
-				'notnull' => true,
602
-				'length' => 64,
603
-				'default' => '',
604
-			]);
605
-			$table->addColumn('visibility', 'smallint', [
606
-				'notnull' => true,
607
-				'length' => 1,
608
-				'default' => 1,
609
-			]);
610
-			$table->addColumn('editable', 'smallint', [
611
-				'notnull' => true,
612
-				'length' => 1,
613
-				'default' => 1,
614
-			]);
615
-			$table->setPrimaryKey(['id']);
616
-			$table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
617
-		}
618
-
619
-		if (!$schema->hasTable('systemtag_object_mapping')) {
620
-			$table = $schema->createTable('systemtag_object_mapping');
621
-			$table->addColumn('objectid', 'string', [
622
-				'notnull' => true,
623
-				'length' => 64,
624
-				'default' => '',
625
-			]);
626
-			$table->addColumn('objecttype', 'string', [
627
-				'notnull' => true,
628
-				'length' => 64,
629
-				'default' => '',
630
-			]);
631
-			$table->addColumn('systemtagid', 'integer', [
632
-				'notnull' => true,
633
-				'length' => 4,
634
-				'default' => 0,
635
-			]);
636
-			$table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
637
-		}
638
-
639
-		if (!$schema->hasTable('systemtag_group')) {
640
-			$table = $schema->createTable('systemtag_group');
641
-			$table->addColumn('systemtagid', 'integer', [
642
-				'notnull' => true,
643
-				'length' => 4,
644
-				'default' => 0,
645
-			]);
646
-			$table->addColumn('gid', 'string', [
647
-				'notnull' => true,
648
-			]);
649
-			$table->setPrimaryKey(['gid', 'systemtagid']);
650
-		}
651
-
652
-		if (!$schema->hasTable('privatedata')) {
653
-			$table = $schema->createTable('privatedata');
654
-			$table->addColumn('keyid', 'integer', [
655
-				'autoincrement' => true,
656
-				'notnull' => true,
657
-				'length' => 4,
658
-			]);
659
-			$table->addColumn('user', 'string', [
660
-				'notnull' => true,
661
-				'length' => 64,
662
-				'default' => '',
663
-			]);
664
-			$table->addColumn('app', 'string', [
665
-				'notnull' => true,
666
-				'length' => 255,
667
-				'default' => '',
668
-			]);
669
-			$table->addColumn('key', 'string', [
670
-				'notnull' => true,
671
-				'length' => 255,
672
-				'default' => '',
673
-			]);
674
-			$table->addColumn('value', 'string', [
675
-				'notnull' => true,
676
-				'length' => 255,
677
-				'default' => '',
678
-			]);
679
-			$table->setPrimaryKey(['keyid']);
680
-		}
681
-
682
-		if (!$schema->hasTable('file_locks')) {
683
-			$table = $schema->createTable('file_locks');
684
-			$table->addColumn('id', 'integer', [
685
-				'autoincrement' => true,
686
-				'notnull' => true,
687
-				'length' => 4,
688
-			]);
689
-			$table->addColumn('lock', 'integer', [
690
-				'notnull' => true,
691
-				'length' => 4,
692
-				'default' => 0,
693
-			]);
694
-			$table->addColumn('key', 'string', [
695
-				'notnull' => true,
696
-				'length' => 64,
697
-			]);
698
-			$table->addColumn('ttl', 'integer', [
699
-				'notnull' => true,
700
-				'length' => 4,
701
-				'default' => -1,
702
-			]);
703
-			$table->setPrimaryKey(['id']);
704
-			$table->addUniqueIndex(['key'], 'lock_key_index');
705
-			$table->addIndex(['ttl'], 'lock_ttl_index');
706
-		}
707
-
708
-		if (!$schema->hasTable('comments')) {
709
-			$table = $schema->createTable('comments');
710
-			$table->addColumn('id', 'integer', [
711
-				'autoincrement' => true,
712
-				'notnull' => true,
713
-				'length' => 4,
714
-			]);
715
-			$table->addColumn('parent_id', 'integer', [
716
-				'notnull' => true,
717
-				'length' => 4,
718
-				'default' => 0,
719
-			]);
720
-			$table->addColumn('topmost_parent_id', 'integer', [
721
-				'notnull' => true,
722
-				'length' => 4,
723
-				'default' => 0,
724
-			]);
725
-			$table->addColumn('children_count', 'integer', [
726
-				'notnull' => true,
727
-				'length' => 4,
728
-				'default' => 0,
729
-			]);
730
-			$table->addColumn('actor_type', 'string', [
731
-				'notnull' => true,
732
-				'length' => 64,
733
-				'default' => '',
734
-			]);
735
-			$table->addColumn('actor_id', 'string', [
736
-				'notnull' => true,
737
-				'length' => 64,
738
-				'default' => '',
739
-			]);
740
-			$table->addColumn('message', 'text', [
741
-				'notnull' => false,
742
-			]);
743
-			$table->addColumn('verb', 'string', [
744
-				'notnull' => false,
745
-				'length' => 64,
746
-			]);
747
-			$table->addColumn('creation_timestamp', 'datetime', [
748
-				'notnull' => false,
749
-			]);
750
-			$table->addColumn('latest_child_timestamp', 'datetime', [
751
-				'notnull' => false,
752
-			]);
753
-			$table->addColumn('object_type', 'string', [
754
-				'notnull' => true,
755
-				'length' => 64,
756
-				'default' => '',
757
-			]);
758
-			$table->addColumn('object_id', 'string', [
759
-				'notnull' => true,
760
-				'length' => 64,
761
-				'default' => '',
762
-			]);
763
-			$table->setPrimaryKey(['id']);
764
-			$table->addIndex(['parent_id'], 'comments_parent_id_index');
765
-			$table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
766
-			$table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
767
-			$table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
768
-		}
769
-
770
-		if (!$schema->hasTable('comments_read_markers')) {
771
-			$table = $schema->createTable('comments_read_markers');
772
-			$table->addColumn('user_id', 'string', [
773
-				'notnull' => true,
774
-				'length' => 64,
775
-				'default' => '',
776
-			]);
777
-			$table->addColumn('marker_datetime', 'datetime', [
778
-				'notnull' => false,
779
-			]);
780
-			$table->addColumn('object_type', 'string', [
781
-				'notnull' => true,
782
-				'length' => 64,
783
-				'default' => '',
784
-			]);
785
-			$table->addColumn('object_id', 'string', [
786
-				'notnull' => true,
787
-				'length' => 64,
788
-				'default' => '',
789
-			]);
790
-			$table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
791
-			$table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
792
-		}
793
-
794
-		if (!$schema->hasTable('credentials')) {
795
-			$table = $schema->createTable('credentials');
796
-			$table->addColumn('user', 'string', [
797
-				'notnull' => true,
798
-				'length' => 64,
799
-			]);
800
-			$table->addColumn('identifier', 'string', [
801
-				'notnull' => true,
802
-				'length' => 64,
803
-			]);
804
-			$table->addColumn('credentials', 'text', [
805
-				'notnull' => false,
806
-			]);
807
-			$table->setPrimaryKey(['user', 'identifier']);
808
-			$table->addIndex(['user'], 'credentials_user');
809
-		}
810
-
811
-		if (!$schema->hasTable('admin_sections')) {
812
-			$table = $schema->createTable('admin_sections');
813
-			$table->addColumn('id', 'string', [
814
-				'notnull' => true,
815
-				'length' => 64,
816
-			]);
817
-			$table->addColumn('class', 'string', [
818
-				'notnull' => true,
819
-				'length' => 255,
820
-				'default' => '',
821
-			]);
822
-			$table->addColumn('priority', 'smallint', [
823
-				'notnull' => true,
824
-				'length' => 1,
825
-				'default' => 0,
826
-			]);
827
-			$table->setPrimaryKey(['id']);
828
-			$table->addUniqueIndex(['class'], 'admin_sections_class');
829
-		}
830
-
831
-		if (!$schema->hasTable('admin_settings')) {
832
-			$table = $schema->createTable('admin_settings');
833
-			$table->addColumn('id', 'integer', [
834
-				'autoincrement' => true,
835
-				'notnull' => true,
836
-				'length' => 4,
837
-			]);
838
-			$table->addColumn('class', 'string', [
839
-				'notnull' => true,
840
-				'length' => 255,
841
-				'default' => '',
842
-			]);
843
-			$table->addColumn('section', 'string', [
844
-				'notnull' => false,
845
-				'length' => 64,
846
-			]);
847
-			$table->addColumn('priority', 'smallint', [
848
-				'notnull' => true,
849
-				'length' => 1,
850
-				'default' => 0,
851
-			]);
852
-			$table->setPrimaryKey(['id']);
853
-			$table->addUniqueIndex(['class'], 'admin_settings_class');
854
-			$table->addIndex(['section'], 'admin_settings_section');
855
-		}
856
-
857
-		if (!$schema->hasTable('personal_sections')) {
858
-			$table = $schema->createTable('personal_sections');
859
-			$table->addColumn('id', 'string', [
860
-				'notnull' => true,
861
-				'length' => 64,
862
-			]);
863
-			$table->addColumn('class', 'string', [
864
-				'notnull' => true,
865
-				'length' => 255,
866
-				'default' => '',
867
-			]);
868
-			$table->addColumn('priority', 'smallint', [
869
-				'notnull' => true,
870
-				'length' => 1,
871
-				'default' => 0,
872
-			]);
873
-			$table->setPrimaryKey(['id']);
874
-			$table->addUniqueIndex(['class'], 'personal_sections_class');
875
-		}
876
-
877
-		if (!$schema->hasTable('personal_settings')) {
878
-			$table = $schema->createTable('personal_settings');
879
-			$table->addColumn('id', 'integer', [
880
-				'autoincrement' => true,
881
-				'notnull' => true,
882
-				'length' => 4,
883
-			]);
884
-			$table->addColumn('class', 'string', [
885
-				'notnull' => true,
886
-				'length' => 255,
887
-				'default' => '',
888
-			]);
889
-			$table->addColumn('section', 'string', [
890
-				'notnull' => false,
891
-				'length' => 64,
892
-			]);
893
-			$table->addColumn('priority', 'smallint', [
894
-				'notnull' => true,
895
-				'length' => 1,
896
-				'default' => 0,
897
-			]);
898
-			$table->setPrimaryKey(['id']);
899
-			$table->addUniqueIndex(['class'], 'personal_settings_class');
900
-			$table->addIndex(['section'], 'personal_settings_section');
901
-		}
902
-
903
-		if (!$schema->hasTable('accounts')) {
904
-			$table = $schema->createTable('accounts');
905
-			$table->addColumn('uid', 'string', [
906
-				'notnull' => true,
907
-				'length' => 64,
908
-				'default' => '',
909
-			]);
910
-			$table->addColumn('data', 'text', [
911
-				'notnull' => true,
912
-				'default' => '',
913
-			]);
914
-			$table->setPrimaryKey(['uid']);
915
-		}
916
-		return $schema;
917
-	}
918
-
919
-	/**
920
-	 * @param IOutput $output
921
-	 * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
922
-	 * @param array $options
923
-	 * @since 13.0.0
924
-	 */
925
-	public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
926
-	}
13
+    /**
14
+     * @param IOutput $output
15
+     * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
16
+     * @param array $options
17
+     * @since 13.0.0
18
+     */
19
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
20
+    }
21
+
22
+    /**
23
+     * @param IOutput $output
24
+     * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
25
+     * @param array $options
26
+     * @return null|Schema
27
+     * @since 13.0.0
28
+     */
29
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
30
+        /** @var Schema $schema */
31
+        $schema = $schemaClosure();
32
+
33
+        if (!$schema->hasTable('appconfig')) {
34
+            $table = $schema->createTable('appconfig');
35
+            $table->addColumn('appid', 'string', [
36
+                'notnull' => true,
37
+                'length' => 32,
38
+                'default' => '',
39
+            ]);
40
+            $table->addColumn('configkey', 'string', [
41
+                'notnull' => true,
42
+                'length' => 64,
43
+                'default' => '',
44
+            ]);
45
+            $table->addColumn('configvalue', 'text', [
46
+                'notnull' => false,
47
+            ]);
48
+            $table->setPrimaryKey(['appid', 'configkey']);
49
+            $table->addIndex(['configkey'], 'appconfig_config_key_index');
50
+            $table->addIndex(['appid'], 'appconfig_appid_key');
51
+        }
52
+
53
+        if (!$schema->hasTable('storages')) {
54
+            $table = $schema->createTable('storages');
55
+            $table->addColumn('id', 'string', [
56
+                'notnull' => false,
57
+                'length' => 64,
58
+            ]);
59
+            $table->addColumn('numeric_id', 'integer', [
60
+                'autoincrement' => true,
61
+                'notnull' => true,
62
+                'length' => 4,
63
+            ]);
64
+            $table->addColumn('available', 'integer', [
65
+                'notnull' => true,
66
+                'default' => 1,
67
+            ]);
68
+            $table->addColumn('last_checked', 'integer', [
69
+                'notnull' => false,
70
+            ]);
71
+            $table->setPrimaryKey(['numeric_id']);
72
+            $table->addUniqueIndex(['id'], 'storages_id_index');
73
+        }
74
+
75
+        if (!$schema->hasTable('mounts')) {
76
+            $table = $schema->createTable('mounts');
77
+            $table->addColumn('id', 'integer', [
78
+                'autoincrement' => true,
79
+                'notnull' => true,
80
+                'length' => 4,
81
+            ]);
82
+            $table->addColumn('storage_id', 'integer', [
83
+                'notnull' => true,
84
+            ]);
85
+            $table->addColumn('root_id', 'integer', [
86
+                'notnull' => true,
87
+            ]);
88
+            $table->addColumn('user_id', 'string', [
89
+                'notnull' => true,
90
+                'length' => 64,
91
+            ]);
92
+            $table->addColumn('mount_point', 'string', [
93
+                'notnull' => true,
94
+                'length' => 4000,
95
+            ]);
96
+            $table->addColumn('mount_id', 'integer', [
97
+                'notnull' => false,
98
+            ]);
99
+            $table->setPrimaryKey(['id']);
100
+            $table->addIndex(['user_id'], 'mounts_user_index');
101
+            $table->addIndex(['storage_id'], 'mounts_storage_index');
102
+            $table->addIndex(['root_id'], 'mounts_root_index');
103
+            $table->addIndex(['mount_id'], 'mounts_mount_id_index');
104
+            $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
105
+        }
106
+
107
+        if (!$schema->hasTable('mimetypes')) {
108
+            $table = $schema->createTable('mimetypes');
109
+            $table->addColumn('id', 'integer', [
110
+                'autoincrement' => true,
111
+                'notnull' => true,
112
+                'length' => 4,
113
+            ]);
114
+            $table->addColumn('mimetype', 'string', [
115
+                'notnull' => true,
116
+                'length' => 255,
117
+                'default' => '',
118
+            ]);
119
+            $table->setPrimaryKey(['id']);
120
+            $table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
121
+        }
122
+
123
+        if (!$schema->hasTable('filecache')) {
124
+            $table = $schema->createTable('filecache');
125
+            $table->addColumn('fileid', 'integer', [
126
+                'autoincrement' => true,
127
+                'notnull' => true,
128
+                'length' => 4,
129
+            ]);
130
+            $table->addColumn('storage', 'integer', [
131
+                'notnull' => true,
132
+                'length' => 4,
133
+                'default' => 0,
134
+            ]);
135
+            $table->addColumn('path', 'string', [
136
+                'notnull' => false,
137
+                'length' => 4000,
138
+            ]);
139
+            $table->addColumn('path_hash', 'string', [
140
+                'notnull' => true,
141
+                'length' => 32,
142
+                'default' => '',
143
+            ]);
144
+            $table->addColumn('parent', 'integer', [
145
+                'notnull' => true,
146
+                'length' => 4,
147
+                'default' => 0,
148
+            ]);
149
+            $table->addColumn('name', 'string', [
150
+                'notnull' => false,
151
+                'length' => 250,
152
+            ]);
153
+            $table->addColumn('mimetype', 'integer', [
154
+                'notnull' => true,
155
+                'length' => 4,
156
+                'default' => 0,
157
+            ]);
158
+            $table->addColumn('mimepart', 'integer', [
159
+                'notnull' => true,
160
+                'length' => 4,
161
+                'default' => 0,
162
+            ]);
163
+            $table->addColumn('size', 'bigint', [
164
+                'notnull' => true,
165
+                'length' => 8,
166
+                'default' => 0,
167
+            ]);
168
+            $table->addColumn('mtime', 'integer', [
169
+                'notnull' => true,
170
+                'length' => 4,
171
+                'default' => 0,
172
+            ]);
173
+            $table->addColumn('storage_mtime', 'integer', [
174
+                'notnull' => true,
175
+                'length' => 4,
176
+                'default' => 0,
177
+            ]);
178
+            $table->addColumn('encrypted', 'integer', [
179
+                'notnull' => true,
180
+                'length' => 4,
181
+                'default' => 0,
182
+            ]);
183
+            $table->addColumn('unencrypted_size', 'bigint', [
184
+                'notnull' => true,
185
+                'length' => 8,
186
+                'default' => 0,
187
+            ]);
188
+            $table->addColumn('etag', 'string', [
189
+                'notnull' => false,
190
+                'length' => 40,
191
+            ]);
192
+            $table->addColumn('permissions', 'integer', [
193
+                'notnull' => false,
194
+                'length' => 4,
195
+                'default' => 0,
196
+            ]);
197
+            $table->addColumn('checksum', 'string', [
198
+                'notnull' => false,
199
+                'length' => 255,
200
+            ]);
201
+            $table->setPrimaryKey(['fileid']);
202
+            $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
203
+            $table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
204
+            $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
205
+            $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
206
+            $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
207
+        }
208
+
209
+        if (!$schema->hasTable('group_user')) {
210
+            $table = $schema->createTable('group_user');
211
+            $table->addColumn('gid', 'string', [
212
+                'notnull' => true,
213
+                'length' => 64,
214
+                'default' => '',
215
+            ]);
216
+            $table->addColumn('uid', 'string', [
217
+                'notnull' => true,
218
+                'length' => 64,
219
+                'default' => '',
220
+            ]);
221
+            $table->setPrimaryKey(['gid', 'uid']);
222
+            $table->addIndex(['uid'], 'gu_uid_index');
223
+        }
224
+
225
+        if (!$schema->hasTable('group_admin')) {
226
+            $table = $schema->createTable('group_admin');
227
+            $table->addColumn('gid', 'string', [
228
+                'notnull' => true,
229
+                'length' => 64,
230
+                'default' => '',
231
+            ]);
232
+            $table->addColumn('uid', 'string', [
233
+                'notnull' => true,
234
+                'length' => 64,
235
+                'default' => '',
236
+            ]);
237
+            $table->setPrimaryKey(['gid', 'uid']);
238
+            $table->addIndex(['uid'], 'group_admin_uid');
239
+        }
240
+
241
+        if (!$schema->hasTable('groups')) {
242
+            $table = $schema->createTable('groups');
243
+            $table->addColumn('gid', 'string', [
244
+                'notnull' => true,
245
+                'length' => 64,
246
+                'default' => '',
247
+            ]);
248
+            $table->setPrimaryKey(['gid']);
249
+        }
250
+
251
+        if (!$schema->hasTable('preferences')) {
252
+            $table = $schema->createTable('preferences');
253
+            $table->addColumn('userid', 'string', [
254
+                'notnull' => true,
255
+                'length' => 64,
256
+                'default' => '',
257
+            ]);
258
+            $table->addColumn('appid', 'string', [
259
+                'notnull' => true,
260
+                'length' => 32,
261
+                'default' => '',
262
+            ]);
263
+            $table->addColumn('configkey', 'string', [
264
+                'notnull' => true,
265
+                'length' => 64,
266
+                'default' => '',
267
+            ]);
268
+            $table->addColumn('configvalue', 'text', [
269
+                'notnull' => false,
270
+            ]);
271
+            $table->setPrimaryKey(['userid', 'appid', 'configkey']);
272
+        }
273
+
274
+        if (!$schema->hasTable('properties')) {
275
+            $table = $schema->createTable('properties');
276
+            $table->addColumn('id', 'integer', [
277
+                'autoincrement' => true,
278
+                'notnull' => true,
279
+                'length' => 4,
280
+            ]);
281
+            $table->addColumn('userid', 'string', [
282
+                'notnull' => true,
283
+                'length' => 64,
284
+                'default' => '',
285
+            ]);
286
+            $table->addColumn('propertypath', 'string', [
287
+                'notnull' => true,
288
+                'length' => 255,
289
+                'default' => '',
290
+            ]);
291
+            $table->addColumn('propertyname', 'string', [
292
+                'notnull' => true,
293
+                'length' => 255,
294
+                'default' => '',
295
+            ]);
296
+            $table->addColumn('propertyvalue', 'text', [
297
+                'notnull' => true,
298
+            ]);
299
+            $table->setPrimaryKey(['id']);
300
+            $table->addIndex(['userid'], 'property_index');
301
+        }
302
+
303
+        if (!$schema->hasTable('share')) {
304
+            $table = $schema->createTable('share');
305
+            $table->addColumn('id', 'integer', [
306
+                'autoincrement' => true,
307
+                'notnull' => true,
308
+                'length' => 4,
309
+            ]);
310
+            $table->addColumn('share_type', 'smallint', [
311
+                'notnull' => true,
312
+                'length' => 1,
313
+                'default' => 0,
314
+            ]);
315
+            $table->addColumn('share_with', 'string', [
316
+                'notnull' => false,
317
+                'length' => 255,
318
+            ]);
319
+            $table->addColumn('password', 'string', [
320
+                'notnull' => false,
321
+                'length' => 255,
322
+            ]);
323
+            $table->addColumn('uid_owner', 'string', [
324
+                'notnull' => true,
325
+                'length' => 64,
326
+                'default' => '',
327
+            ]);
328
+            $table->addColumn('uid_initiator', 'string', [
329
+                'notnull' => false,
330
+                'length' => 64,
331
+            ]);
332
+            $table->addColumn('parent', 'integer', [
333
+                'notnull' => false,
334
+                'length' => 4,
335
+            ]);
336
+            $table->addColumn('item_type', 'string', [
337
+                'notnull' => true,
338
+                'length' => 64,
339
+                'default' => '',
340
+            ]);
341
+            $table->addColumn('item_source', 'string', [
342
+                'notnull' => false,
343
+                'length' => 255,
344
+            ]);
345
+            $table->addColumn('item_target', 'string', [
346
+                'notnull' => false,
347
+                'length' => 255,
348
+            ]);
349
+            $table->addColumn('file_source', 'integer', [
350
+                'notnull' => false,
351
+                'length' => 4,
352
+            ]);
353
+            $table->addColumn('file_target', 'string', [
354
+                'notnull' => false,
355
+                'length' => 512,
356
+            ]);
357
+            $table->addColumn('permissions', 'smallint', [
358
+                'notnull' => true,
359
+                'length' => 1,
360
+                'default' => 0,
361
+            ]);
362
+            $table->addColumn('stime', 'bigint', [
363
+                'notnull' => true,
364
+                'length' => 8,
365
+                'default' => 0,
366
+            ]);
367
+            $table->addColumn('accepted', 'smallint', [
368
+                'notnull' => true,
369
+                'length' => 1,
370
+                'default' => 0,
371
+            ]);
372
+            $table->addColumn('expiration', 'datetime', [
373
+                'notnull' => false,
374
+            ]);
375
+            $table->addColumn('token', 'string', [
376
+                'notnull' => false,
377
+                'length' => 32,
378
+            ]);
379
+            $table->addColumn('mail_send', 'smallint', [
380
+                'notnull' => true,
381
+                'length' => 1,
382
+                'default' => 0,
383
+            ]);
384
+            $table->addColumn('share_name', 'string', [
385
+                'notnull' => false,
386
+                'length' => 64,
387
+            ]);
388
+            $table->setPrimaryKey(['id']);
389
+            $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
390
+            $table->addIndex(['file_source'], 'file_source_index');
391
+            $table->addIndex(['token'], 'token_index');
392
+        }
393
+
394
+        if (!$schema->hasTable('jobs')) {
395
+            $table = $schema->createTable('jobs');
396
+            $table->addColumn('id', 'integer', [
397
+                'autoincrement' => true,
398
+                'notnull' => true,
399
+                'length' => 4,
400
+            ]);
401
+            $table->addColumn('class', 'string', [
402
+                'notnull' => true,
403
+                'length' => 255,
404
+                'default' => '',
405
+            ]);
406
+            $table->addColumn('argument', 'string', [
407
+                'notnull' => true,
408
+                'length' => 4000,
409
+                'default' => '',
410
+            ]);
411
+            $table->addColumn('last_run', 'integer', [
412
+                'notnull' => false,
413
+                'default' => 0,
414
+            ]);
415
+            $table->addColumn('last_checked', 'integer', [
416
+                'notnull' => false,
417
+                'default' => 0,
418
+            ]);
419
+            $table->addColumn('reserved_at', 'integer', [
420
+                'notnull' => false,
421
+                'default' => 0,
422
+            ]);
423
+            $table->addColumn('execution_duration', 'integer', [
424
+                'notnull' => true,
425
+                'default' => 0,
426
+            ]);
427
+            $table->setPrimaryKey(['id']);
428
+            $table->addIndex(['class'], 'job_class_index');
429
+        }
430
+
431
+        if (!$schema->hasTable('users')) {
432
+            $table = $schema->createTable('users');
433
+            $table->addColumn('uid', 'string', [
434
+                'notnull' => true,
435
+                'length' => 64,
436
+                'default' => '',
437
+            ]);
438
+            $table->addColumn('displayname', 'string', [
439
+                'notnull' => false,
440
+                'length' => 64,
441
+            ]);
442
+            $table->addColumn('password', 'string', [
443
+                'notnull' => true,
444
+                'length' => 255,
445
+                'default' => '',
446
+            ]);
447
+            $table->setPrimaryKey(['uid']);
448
+        }
449
+
450
+        if (!$schema->hasTable('authtoken')) {
451
+            $table = $schema->createTable('authtoken');
452
+            $table->addColumn('id', 'integer', [
453
+                'autoincrement' => true,
454
+                'notnull' => true,
455
+                'length' => 4,
456
+            ]);
457
+            $table->addColumn('uid', 'string', [
458
+                'notnull' => true,
459
+                'length' => 64,
460
+                'default' => '',
461
+            ]);
462
+            $table->addColumn('login_name', 'string', [
463
+                'notnull' => true,
464
+                'length' => 64,
465
+                'default' => '',
466
+            ]);
467
+            $table->addColumn('password', 'text', [
468
+                'notnull' => false,
469
+            ]);
470
+            $table->addColumn('name', 'text', [
471
+                'notnull' => true,
472
+                'default' => '',
473
+            ]);
474
+            $table->addColumn('token', 'string', [
475
+                'notnull' => true,
476
+                'length' => 200,
477
+                'default' => '',
478
+            ]);
479
+            $table->addColumn('type', 'smallint', [
480
+                'notnull' => true,
481
+                'length' => 2,
482
+                'default' => 0,
483
+            ]);
484
+            $table->addColumn('remember', 'smallint', [
485
+                'notnull' => true,
486
+                'length' => 1,
487
+                'default' => 0,
488
+            ]);
489
+            $table->addColumn('last_activity', 'integer', [
490
+                'notnull' => true,
491
+                'length' => 4,
492
+                'default' => 0,
493
+            ]);
494
+            $table->addColumn('last_check', 'integer', [
495
+                'notnull' => true,
496
+                'length' => 4,
497
+                'default' => 0,
498
+            ]);
499
+            $table->addColumn('scope', 'text', [
500
+                'notnull' => false,
501
+            ]);
502
+            $table->setPrimaryKey(['id']);
503
+            $table->addUniqueIndex(['token'], 'authtoken_token_index');
504
+            $table->addIndex(['last_activity'], 'authtoken_last_activity_index');
505
+        }
506
+
507
+        if (!$schema->hasTable('bruteforce_attempts')) {
508
+            $table = $schema->createTable('bruteforce_attempts');
509
+            $table->addColumn('id', 'integer', [
510
+                'autoincrement' => true,
511
+                'notnull' => true,
512
+                'length' => 4,
513
+            ]);
514
+            $table->addColumn('action', 'string', [
515
+                'notnull' => true,
516
+                'length' => 64,
517
+                'default' => '',
518
+            ]);
519
+            $table->addColumn('occurred', 'integer', [
520
+                'notnull' => true,
521
+                'length' => 4,
522
+                'default' => 0,
523
+            ]);
524
+            $table->addColumn('ip', 'string', [
525
+                'notnull' => true,
526
+                'length' => 255,
527
+                'default' => '',
528
+            ]);
529
+            $table->addColumn('subnet', 'string', [
530
+                'notnull' => true,
531
+                'length' => 255,
532
+                'default' => '',
533
+            ]);
534
+            $table->addColumn('metadata', 'string', [
535
+                'notnull' => true,
536
+                'length' => 255,
537
+                'default' => '',
538
+            ]);
539
+            $table->setPrimaryKey(['id']);
540
+            $table->addIndex(['ip'], 'bruteforce_attempts_ip');
541
+            $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
542
+        }
543
+
544
+        if (!$schema->hasTable('vcategory')) {
545
+            $table = $schema->createTable('vcategory');
546
+            $table->addColumn('id', 'integer', [
547
+                'autoincrement' => true,
548
+                'notnull' => true,
549
+                'length' => 4,
550
+            ]);
551
+            $table->addColumn('uid', 'string', [
552
+                'notnull' => true,
553
+                'length' => 64,
554
+                'default' => '',
555
+            ]);
556
+            $table->addColumn('type', 'string', [
557
+                'notnull' => true,
558
+                'length' => 64,
559
+                'default' => '',
560
+            ]);
561
+            $table->addColumn('category', 'string', [
562
+                'notnull' => true,
563
+                'length' => 255,
564
+                'default' => '',
565
+            ]);
566
+            $table->setPrimaryKey(['id']);
567
+            $table->addIndex(['uid'], 'uid_index');
568
+            $table->addIndex(['type'], 'type_index');
569
+            $table->addIndex(['category'], 'category_index');
570
+        }
571
+
572
+        if (!$schema->hasTable('vcategory_to_object')) {
573
+            $table = $schema->createTable('vcategory_to_object');
574
+            $table->addColumn('objid', 'integer', [
575
+                'notnull' => true,
576
+                'length' => 4,
577
+                'default' => 0,
578
+            ]);
579
+            $table->addColumn('categoryid', 'integer', [
580
+                'notnull' => true,
581
+                'length' => 4,
582
+                'default' => 0,
583
+            ]);
584
+            $table->addColumn('type', 'string', [
585
+                'notnull' => true,
586
+                'length' => 64,
587
+                'default' => '',
588
+            ]);
589
+            $table->setPrimaryKey(['categoryid', 'objid', 'type']);
590
+            $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
591
+        }
592
+
593
+        if (!$schema->hasTable('systemtag')) {
594
+            $table = $schema->createTable('systemtag');
595
+            $table->addColumn('id', 'integer', [
596
+                'autoincrement' => true,
597
+                'notnull' => true,
598
+                'length' => 4,
599
+            ]);
600
+            $table->addColumn('name', 'string', [
601
+                'notnull' => true,
602
+                'length' => 64,
603
+                'default' => '',
604
+            ]);
605
+            $table->addColumn('visibility', 'smallint', [
606
+                'notnull' => true,
607
+                'length' => 1,
608
+                'default' => 1,
609
+            ]);
610
+            $table->addColumn('editable', 'smallint', [
611
+                'notnull' => true,
612
+                'length' => 1,
613
+                'default' => 1,
614
+            ]);
615
+            $table->setPrimaryKey(['id']);
616
+            $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
617
+        }
618
+
619
+        if (!$schema->hasTable('systemtag_object_mapping')) {
620
+            $table = $schema->createTable('systemtag_object_mapping');
621
+            $table->addColumn('objectid', 'string', [
622
+                'notnull' => true,
623
+                'length' => 64,
624
+                'default' => '',
625
+            ]);
626
+            $table->addColumn('objecttype', 'string', [
627
+                'notnull' => true,
628
+                'length' => 64,
629
+                'default' => '',
630
+            ]);
631
+            $table->addColumn('systemtagid', 'integer', [
632
+                'notnull' => true,
633
+                'length' => 4,
634
+                'default' => 0,
635
+            ]);
636
+            $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
637
+        }
638
+
639
+        if (!$schema->hasTable('systemtag_group')) {
640
+            $table = $schema->createTable('systemtag_group');
641
+            $table->addColumn('systemtagid', 'integer', [
642
+                'notnull' => true,
643
+                'length' => 4,
644
+                'default' => 0,
645
+            ]);
646
+            $table->addColumn('gid', 'string', [
647
+                'notnull' => true,
648
+            ]);
649
+            $table->setPrimaryKey(['gid', 'systemtagid']);
650
+        }
651
+
652
+        if (!$schema->hasTable('privatedata')) {
653
+            $table = $schema->createTable('privatedata');
654
+            $table->addColumn('keyid', 'integer', [
655
+                'autoincrement' => true,
656
+                'notnull' => true,
657
+                'length' => 4,
658
+            ]);
659
+            $table->addColumn('user', 'string', [
660
+                'notnull' => true,
661
+                'length' => 64,
662
+                'default' => '',
663
+            ]);
664
+            $table->addColumn('app', 'string', [
665
+                'notnull' => true,
666
+                'length' => 255,
667
+                'default' => '',
668
+            ]);
669
+            $table->addColumn('key', 'string', [
670
+                'notnull' => true,
671
+                'length' => 255,
672
+                'default' => '',
673
+            ]);
674
+            $table->addColumn('value', 'string', [
675
+                'notnull' => true,
676
+                'length' => 255,
677
+                'default' => '',
678
+            ]);
679
+            $table->setPrimaryKey(['keyid']);
680
+        }
681
+
682
+        if (!$schema->hasTable('file_locks')) {
683
+            $table = $schema->createTable('file_locks');
684
+            $table->addColumn('id', 'integer', [
685
+                'autoincrement' => true,
686
+                'notnull' => true,
687
+                'length' => 4,
688
+            ]);
689
+            $table->addColumn('lock', 'integer', [
690
+                'notnull' => true,
691
+                'length' => 4,
692
+                'default' => 0,
693
+            ]);
694
+            $table->addColumn('key', 'string', [
695
+                'notnull' => true,
696
+                'length' => 64,
697
+            ]);
698
+            $table->addColumn('ttl', 'integer', [
699
+                'notnull' => true,
700
+                'length' => 4,
701
+                'default' => -1,
702
+            ]);
703
+            $table->setPrimaryKey(['id']);
704
+            $table->addUniqueIndex(['key'], 'lock_key_index');
705
+            $table->addIndex(['ttl'], 'lock_ttl_index');
706
+        }
707
+
708
+        if (!$schema->hasTable('comments')) {
709
+            $table = $schema->createTable('comments');
710
+            $table->addColumn('id', 'integer', [
711
+                'autoincrement' => true,
712
+                'notnull' => true,
713
+                'length' => 4,
714
+            ]);
715
+            $table->addColumn('parent_id', 'integer', [
716
+                'notnull' => true,
717
+                'length' => 4,
718
+                'default' => 0,
719
+            ]);
720
+            $table->addColumn('topmost_parent_id', 'integer', [
721
+                'notnull' => true,
722
+                'length' => 4,
723
+                'default' => 0,
724
+            ]);
725
+            $table->addColumn('children_count', 'integer', [
726
+                'notnull' => true,
727
+                'length' => 4,
728
+                'default' => 0,
729
+            ]);
730
+            $table->addColumn('actor_type', 'string', [
731
+                'notnull' => true,
732
+                'length' => 64,
733
+                'default' => '',
734
+            ]);
735
+            $table->addColumn('actor_id', 'string', [
736
+                'notnull' => true,
737
+                'length' => 64,
738
+                'default' => '',
739
+            ]);
740
+            $table->addColumn('message', 'text', [
741
+                'notnull' => false,
742
+            ]);
743
+            $table->addColumn('verb', 'string', [
744
+                'notnull' => false,
745
+                'length' => 64,
746
+            ]);
747
+            $table->addColumn('creation_timestamp', 'datetime', [
748
+                'notnull' => false,
749
+            ]);
750
+            $table->addColumn('latest_child_timestamp', 'datetime', [
751
+                'notnull' => false,
752
+            ]);
753
+            $table->addColumn('object_type', 'string', [
754
+                'notnull' => true,
755
+                'length' => 64,
756
+                'default' => '',
757
+            ]);
758
+            $table->addColumn('object_id', 'string', [
759
+                'notnull' => true,
760
+                'length' => 64,
761
+                'default' => '',
762
+            ]);
763
+            $table->setPrimaryKey(['id']);
764
+            $table->addIndex(['parent_id'], 'comments_parent_id_index');
765
+            $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
766
+            $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
767
+            $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
768
+        }
769
+
770
+        if (!$schema->hasTable('comments_read_markers')) {
771
+            $table = $schema->createTable('comments_read_markers');
772
+            $table->addColumn('user_id', 'string', [
773
+                'notnull' => true,
774
+                'length' => 64,
775
+                'default' => '',
776
+            ]);
777
+            $table->addColumn('marker_datetime', 'datetime', [
778
+                'notnull' => false,
779
+            ]);
780
+            $table->addColumn('object_type', 'string', [
781
+                'notnull' => true,
782
+                'length' => 64,
783
+                'default' => '',
784
+            ]);
785
+            $table->addColumn('object_id', 'string', [
786
+                'notnull' => true,
787
+                'length' => 64,
788
+                'default' => '',
789
+            ]);
790
+            $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
791
+            $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
792
+        }
793
+
794
+        if (!$schema->hasTable('credentials')) {
795
+            $table = $schema->createTable('credentials');
796
+            $table->addColumn('user', 'string', [
797
+                'notnull' => true,
798
+                'length' => 64,
799
+            ]);
800
+            $table->addColumn('identifier', 'string', [
801
+                'notnull' => true,
802
+                'length' => 64,
803
+            ]);
804
+            $table->addColumn('credentials', 'text', [
805
+                'notnull' => false,
806
+            ]);
807
+            $table->setPrimaryKey(['user', 'identifier']);
808
+            $table->addIndex(['user'], 'credentials_user');
809
+        }
810
+
811
+        if (!$schema->hasTable('admin_sections')) {
812
+            $table = $schema->createTable('admin_sections');
813
+            $table->addColumn('id', 'string', [
814
+                'notnull' => true,
815
+                'length' => 64,
816
+            ]);
817
+            $table->addColumn('class', 'string', [
818
+                'notnull' => true,
819
+                'length' => 255,
820
+                'default' => '',
821
+            ]);
822
+            $table->addColumn('priority', 'smallint', [
823
+                'notnull' => true,
824
+                'length' => 1,
825
+                'default' => 0,
826
+            ]);
827
+            $table->setPrimaryKey(['id']);
828
+            $table->addUniqueIndex(['class'], 'admin_sections_class');
829
+        }
830
+
831
+        if (!$schema->hasTable('admin_settings')) {
832
+            $table = $schema->createTable('admin_settings');
833
+            $table->addColumn('id', 'integer', [
834
+                'autoincrement' => true,
835
+                'notnull' => true,
836
+                'length' => 4,
837
+            ]);
838
+            $table->addColumn('class', 'string', [
839
+                'notnull' => true,
840
+                'length' => 255,
841
+                'default' => '',
842
+            ]);
843
+            $table->addColumn('section', 'string', [
844
+                'notnull' => false,
845
+                'length' => 64,
846
+            ]);
847
+            $table->addColumn('priority', 'smallint', [
848
+                'notnull' => true,
849
+                'length' => 1,
850
+                'default' => 0,
851
+            ]);
852
+            $table->setPrimaryKey(['id']);
853
+            $table->addUniqueIndex(['class'], 'admin_settings_class');
854
+            $table->addIndex(['section'], 'admin_settings_section');
855
+        }
856
+
857
+        if (!$schema->hasTable('personal_sections')) {
858
+            $table = $schema->createTable('personal_sections');
859
+            $table->addColumn('id', 'string', [
860
+                'notnull' => true,
861
+                'length' => 64,
862
+            ]);
863
+            $table->addColumn('class', 'string', [
864
+                'notnull' => true,
865
+                'length' => 255,
866
+                'default' => '',
867
+            ]);
868
+            $table->addColumn('priority', 'smallint', [
869
+                'notnull' => true,
870
+                'length' => 1,
871
+                'default' => 0,
872
+            ]);
873
+            $table->setPrimaryKey(['id']);
874
+            $table->addUniqueIndex(['class'], 'personal_sections_class');
875
+        }
876
+
877
+        if (!$schema->hasTable('personal_settings')) {
878
+            $table = $schema->createTable('personal_settings');
879
+            $table->addColumn('id', 'integer', [
880
+                'autoincrement' => true,
881
+                'notnull' => true,
882
+                'length' => 4,
883
+            ]);
884
+            $table->addColumn('class', 'string', [
885
+                'notnull' => true,
886
+                'length' => 255,
887
+                'default' => '',
888
+            ]);
889
+            $table->addColumn('section', 'string', [
890
+                'notnull' => false,
891
+                'length' => 64,
892
+            ]);
893
+            $table->addColumn('priority', 'smallint', [
894
+                'notnull' => true,
895
+                'length' => 1,
896
+                'default' => 0,
897
+            ]);
898
+            $table->setPrimaryKey(['id']);
899
+            $table->addUniqueIndex(['class'], 'personal_settings_class');
900
+            $table->addIndex(['section'], 'personal_settings_section');
901
+        }
902
+
903
+        if (!$schema->hasTable('accounts')) {
904
+            $table = $schema->createTable('accounts');
905
+            $table->addColumn('uid', 'string', [
906
+                'notnull' => true,
907
+                'length' => 64,
908
+                'default' => '',
909
+            ]);
910
+            $table->addColumn('data', 'text', [
911
+                'notnull' => true,
912
+                'default' => '',
913
+            ]);
914
+            $table->setPrimaryKey(['uid']);
915
+        }
916
+        return $schema;
917
+    }
918
+
919
+    /**
920
+     * @param IOutput $output
921
+     * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
922
+     * @param array $options
923
+     * @since 13.0.0
924
+     */
925
+    public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
926
+    }
927 927
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/GenerateCommand.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 
37 37
 class GenerateCommand extends Command {
38 38
 
39
-	protected static $_templateSimple =
40
-		'<?php
39
+    protected static $_templateSimple =
40
+        '<?php
41 41
 namespace <namespace>;
42 42
 
43 43
 use Doctrine\DBAL\Schema\Schema;
@@ -80,94 +80,94 @@  discard block
 block discarded – undo
80 80
 }
81 81
 ';
82 82
 
83
-	/** @var IDBConnection */
84
-	protected $connection;
85
-
86
-	/**
87
-	 * @param IDBConnection $connection
88
-	 */
89
-	public function __construct(IDBConnection $connection) {
90
-		$this->connection = $connection;
91
-
92
-		parent::__construct();
93
-	}
94
-
95
-	protected function configure() {
96
-		$this
97
-			->setName('migrations:generate')
98
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
99
-			->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
100
-		;
101
-
102
-		parent::configure();
103
-	}
104
-
105
-	public function execute(InputInterface $input, OutputInterface $output) {
106
-		$appName = $input->getArgument('app');
107
-		$version = $input->getArgument('version');
108
-
109
-		if (!preg_match('/^\d{1,16}$/',$version)) {
110
-			$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
111
-			return 1;
112
-		}
113
-
114
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
115
-
116
-		$date = date('YmdHis');
117
-		$path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
118
-
119
-		$output->writeln("New migration class has been generated to <info>$path</info>");
120
-		return 0;
121
-	}
122
-
123
-	/**
124
-	 * @param MigrationService $ms
125
-	 * @param string $className
126
-	 * @param string $schemaBody
127
-	 * @return string
128
-	 */
129
-	protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
130
-		if ($schemaBody === '') {
131
-			$schemaBody = "\t\t" . 'return null;';
132
-		}
133
-
134
-
135
-		$placeHolders = [
136
-			'<namespace>',
137
-			'<classname>',
138
-			'<schemabody>',
139
-		];
140
-		$replacements = [
141
-			$ms->getMigrationsNamespace(),
142
-			$className,
143
-			$schemaBody,
144
-		];
145
-		$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
146
-		$dir = $ms->getMigrationsDirectory();
147
-
148
-		$this->ensureMigrationDirExists($dir);
149
-		$path = $dir . '/' . $className . '.php';
150
-
151
-		if (file_put_contents($path, $code) === false) {
152
-			throw new RuntimeException('Failed to generate new migration step.');
153
-		}
154
-
155
-		return $path;
156
-	}
157
-
158
-	protected function ensureMigrationDirExists($directory) {
159
-		if (file_exists($directory) && is_dir($directory)) {
160
-			return;
161
-		}
162
-
163
-		if (file_exists($directory)) {
164
-			throw new \RuntimeException("Could not create folder \"$directory\"");
165
-		}
166
-
167
-		$this->ensureMigrationDirExists(dirname($directory));
168
-
169
-		if (!@mkdir($directory) && !is_dir($directory)) {
170
-			throw new \RuntimeException("Could not create folder \"$directory\"");
171
-		}
172
-	}
83
+    /** @var IDBConnection */
84
+    protected $connection;
85
+
86
+    /**
87
+     * @param IDBConnection $connection
88
+     */
89
+    public function __construct(IDBConnection $connection) {
90
+        $this->connection = $connection;
91
+
92
+        parent::__construct();
93
+    }
94
+
95
+    protected function configure() {
96
+        $this
97
+            ->setName('migrations:generate')
98
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
99
+            ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
100
+        ;
101
+
102
+        parent::configure();
103
+    }
104
+
105
+    public function execute(InputInterface $input, OutputInterface $output) {
106
+        $appName = $input->getArgument('app');
107
+        $version = $input->getArgument('version');
108
+
109
+        if (!preg_match('/^\d{1,16}$/',$version)) {
110
+            $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
111
+            return 1;
112
+        }
113
+
114
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
115
+
116
+        $date = date('YmdHis');
117
+        $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
118
+
119
+        $output->writeln("New migration class has been generated to <info>$path</info>");
120
+        return 0;
121
+    }
122
+
123
+    /**
124
+     * @param MigrationService $ms
125
+     * @param string $className
126
+     * @param string $schemaBody
127
+     * @return string
128
+     */
129
+    protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
130
+        if ($schemaBody === '') {
131
+            $schemaBody = "\t\t" . 'return null;';
132
+        }
133
+
134
+
135
+        $placeHolders = [
136
+            '<namespace>',
137
+            '<classname>',
138
+            '<schemabody>',
139
+        ];
140
+        $replacements = [
141
+            $ms->getMigrationsNamespace(),
142
+            $className,
143
+            $schemaBody,
144
+        ];
145
+        $code = str_replace($placeHolders, $replacements, self::$_templateSimple);
146
+        $dir = $ms->getMigrationsDirectory();
147
+
148
+        $this->ensureMigrationDirExists($dir);
149
+        $path = $dir . '/' . $className . '.php';
150
+
151
+        if (file_put_contents($path, $code) === false) {
152
+            throw new RuntimeException('Failed to generate new migration step.');
153
+        }
154
+
155
+        return $path;
156
+    }
157
+
158
+    protected function ensureMigrationDirExists($directory) {
159
+        if (file_exists($directory) && is_dir($directory)) {
160
+            return;
161
+        }
162
+
163
+        if (file_exists($directory)) {
164
+            throw new \RuntimeException("Could not create folder \"$directory\"");
165
+        }
166
+
167
+        $this->ensureMigrationDirExists(dirname($directory));
168
+
169
+        if (!@mkdir($directory) && !is_dir($directory)) {
170
+            throw new \RuntimeException("Could not create folder \"$directory\"");
171
+        }
172
+    }
173 173
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 		$appName = $input->getArgument('app');
107 107
 		$version = $input->getArgument('version');
108 108
 
109
-		if (!preg_match('/^\d{1,16}$/',$version)) {
109
+		if (!preg_match('/^\d{1,16}$/', $version)) {
110 110
 			$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
111 111
 			return 1;
112 112
 		}
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
115 115
 
116 116
 		$date = date('YmdHis');
117
-		$path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
117
+		$path = $this->generateMigration($ms, 'Version'.$version.'Date'.$date);
118 118
 
119 119
 		$output->writeln("New migration class has been generated to <info>$path</info>");
120 120
 		return 0;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
130 130
 		if ($schemaBody === '') {
131
-			$schemaBody = "\t\t" . 'return null;';
131
+			$schemaBody = "\t\t".'return null;';
132 132
 		}
133 133
 
134 134
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		$dir = $ms->getMigrationsDirectory();
147 147
 
148 148
 		$this->ensureMigrationDirExists($dir);
149
-		$path = $dir . '/' . $className . '.php';
149
+		$path = $dir.'/'.$className.'.php';
150 150
 
151 151
 		if (file_put_contents($path, $code) === false) {
152 152
 			throw new RuntimeException('Failed to generate new migration step.');
Please login to merge, or discard this patch.
lib/private/Setup.php 1 patch
Indentation   +482 added lines, -482 removed lines patch added patch discarded remove patch
@@ -48,486 +48,486 @@
 block discarded – undo
48 48
 use OCP\Security\ISecureRandom;
49 49
 
50 50
 class Setup {
51
-	/** @var SystemConfig */
52
-	protected $config;
53
-	/** @var IniGetWrapper */
54
-	protected $iniWrapper;
55
-	/** @var IL10N */
56
-	protected $l10n;
57
-	/** @var Defaults */
58
-	protected $defaults;
59
-	/** @var ILogger */
60
-	protected $logger;
61
-	/** @var ISecureRandom */
62
-	protected $random;
63
-
64
-	/**
65
-	 * @param SystemConfig $config
66
-	 * @param IniGetWrapper $iniWrapper
67
-	 * @param IL10N $l10n
68
-	 * @param Defaults $defaults
69
-	 * @param ILogger $logger
70
-	 * @param ISecureRandom $random
71
-	 */
72
-	public function __construct(SystemConfig $config,
73
-						 IniGetWrapper $iniWrapper,
74
-						 IL10N $l10n,
75
-						 Defaults $defaults,
76
-						 ILogger $logger,
77
-						 ISecureRandom $random
78
-		) {
79
-		$this->config = $config;
80
-		$this->iniWrapper = $iniWrapper;
81
-		$this->l10n = $l10n;
82
-		$this->defaults = $defaults;
83
-		$this->logger = $logger;
84
-		$this->random = $random;
85
-	}
86
-
87
-	static $dbSetupClasses = [
88
-		'mysql' => \OC\Setup\MySQL::class,
89
-		'pgsql' => \OC\Setup\PostgreSQL::class,
90
-		'oci'   => \OC\Setup\OCI::class,
91
-		'sqlite' => \OC\Setup\Sqlite::class,
92
-		'sqlite3' => \OC\Setup\Sqlite::class,
93
-	];
94
-
95
-	/**
96
-	 * Wrapper around the "class_exists" PHP function to be able to mock it
97
-	 * @param string $name
98
-	 * @return bool
99
-	 */
100
-	protected function class_exists($name) {
101
-		return class_exists($name);
102
-	}
103
-
104
-	/**
105
-	 * Wrapper around the "is_callable" PHP function to be able to mock it
106
-	 * @param string $name
107
-	 * @return bool
108
-	 */
109
-	protected function is_callable($name) {
110
-		return is_callable($name);
111
-	}
112
-
113
-	/**
114
-	 * Wrapper around \PDO::getAvailableDrivers
115
-	 *
116
-	 * @return array
117
-	 */
118
-	protected function getAvailableDbDriversForPdo() {
119
-		return \PDO::getAvailableDrivers();
120
-	}
121
-
122
-	/**
123
-	 * Get the available and supported databases of this instance
124
-	 *
125
-	 * @param bool $allowAllDatabases
126
-	 * @return array
127
-	 * @throws Exception
128
-	 */
129
-	public function getSupportedDatabases($allowAllDatabases = false) {
130
-		$availableDatabases = array(
131
-			'sqlite' =>  array(
132
-				'type' => 'pdo',
133
-				'call' => 'sqlite',
134
-				'name' => 'SQLite'
135
-			),
136
-			'mysql' => array(
137
-				'type' => 'pdo',
138
-				'call' => 'mysql',
139
-				'name' => 'MySQL/MariaDB'
140
-			),
141
-			'pgsql' => array(
142
-				'type' => 'pdo',
143
-				'call' => 'pgsql',
144
-				'name' => 'PostgreSQL'
145
-			),
146
-			'oci' => array(
147
-				'type' => 'function',
148
-				'call' => 'oci_connect',
149
-				'name' => 'Oracle'
150
-			)
151
-		);
152
-		if ($allowAllDatabases) {
153
-			$configuredDatabases = array_keys($availableDatabases);
154
-		} else {
155
-			$configuredDatabases = $this->config->getValue('supportedDatabases',
156
-				array('sqlite', 'mysql', 'pgsql'));
157
-		}
158
-		if(!is_array($configuredDatabases)) {
159
-			throw new Exception('Supported databases are not properly configured.');
160
-		}
161
-
162
-		$supportedDatabases = array();
163
-
164
-		foreach($configuredDatabases as $database) {
165
-			if(array_key_exists($database, $availableDatabases)) {
166
-				$working = false;
167
-				$type = $availableDatabases[$database]['type'];
168
-				$call = $availableDatabases[$database]['call'];
169
-
170
-				if ($type === 'function') {
171
-					$working = $this->is_callable($call);
172
-				} elseif($type === 'pdo') {
173
-					$working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
174
-				}
175
-				if($working) {
176
-					$supportedDatabases[$database] = $availableDatabases[$database]['name'];
177
-				}
178
-			}
179
-		}
180
-
181
-		return $supportedDatabases;
182
-	}
183
-
184
-	/**
185
-	 * Gathers system information like database type and does
186
-	 * a few system checks.
187
-	 *
188
-	 * @return array of system info, including an "errors" value
189
-	 * in case of errors/warnings
190
-	 */
191
-	public function getSystemInfo($allowAllDatabases = false) {
192
-		$databases = $this->getSupportedDatabases($allowAllDatabases);
193
-
194
-		$dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
195
-
196
-		$errors = array();
197
-
198
-		// Create data directory to test whether the .htaccess works
199
-		// Notice that this is not necessarily the same data directory as the one
200
-		// that will effectively be used.
201
-		if(!file_exists($dataDir)) {
202
-			@mkdir($dataDir);
203
-		}
204
-		$htAccessWorking = true;
205
-		if (is_dir($dataDir) && is_writable($dataDir)) {
206
-			// Protect data directory here, so we can test if the protection is working
207
-			\OC\Setup::protectDataDirectory();
208
-
209
-			try {
210
-				$util = new \OC_Util();
211
-				$htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig());
212
-			} catch (\OC\HintException $e) {
213
-				$errors[] = array(
214
-					'error' => $e->getMessage(),
215
-					'hint' => $e->getHint()
216
-				);
217
-				$htAccessWorking = false;
218
-			}
219
-		}
220
-
221
-		if (\OC_Util::runningOnMac()) {
222
-			$errors[] = array(
223
-				'error' => $this->l10n->t(
224
-					'Mac OS X is not supported and %s will not work properly on this platform. ' .
225
-					'Use it at your own risk! ',
226
-					$this->defaults->getName()
227
-				),
228
-				'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.')
229
-			);
230
-		}
231
-
232
-		if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
233
-			$errors[] = array(
234
-				'error' => $this->l10n->t(
235
-					'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
236
-					'This will lead to problems with files over 4 GB and is highly discouraged.',
237
-					$this->defaults->getName()
238
-				),
239
-				'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.')
240
-			);
241
-		}
242
-
243
-		return array(
244
-			'hasSQLite' => isset($databases['sqlite']),
245
-			'hasMySQL' => isset($databases['mysql']),
246
-			'hasPostgreSQL' => isset($databases['pgsql']),
247
-			'hasOracle' => isset($databases['oci']),
248
-			'databases' => $databases,
249
-			'directory' => $dataDir,
250
-			'htaccessWorking' => $htAccessWorking,
251
-			'errors' => $errors,
252
-		);
253
-	}
254
-
255
-	/**
256
-	 * @param $options
257
-	 * @return array
258
-	 */
259
-	public function install($options) {
260
-		$l = $this->l10n;
261
-
262
-		$error = array();
263
-		$dbType = $options['dbtype'];
264
-
265
-		if(empty($options['adminlogin'])) {
266
-			$error[] = $l->t('Set an admin username.');
267
-		}
268
-		if(empty($options['adminpass'])) {
269
-			$error[] = $l->t('Set an admin password.');
270
-		}
271
-		if(empty($options['directory'])) {
272
-			$options['directory'] = \OC::$SERVERROOT."/data";
273
-		}
274
-
275
-		if (!isset(self::$dbSetupClasses[$dbType])) {
276
-			$dbType = 'sqlite';
277
-		}
278
-
279
-		$username = htmlspecialchars_decode($options['adminlogin']);
280
-		$password = htmlspecialchars_decode($options['adminpass']);
281
-		$dataDir = htmlspecialchars_decode($options['directory']);
282
-
283
-		$class = self::$dbSetupClasses[$dbType];
284
-		/** @var \OC\Setup\AbstractDatabase $dbSetup */
285
-		$dbSetup = new $class($l, $this->config, $this->logger, $this->random);
286
-		$error = array_merge($error, $dbSetup->validate($options));
287
-
288
-		// validate the data directory
289
-		if (
290
-			(!is_dir($dataDir) and !mkdir($dataDir)) or
291
-			!is_writable($dataDir)
292
-		) {
293
-			$error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
294
-		}
295
-
296
-		if(count($error) != 0) {
297
-			return $error;
298
-		}
299
-
300
-		$request = \OC::$server->getRequest();
301
-
302
-		//no errors, good
303
-		if(isset($options['trusted_domains'])
304
-		    && is_array($options['trusted_domains'])) {
305
-			$trustedDomains = $options['trusted_domains'];
306
-		} else {
307
-			$trustedDomains = [$request->getInsecureServerHost()];
308
-		}
309
-
310
-		//use sqlite3 when available, otherwise sqlite2 will be used.
311
-		if($dbType=='sqlite' and class_exists('SQLite3')) {
312
-			$dbType='sqlite3';
313
-		}
314
-
315
-		//generate a random salt that is used to salt the local user passwords
316
-		$salt = $this->random->generate(30);
317
-		// generate a secret
318
-		$secret = $this->random->generate(48);
319
-
320
-		//write the config file
321
-		$this->config->setValues([
322
-			'passwordsalt'		=> $salt,
323
-			'secret'			=> $secret,
324
-			'trusted_domains'	=> $trustedDomains,
325
-			'datadirectory'		=> $dataDir,
326
-			'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT,
327
-			'dbtype'			=> $dbType,
328
-			'version'			=> implode('.', \OCP\Util::getVersion()),
329
-		]);
330
-
331
-		try {
332
-			$dbSetup->initialize($options);
333
-			$dbSetup->setupDatabase($username);
334
-			// apply necessary migrations
335
-			$dbSetup->runMigrations();
336
-		} catch (\OC\DatabaseSetupException $e) {
337
-			$error[] = array(
338
-				'error' => $e->getMessage(),
339
-				'hint' => $e->getHint()
340
-			);
341
-			return($error);
342
-		} catch (Exception $e) {
343
-			$error[] = array(
344
-				'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
345
-				'hint' => ''
346
-			);
347
-			return($error);
348
-		}
349
-
350
-		//create the user and group
351
-		$user =  null;
352
-		try {
353
-			$user = \OC::$server->getUserManager()->createUser($username, $password);
354
-			if (!$user) {
355
-				$error[] = "User <$username> could not be created.";
356
-			}
357
-		} catch(Exception $exception) {
358
-			$error[] = $exception->getMessage();
359
-		}
360
-
361
-		if(count($error) == 0) {
362
-			$config = \OC::$server->getConfig();
363
-			$config->setAppValue('core', 'installedat', microtime(true));
364
-			$config->setAppValue('core', 'lastupdatedat', microtime(true));
365
-			$config->setAppValue('core', 'vendor', $this->getVendor());
366
-
367
-			$group =\OC::$server->getGroupManager()->createGroup('admin');
368
-			$group->addUser($user);
369
-
370
-			// Install shipped apps and specified app bundles
371
-			Installer::installShippedApps();
372
-			$installer = new Installer(
373
-				\OC::$server->getAppFetcher(),
374
-				\OC::$server->getHTTPClientService(),
375
-				\OC::$server->getTempManager(),
376
-				\OC::$server->getLogger(),
377
-				\OC::$server->getConfig()
378
-			);
379
-			$bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
380
-			$defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
381
-			foreach($defaultInstallationBundles as $bundle) {
382
-				try {
383
-					$installer->installAppBundle($bundle);
384
-				} catch (Exception $e) {}
385
-			}
386
-
387
-			// create empty file in data dir, so we can later find
388
-			// out that this is indeed an ownCloud data directory
389
-			file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
390
-
391
-			// Update .htaccess files
392
-			Setup::updateHtaccess();
393
-			Setup::protectDataDirectory();
394
-
395
-			self::installBackgroundJobs();
396
-
397
-			//and we are done
398
-			$config->setSystemValue('installed', true);
399
-
400
-			// Create a session token for the newly created user
401
-			// The token provider requires a working db, so it's not injected on setup
402
-			/* @var $userSession User\Session */
403
-			$userSession = \OC::$server->getUserSession();
404
-			$defaultTokenProvider = \OC::$server->query('OC\Authentication\Token\DefaultTokenProvider');
405
-			$userSession->setTokenProvider($defaultTokenProvider);
406
-			$userSession->login($username, $password);
407
-			$userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password);
408
-		}
409
-
410
-		return $error;
411
-	}
412
-
413
-	public static function installBackgroundJobs() {
414
-		\OC::$server->getJobList()->add('\OC\Authentication\Token\DefaultTokenCleanupJob');
415
-	}
416
-
417
-	/**
418
-	 * @return string Absolute path to htaccess
419
-	 */
420
-	private function pathToHtaccess() {
421
-		return \OC::$SERVERROOT.'/.htaccess';
422
-	}
423
-
424
-	/**
425
-	 * Append the correct ErrorDocument path for Apache hosts
426
-	 * @return bool True when success, False otherwise
427
-	 */
428
-	public static function updateHtaccess() {
429
-		$config = \OC::$server->getSystemConfig();
430
-
431
-		// For CLI read the value from overwrite.cli.url
432
-		if(\OC::$CLI) {
433
-			$webRoot = $config->getValue('overwrite.cli.url', '');
434
-			if($webRoot === '') {
435
-				return false;
436
-			}
437
-			$webRoot = parse_url($webRoot, PHP_URL_PATH);
438
-			$webRoot = rtrim($webRoot, '/');
439
-		} else {
440
-			$webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
441
-		}
442
-
443
-		$setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
444
-			\OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
445
-			\OC::$server->getSecureRandom());
446
-
447
-		$htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
448
-		$content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
449
-		$htaccessContent = explode($content, $htaccessContent, 2)[0];
450
-
451
-		//custom 403 error page
452
-		$content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php";
453
-
454
-		//custom 404 error page
455
-		$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
456
-
457
-		// Add rewrite rules if the RewriteBase is configured
458
-		$rewriteBase = $config->getValue('htaccess.RewriteBase', '');
459
-		if($rewriteBase !== '') {
460
-			$content .= "\n<IfModule mod_rewrite.c>";
461
-			$content .= "\n  Options -MultiViews";
462
-			$content .= "\n  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
463
-			$content .= "\n  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
464
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$";
465
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$";
466
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$";
467
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/remote.php";
468
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/public.php";
469
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/cron.php";
470
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php";
471
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/status.php";
472
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php";
473
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php";
474
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/robots.txt";
475
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/updater/";
476
-			$content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
477
-			$content .= "\n  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
478
-			$content .= "\n  RewriteRule . index.php [PT,E=PATH_INFO:$1]";
479
-			$content .= "\n  RewriteBase " . $rewriteBase;
480
-			$content .= "\n  <IfModule mod_env.c>";
481
-			$content .= "\n    SetEnv front_controller_active true";
482
-			$content .= "\n    <IfModule mod_dir.c>";
483
-			$content .= "\n      DirectorySlash off";
484
-			$content .= "\n    </IfModule>";
485
-			$content .= "\n  </IfModule>";
486
-			$content .= "\n</IfModule>";
487
-		}
488
-
489
-		if ($content !== '') {
490
-			//suppress errors in case we don't have permissions for it
491
-			return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
492
-		}
493
-
494
-		return false;
495
-	}
496
-
497
-	public static function protectDataDirectory() {
498
-		//Require all denied
499
-		$now =  date('Y-m-d H:i:s');
500
-		$content = "# Generated by Nextcloud on $now\n";
501
-		$content.= "# line below if for Apache 2.4\n";
502
-		$content.= "<ifModule mod_authz_core.c>\n";
503
-		$content.= "Require all denied\n";
504
-		$content.= "</ifModule>\n\n";
505
-		$content.= "# line below if for Apache 2.2\n";
506
-		$content.= "<ifModule !mod_authz_core.c>\n";
507
-		$content.= "deny from all\n";
508
-		$content.= "Satisfy All\n";
509
-		$content.= "</ifModule>\n\n";
510
-		$content.= "# section for Apache 2.2 and 2.4\n";
511
-		$content.= "<ifModule mod_autoindex.c>\n";
512
-		$content.= "IndexIgnore *\n";
513
-		$content.= "</ifModule>\n";
514
-
515
-		$baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
516
-		file_put_contents($baseDir . '/.htaccess', $content);
517
-		file_put_contents($baseDir . '/index.html', '');
518
-	}
519
-
520
-	/**
521
-	 * Return vendor from which this version was published
522
-	 *
523
-	 * @return string Get the vendor
524
-	 *
525
-	 * Copy of \OC\Updater::getVendor()
526
-	 */
527
-	private function getVendor() {
528
-		// this should really be a JSON file
529
-		require \OC::$SERVERROOT . '/version.php';
530
-		/** @var string $vendor */
531
-		return (string) $vendor;
532
-	}
51
+    /** @var SystemConfig */
52
+    protected $config;
53
+    /** @var IniGetWrapper */
54
+    protected $iniWrapper;
55
+    /** @var IL10N */
56
+    protected $l10n;
57
+    /** @var Defaults */
58
+    protected $defaults;
59
+    /** @var ILogger */
60
+    protected $logger;
61
+    /** @var ISecureRandom */
62
+    protected $random;
63
+
64
+    /**
65
+     * @param SystemConfig $config
66
+     * @param IniGetWrapper $iniWrapper
67
+     * @param IL10N $l10n
68
+     * @param Defaults $defaults
69
+     * @param ILogger $logger
70
+     * @param ISecureRandom $random
71
+     */
72
+    public function __construct(SystemConfig $config,
73
+                            IniGetWrapper $iniWrapper,
74
+                            IL10N $l10n,
75
+                            Defaults $defaults,
76
+                            ILogger $logger,
77
+                            ISecureRandom $random
78
+        ) {
79
+        $this->config = $config;
80
+        $this->iniWrapper = $iniWrapper;
81
+        $this->l10n = $l10n;
82
+        $this->defaults = $defaults;
83
+        $this->logger = $logger;
84
+        $this->random = $random;
85
+    }
86
+
87
+    static $dbSetupClasses = [
88
+        'mysql' => \OC\Setup\MySQL::class,
89
+        'pgsql' => \OC\Setup\PostgreSQL::class,
90
+        'oci'   => \OC\Setup\OCI::class,
91
+        'sqlite' => \OC\Setup\Sqlite::class,
92
+        'sqlite3' => \OC\Setup\Sqlite::class,
93
+    ];
94
+
95
+    /**
96
+     * Wrapper around the "class_exists" PHP function to be able to mock it
97
+     * @param string $name
98
+     * @return bool
99
+     */
100
+    protected function class_exists($name) {
101
+        return class_exists($name);
102
+    }
103
+
104
+    /**
105
+     * Wrapper around the "is_callable" PHP function to be able to mock it
106
+     * @param string $name
107
+     * @return bool
108
+     */
109
+    protected function is_callable($name) {
110
+        return is_callable($name);
111
+    }
112
+
113
+    /**
114
+     * Wrapper around \PDO::getAvailableDrivers
115
+     *
116
+     * @return array
117
+     */
118
+    protected function getAvailableDbDriversForPdo() {
119
+        return \PDO::getAvailableDrivers();
120
+    }
121
+
122
+    /**
123
+     * Get the available and supported databases of this instance
124
+     *
125
+     * @param bool $allowAllDatabases
126
+     * @return array
127
+     * @throws Exception
128
+     */
129
+    public function getSupportedDatabases($allowAllDatabases = false) {
130
+        $availableDatabases = array(
131
+            'sqlite' =>  array(
132
+                'type' => 'pdo',
133
+                'call' => 'sqlite',
134
+                'name' => 'SQLite'
135
+            ),
136
+            'mysql' => array(
137
+                'type' => 'pdo',
138
+                'call' => 'mysql',
139
+                'name' => 'MySQL/MariaDB'
140
+            ),
141
+            'pgsql' => array(
142
+                'type' => 'pdo',
143
+                'call' => 'pgsql',
144
+                'name' => 'PostgreSQL'
145
+            ),
146
+            'oci' => array(
147
+                'type' => 'function',
148
+                'call' => 'oci_connect',
149
+                'name' => 'Oracle'
150
+            )
151
+        );
152
+        if ($allowAllDatabases) {
153
+            $configuredDatabases = array_keys($availableDatabases);
154
+        } else {
155
+            $configuredDatabases = $this->config->getValue('supportedDatabases',
156
+                array('sqlite', 'mysql', 'pgsql'));
157
+        }
158
+        if(!is_array($configuredDatabases)) {
159
+            throw new Exception('Supported databases are not properly configured.');
160
+        }
161
+
162
+        $supportedDatabases = array();
163
+
164
+        foreach($configuredDatabases as $database) {
165
+            if(array_key_exists($database, $availableDatabases)) {
166
+                $working = false;
167
+                $type = $availableDatabases[$database]['type'];
168
+                $call = $availableDatabases[$database]['call'];
169
+
170
+                if ($type === 'function') {
171
+                    $working = $this->is_callable($call);
172
+                } elseif($type === 'pdo') {
173
+                    $working = in_array($call, $this->getAvailableDbDriversForPdo(), TRUE);
174
+                }
175
+                if($working) {
176
+                    $supportedDatabases[$database] = $availableDatabases[$database]['name'];
177
+                }
178
+            }
179
+        }
180
+
181
+        return $supportedDatabases;
182
+    }
183
+
184
+    /**
185
+     * Gathers system information like database type and does
186
+     * a few system checks.
187
+     *
188
+     * @return array of system info, including an "errors" value
189
+     * in case of errors/warnings
190
+     */
191
+    public function getSystemInfo($allowAllDatabases = false) {
192
+        $databases = $this->getSupportedDatabases($allowAllDatabases);
193
+
194
+        $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
195
+
196
+        $errors = array();
197
+
198
+        // Create data directory to test whether the .htaccess works
199
+        // Notice that this is not necessarily the same data directory as the one
200
+        // that will effectively be used.
201
+        if(!file_exists($dataDir)) {
202
+            @mkdir($dataDir);
203
+        }
204
+        $htAccessWorking = true;
205
+        if (is_dir($dataDir) && is_writable($dataDir)) {
206
+            // Protect data directory here, so we can test if the protection is working
207
+            \OC\Setup::protectDataDirectory();
208
+
209
+            try {
210
+                $util = new \OC_Util();
211
+                $htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig());
212
+            } catch (\OC\HintException $e) {
213
+                $errors[] = array(
214
+                    'error' => $e->getMessage(),
215
+                    'hint' => $e->getHint()
216
+                );
217
+                $htAccessWorking = false;
218
+            }
219
+        }
220
+
221
+        if (\OC_Util::runningOnMac()) {
222
+            $errors[] = array(
223
+                'error' => $this->l10n->t(
224
+                    'Mac OS X is not supported and %s will not work properly on this platform. ' .
225
+                    'Use it at your own risk! ',
226
+                    $this->defaults->getName()
227
+                ),
228
+                'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.')
229
+            );
230
+        }
231
+
232
+        if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
233
+            $errors[] = array(
234
+                'error' => $this->l10n->t(
235
+                    'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
236
+                    'This will lead to problems with files over 4 GB and is highly discouraged.',
237
+                    $this->defaults->getName()
238
+                ),
239
+                'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.')
240
+            );
241
+        }
242
+
243
+        return array(
244
+            'hasSQLite' => isset($databases['sqlite']),
245
+            'hasMySQL' => isset($databases['mysql']),
246
+            'hasPostgreSQL' => isset($databases['pgsql']),
247
+            'hasOracle' => isset($databases['oci']),
248
+            'databases' => $databases,
249
+            'directory' => $dataDir,
250
+            'htaccessWorking' => $htAccessWorking,
251
+            'errors' => $errors,
252
+        );
253
+    }
254
+
255
+    /**
256
+     * @param $options
257
+     * @return array
258
+     */
259
+    public function install($options) {
260
+        $l = $this->l10n;
261
+
262
+        $error = array();
263
+        $dbType = $options['dbtype'];
264
+
265
+        if(empty($options['adminlogin'])) {
266
+            $error[] = $l->t('Set an admin username.');
267
+        }
268
+        if(empty($options['adminpass'])) {
269
+            $error[] = $l->t('Set an admin password.');
270
+        }
271
+        if(empty($options['directory'])) {
272
+            $options['directory'] = \OC::$SERVERROOT."/data";
273
+        }
274
+
275
+        if (!isset(self::$dbSetupClasses[$dbType])) {
276
+            $dbType = 'sqlite';
277
+        }
278
+
279
+        $username = htmlspecialchars_decode($options['adminlogin']);
280
+        $password = htmlspecialchars_decode($options['adminpass']);
281
+        $dataDir = htmlspecialchars_decode($options['directory']);
282
+
283
+        $class = self::$dbSetupClasses[$dbType];
284
+        /** @var \OC\Setup\AbstractDatabase $dbSetup */
285
+        $dbSetup = new $class($l, $this->config, $this->logger, $this->random);
286
+        $error = array_merge($error, $dbSetup->validate($options));
287
+
288
+        // validate the data directory
289
+        if (
290
+            (!is_dir($dataDir) and !mkdir($dataDir)) or
291
+            !is_writable($dataDir)
292
+        ) {
293
+            $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
294
+        }
295
+
296
+        if(count($error) != 0) {
297
+            return $error;
298
+        }
299
+
300
+        $request = \OC::$server->getRequest();
301
+
302
+        //no errors, good
303
+        if(isset($options['trusted_domains'])
304
+            && is_array($options['trusted_domains'])) {
305
+            $trustedDomains = $options['trusted_domains'];
306
+        } else {
307
+            $trustedDomains = [$request->getInsecureServerHost()];
308
+        }
309
+
310
+        //use sqlite3 when available, otherwise sqlite2 will be used.
311
+        if($dbType=='sqlite' and class_exists('SQLite3')) {
312
+            $dbType='sqlite3';
313
+        }
314
+
315
+        //generate a random salt that is used to salt the local user passwords
316
+        $salt = $this->random->generate(30);
317
+        // generate a secret
318
+        $secret = $this->random->generate(48);
319
+
320
+        //write the config file
321
+        $this->config->setValues([
322
+            'passwordsalt'		=> $salt,
323
+            'secret'			=> $secret,
324
+            'trusted_domains'	=> $trustedDomains,
325
+            'datadirectory'		=> $dataDir,
326
+            'overwrite.cli.url'	=> $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT,
327
+            'dbtype'			=> $dbType,
328
+            'version'			=> implode('.', \OCP\Util::getVersion()),
329
+        ]);
330
+
331
+        try {
332
+            $dbSetup->initialize($options);
333
+            $dbSetup->setupDatabase($username);
334
+            // apply necessary migrations
335
+            $dbSetup->runMigrations();
336
+        } catch (\OC\DatabaseSetupException $e) {
337
+            $error[] = array(
338
+                'error' => $e->getMessage(),
339
+                'hint' => $e->getHint()
340
+            );
341
+            return($error);
342
+        } catch (Exception $e) {
343
+            $error[] = array(
344
+                'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
345
+                'hint' => ''
346
+            );
347
+            return($error);
348
+        }
349
+
350
+        //create the user and group
351
+        $user =  null;
352
+        try {
353
+            $user = \OC::$server->getUserManager()->createUser($username, $password);
354
+            if (!$user) {
355
+                $error[] = "User <$username> could not be created.";
356
+            }
357
+        } catch(Exception $exception) {
358
+            $error[] = $exception->getMessage();
359
+        }
360
+
361
+        if(count($error) == 0) {
362
+            $config = \OC::$server->getConfig();
363
+            $config->setAppValue('core', 'installedat', microtime(true));
364
+            $config->setAppValue('core', 'lastupdatedat', microtime(true));
365
+            $config->setAppValue('core', 'vendor', $this->getVendor());
366
+
367
+            $group =\OC::$server->getGroupManager()->createGroup('admin');
368
+            $group->addUser($user);
369
+
370
+            // Install shipped apps and specified app bundles
371
+            Installer::installShippedApps();
372
+            $installer = new Installer(
373
+                \OC::$server->getAppFetcher(),
374
+                \OC::$server->getHTTPClientService(),
375
+                \OC::$server->getTempManager(),
376
+                \OC::$server->getLogger(),
377
+                \OC::$server->getConfig()
378
+            );
379
+            $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
380
+            $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
381
+            foreach($defaultInstallationBundles as $bundle) {
382
+                try {
383
+                    $installer->installAppBundle($bundle);
384
+                } catch (Exception $e) {}
385
+            }
386
+
387
+            // create empty file in data dir, so we can later find
388
+            // out that this is indeed an ownCloud data directory
389
+            file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
390
+
391
+            // Update .htaccess files
392
+            Setup::updateHtaccess();
393
+            Setup::protectDataDirectory();
394
+
395
+            self::installBackgroundJobs();
396
+
397
+            //and we are done
398
+            $config->setSystemValue('installed', true);
399
+
400
+            // Create a session token for the newly created user
401
+            // The token provider requires a working db, so it's not injected on setup
402
+            /* @var $userSession User\Session */
403
+            $userSession = \OC::$server->getUserSession();
404
+            $defaultTokenProvider = \OC::$server->query('OC\Authentication\Token\DefaultTokenProvider');
405
+            $userSession->setTokenProvider($defaultTokenProvider);
406
+            $userSession->login($username, $password);
407
+            $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password);
408
+        }
409
+
410
+        return $error;
411
+    }
412
+
413
+    public static function installBackgroundJobs() {
414
+        \OC::$server->getJobList()->add('\OC\Authentication\Token\DefaultTokenCleanupJob');
415
+    }
416
+
417
+    /**
418
+     * @return string Absolute path to htaccess
419
+     */
420
+    private function pathToHtaccess() {
421
+        return \OC::$SERVERROOT.'/.htaccess';
422
+    }
423
+
424
+    /**
425
+     * Append the correct ErrorDocument path for Apache hosts
426
+     * @return bool True when success, False otherwise
427
+     */
428
+    public static function updateHtaccess() {
429
+        $config = \OC::$server->getSystemConfig();
430
+
431
+        // For CLI read the value from overwrite.cli.url
432
+        if(\OC::$CLI) {
433
+            $webRoot = $config->getValue('overwrite.cli.url', '');
434
+            if($webRoot === '') {
435
+                return false;
436
+            }
437
+            $webRoot = parse_url($webRoot, PHP_URL_PATH);
438
+            $webRoot = rtrim($webRoot, '/');
439
+        } else {
440
+            $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
441
+        }
442
+
443
+        $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
444
+            \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
445
+            \OC::$server->getSecureRandom());
446
+
447
+        $htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
448
+        $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
449
+        $htaccessContent = explode($content, $htaccessContent, 2)[0];
450
+
451
+        //custom 403 error page
452
+        $content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php";
453
+
454
+        //custom 404 error page
455
+        $content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
456
+
457
+        // Add rewrite rules if the RewriteBase is configured
458
+        $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
459
+        if($rewriteBase !== '') {
460
+            $content .= "\n<IfModule mod_rewrite.c>";
461
+            $content .= "\n  Options -MultiViews";
462
+            $content .= "\n  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
463
+            $content .= "\n  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
464
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$";
465
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$";
466
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$";
467
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/remote.php";
468
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/public.php";
469
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/cron.php";
470
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php";
471
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/status.php";
472
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php";
473
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php";
474
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/robots.txt";
475
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/updater/";
476
+            $content .= "\n  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
477
+            $content .= "\n  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
478
+            $content .= "\n  RewriteRule . index.php [PT,E=PATH_INFO:$1]";
479
+            $content .= "\n  RewriteBase " . $rewriteBase;
480
+            $content .= "\n  <IfModule mod_env.c>";
481
+            $content .= "\n    SetEnv front_controller_active true";
482
+            $content .= "\n    <IfModule mod_dir.c>";
483
+            $content .= "\n      DirectorySlash off";
484
+            $content .= "\n    </IfModule>";
485
+            $content .= "\n  </IfModule>";
486
+            $content .= "\n</IfModule>";
487
+        }
488
+
489
+        if ($content !== '') {
490
+            //suppress errors in case we don't have permissions for it
491
+            return (bool) @file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
492
+        }
493
+
494
+        return false;
495
+    }
496
+
497
+    public static function protectDataDirectory() {
498
+        //Require all denied
499
+        $now =  date('Y-m-d H:i:s');
500
+        $content = "# Generated by Nextcloud on $now\n";
501
+        $content.= "# line below if for Apache 2.4\n";
502
+        $content.= "<ifModule mod_authz_core.c>\n";
503
+        $content.= "Require all denied\n";
504
+        $content.= "</ifModule>\n\n";
505
+        $content.= "# line below if for Apache 2.2\n";
506
+        $content.= "<ifModule !mod_authz_core.c>\n";
507
+        $content.= "deny from all\n";
508
+        $content.= "Satisfy All\n";
509
+        $content.= "</ifModule>\n\n";
510
+        $content.= "# section for Apache 2.2 and 2.4\n";
511
+        $content.= "<ifModule mod_autoindex.c>\n";
512
+        $content.= "IndexIgnore *\n";
513
+        $content.= "</ifModule>\n";
514
+
515
+        $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
516
+        file_put_contents($baseDir . '/.htaccess', $content);
517
+        file_put_contents($baseDir . '/index.html', '');
518
+    }
519
+
520
+    /**
521
+     * Return vendor from which this version was published
522
+     *
523
+     * @return string Get the vendor
524
+     *
525
+     * Copy of \OC\Updater::getVendor()
526
+     */
527
+    private function getVendor() {
528
+        // this should really be a JSON file
529
+        require \OC::$SERVERROOT . '/version.php';
530
+        /** @var string $vendor */
531
+        return (string) $vendor;
532
+    }
533 533
 }
Please login to merge, or discard this patch.
lib/private/Setup/OCI.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -31,233 +31,233 @@
 block discarded – undo
31 31
 namespace OC\Setup;
32 32
 
33 33
 class OCI extends AbstractDatabase {
34
-	public $dbprettyname = 'Oracle';
34
+    public $dbprettyname = 'Oracle';
35 35
 
36
-	protected $dbtablespace;
36
+    protected $dbtablespace;
37 37
 
38
-	public function initialize($config) {
39
-		parent::initialize($config);
40
-		if (array_key_exists('dbtablespace', $config)) {
41
-			$this->dbtablespace = $config['dbtablespace'];
42
-		} else {
43
-			$this->dbtablespace = 'USERS';
44
-		}
45
-		// allow empty hostname for oracle
46
-		$this->dbHost = $config['dbhost'];
38
+    public function initialize($config) {
39
+        parent::initialize($config);
40
+        if (array_key_exists('dbtablespace', $config)) {
41
+            $this->dbtablespace = $config['dbtablespace'];
42
+        } else {
43
+            $this->dbtablespace = 'USERS';
44
+        }
45
+        // allow empty hostname for oracle
46
+        $this->dbHost = $config['dbhost'];
47 47
 
48
-		$this->config->setValues([
49
-			'dbhost'		=> $this->dbHost,
50
-			'dbtablespace'	=> $this->dbtablespace,
51
-		]);
52
-	}
48
+        $this->config->setValues([
49
+            'dbhost'		=> $this->dbHost,
50
+            'dbtablespace'	=> $this->dbtablespace,
51
+        ]);
52
+    }
53 53
 
54
-	public function validate($config) {
55
-		$errors = array();
56
-		if(empty($config['dbuser']) && empty($config['dbname'])) {
57
-			$errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname));
58
-		} else if(empty($config['dbuser'])) {
59
-			$errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
60
-		} else if(empty($config['dbname'])) {
61
-			$errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
62
-		}
63
-		return $errors;
64
-	}
54
+    public function validate($config) {
55
+        $errors = array();
56
+        if(empty($config['dbuser']) && empty($config['dbname'])) {
57
+            $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname));
58
+        } else if(empty($config['dbuser'])) {
59
+            $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
60
+        } else if(empty($config['dbname'])) {
61
+            $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
62
+        }
63
+        return $errors;
64
+    }
65 65
 
66
-	public function setupDatabase($username) {
67
-		$e_host = addslashes($this->dbHost);
68
-		// casting to int to avoid malicious input
69
-		$e_port = (int)$this->dbPort;
70
-		$e_dbname = addslashes($this->dbName);
71
-		//check if the database user has admin right
72
-		if ($e_host == '') {
73
-			$easy_connect_string = $e_dbname; // use dbname as easy connect name
74
-		} else {
75
-			$easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname;
76
-		}
77
-		$this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']);
78
-		$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
79
-		if(!$connection) {
80
-			$errorMessage = $this->getLastError();
81
-			if ($errorMessage) {
82
-				throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'),
83
-				$errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
84
-							.' ORACLE_SID='.getenv('ORACLE_SID')
85
-							.' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
86
-							.' NLS_LANG='.getenv('NLS_LANG')
87
-							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
88
-			}
89
-			throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
90
-					'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
91
-							.' ORACLE_SID='.getenv('ORACLE_SID')
92
-							.' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
93
-							.' NLS_LANG='.getenv('NLS_LANG')
94
-							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
95
-		}
96
-		//check for roles creation rights in oracle
66
+    public function setupDatabase($username) {
67
+        $e_host = addslashes($this->dbHost);
68
+        // casting to int to avoid malicious input
69
+        $e_port = (int)$this->dbPort;
70
+        $e_dbname = addslashes($this->dbName);
71
+        //check if the database user has admin right
72
+        if ($e_host == '') {
73
+            $easy_connect_string = $e_dbname; // use dbname as easy connect name
74
+        } else {
75
+            $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname;
76
+        }
77
+        $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']);
78
+        $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
79
+        if(!$connection) {
80
+            $errorMessage = $this->getLastError();
81
+            if ($errorMessage) {
82
+                throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'),
83
+                $errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
84
+                            .' ORACLE_SID='.getenv('ORACLE_SID')
85
+                            .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
86
+                            .' NLS_LANG='.getenv('NLS_LANG')
87
+                            .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
88
+            }
89
+            throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
90
+                    'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
91
+                            .' ORACLE_SID='.getenv('ORACLE_SID')
92
+                            .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
93
+                            .' NLS_LANG='.getenv('NLS_LANG')
94
+                            .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
95
+        }
96
+        //check for roles creation rights in oracle
97 97
 
98
-		$query='SELECT count(*) FROM user_role_privs, role_sys_privs'
99
-			." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
100
-		$stmt = oci_parse($connection, $query);
101
-		if (!$stmt) {
102
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
103
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
104
-			$this->logger->warning($entry, ['app' => 'setup.oci']);
105
-		}
106
-		$result = oci_execute($stmt);
107
-		if($result) {
108
-			$row = oci_fetch_row($stmt);
98
+        $query='SELECT count(*) FROM user_role_privs, role_sys_privs'
99
+            ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
100
+        $stmt = oci_parse($connection, $query);
101
+        if (!$stmt) {
102
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
103
+            $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
104
+            $this->logger->warning($entry, ['app' => 'setup.oci']);
105
+        }
106
+        $result = oci_execute($stmt);
107
+        if($result) {
108
+            $row = oci_fetch_row($stmt);
109 109
 
110
-			if ($row[0] > 0) {
111
-				//use the admin login data for the new database user
110
+            if ($row[0] > 0) {
111
+                //use the admin login data for the new database user
112 112
 
113
-				//add prefix to the oracle user name to prevent collisions
114
-				$this->dbUser='oc_'.$username;
115
-				//create a new password so we don't need to store the admin config in the config file
116
-				$this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
113
+                //add prefix to the oracle user name to prevent collisions
114
+                $this->dbUser='oc_'.$username;
115
+                //create a new password so we don't need to store the admin config in the config file
116
+                $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
117 117
 
118
-				//oracle passwords are treated as identifiers:
119
-				//  must start with alphanumeric char
120
-				//  needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
121
-				$this->dbPassword=substr($this->dbPassword, 0, 30);
118
+                //oracle passwords are treated as identifiers:
119
+                //  must start with alphanumeric char
120
+                //  needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
121
+                $this->dbPassword=substr($this->dbPassword, 0, 30);
122 122
 
123
-				$this->createDBUser($connection);
124
-			}
125
-		}
123
+                $this->createDBUser($connection);
124
+            }
125
+        }
126 126
 
127
-		$this->config->setValues([
128
-			'dbuser'		=> $this->dbUser,
129
-			'dbname'		=> $this->dbName,
130
-			'dbpassword'	=> $this->dbPassword,
131
-		]);
127
+        $this->config->setValues([
128
+            'dbuser'		=> $this->dbUser,
129
+            'dbname'		=> $this->dbName,
130
+            'dbpassword'	=> $this->dbPassword,
131
+        ]);
132 132
 
133
-		//create the database not necessary, oracle implies user = schema
134
-		//$this->createDatabase($this->dbname, $this->dbuser, $connection);
133
+        //create the database not necessary, oracle implies user = schema
134
+        //$this->createDatabase($this->dbname, $this->dbuser, $connection);
135 135
 
136
-		//FIXME check tablespace exists: select * from user_tablespaces
136
+        //FIXME check tablespace exists: select * from user_tablespaces
137 137
 
138
-		// the connection to dbname=oracle is not needed anymore
139
-		oci_close($connection);
138
+        // the connection to dbname=oracle is not needed anymore
139
+        oci_close($connection);
140 140
 
141
-		// connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled
142
-		$this->dbUser = $this->config->getValue('dbuser');
143
-		//$this->dbname = \OC_Config::getValue('dbname');
144
-		$this->dbPassword = $this->config->getValue('dbpassword');
141
+        // connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled
142
+        $this->dbUser = $this->config->getValue('dbuser');
143
+        //$this->dbname = \OC_Config::getValue('dbname');
144
+        $this->dbPassword = $this->config->getValue('dbpassword');
145 145
 
146
-		$e_host = addslashes($this->dbHost);
147
-		$e_dbname = addslashes($this->dbName);
146
+        $e_host = addslashes($this->dbHost);
147
+        $e_dbname = addslashes($this->dbName);
148 148
 
149
-		if ($e_host == '') {
150
-			$easy_connect_string = $e_dbname; // use dbname as easy connect name
151
-		} else {
152
-			$easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname;
153
-		}
154
-		$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
155
-		if(!$connection) {
156
-			throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
157
-					$this->trans->t('You need to enter details of an existing account.'));
158
-		}
159
-		$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
160
-		$stmt = oci_parse($connection, $query);
161
-		$un = $this->tablePrefix.'users';
162
-		oci_bind_by_name($stmt, ':un', $un);
163
-		if (!$stmt) {
164
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
165
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
166
-			$this->logger->warning( $entry, ['app' => 'setup.oci']);
167
-		}
168
-		oci_execute($stmt);
169
-	}
149
+        if ($e_host == '') {
150
+            $easy_connect_string = $e_dbname; // use dbname as easy connect name
151
+        } else {
152
+            $easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname;
153
+        }
154
+        $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
155
+        if(!$connection) {
156
+            throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
157
+                    $this->trans->t('You need to enter details of an existing account.'));
158
+        }
159
+        $query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
160
+        $stmt = oci_parse($connection, $query);
161
+        $un = $this->tablePrefix.'users';
162
+        oci_bind_by_name($stmt, ':un', $un);
163
+        if (!$stmt) {
164
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
165
+            $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
166
+            $this->logger->warning( $entry, ['app' => 'setup.oci']);
167
+        }
168
+        oci_execute($stmt);
169
+    }
170 170
 
171
-	/**
172
-	 * @param resource $connection
173
-	 */
174
-	private function createDBUser($connection) {
175
-		$name = $this->dbUser;
176
-		$password = $this->dbPassword;
177
-		$query = "SELECT * FROM all_users WHERE USERNAME = :un";
178
-		$stmt = oci_parse($connection, $query);
179
-		if (!$stmt) {
180
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
181
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
182
-			$this->logger->warning($entry, ['app' => 'setup.oci']);
183
-		}
184
-		oci_bind_by_name($stmt, ':un', $name);
185
-		$result = oci_execute($stmt);
186
-		if(!$result) {
187
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
188
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
189
-			$this->logger->warning($entry, ['app' => 'setup.oci']);
190
-		}
171
+    /**
172
+     * @param resource $connection
173
+     */
174
+    private function createDBUser($connection) {
175
+        $name = $this->dbUser;
176
+        $password = $this->dbPassword;
177
+        $query = "SELECT * FROM all_users WHERE USERNAME = :un";
178
+        $stmt = oci_parse($connection, $query);
179
+        if (!$stmt) {
180
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
181
+            $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
182
+            $this->logger->warning($entry, ['app' => 'setup.oci']);
183
+        }
184
+        oci_bind_by_name($stmt, ':un', $name);
185
+        $result = oci_execute($stmt);
186
+        if(!$result) {
187
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
188
+            $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
189
+            $this->logger->warning($entry, ['app' => 'setup.oci']);
190
+        }
191 191
 
192
-		if(! oci_fetch_row($stmt)) {
193
-			//user does not exists let's create it :)
194
-			//password must start with alphabetic character in oracle
195
-			$query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace;
196
-			$stmt = oci_parse($connection, $query);
197
-			if (!$stmt) {
198
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
199
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
200
-				$this->logger->warning($entry, ['app' => 'setup.oci']);
192
+        if(! oci_fetch_row($stmt)) {
193
+            //user does not exists let's create it :)
194
+            //password must start with alphabetic character in oracle
195
+            $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace;
196
+            $stmt = oci_parse($connection, $query);
197
+            if (!$stmt) {
198
+                $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
199
+                $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
200
+                $this->logger->warning($entry, ['app' => 'setup.oci']);
201 201
 
202
-			}
203
-			//oci_bind_by_name($stmt, ':un', $name);
204
-			$result = oci_execute($stmt);
205
-			if(!$result) {
206
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
207
-				$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
208
-					array($query, $name, $password)) . '<br />';
209
-				$this->logger->warning($entry, ['app' => 'setup.oci']);
202
+            }
203
+            //oci_bind_by_name($stmt, ':un', $name);
204
+            $result = oci_execute($stmt);
205
+            if(!$result) {
206
+                $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
207
+                $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
208
+                    array($query, $name, $password)) . '<br />';
209
+                $this->logger->warning($entry, ['app' => 'setup.oci']);
210 210
 
211
-			}
212
-		} else { // change password of the existing role
213
-			$query = "ALTER USER :un IDENTIFIED BY :pw";
214
-			$stmt = oci_parse($connection, $query);
215
-			if (!$stmt) {
216
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
217
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
218
-				$this->logger->warning($entry, ['app' => 'setup.oci']);
219
-			}
220
-			oci_bind_by_name($stmt, ':un', $name);
221
-			oci_bind_by_name($stmt, ':pw', $password);
222
-			$result = oci_execute($stmt);
223
-			if(!$result) {
224
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
225
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
226
-				$this->logger->warning($entry, ['app' => 'setup.oci']);
227
-			}
228
-		}
229
-		// grant necessary roles
230
-		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
231
-		$stmt = oci_parse($connection, $query);
232
-		if (!$stmt) {
233
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
234
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
235
-			$this->logger->warning($entry, ['app' => 'setup.oci']);
236
-		}
237
-		$result = oci_execute($stmt);
238
-		if(!$result) {
239
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
240
-			$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
241
-				array($query, $name, $password)) . '<br />';
242
-			$this->logger->warning($entry, ['app' => 'setup.oci']);
243
-		}
244
-	}
211
+            }
212
+        } else { // change password of the existing role
213
+            $query = "ALTER USER :un IDENTIFIED BY :pw";
214
+            $stmt = oci_parse($connection, $query);
215
+            if (!$stmt) {
216
+                $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
217
+                $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
218
+                $this->logger->warning($entry, ['app' => 'setup.oci']);
219
+            }
220
+            oci_bind_by_name($stmt, ':un', $name);
221
+            oci_bind_by_name($stmt, ':pw', $password);
222
+            $result = oci_execute($stmt);
223
+            if(!$result) {
224
+                $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
225
+                $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
226
+                $this->logger->warning($entry, ['app' => 'setup.oci']);
227
+            }
228
+        }
229
+        // grant necessary roles
230
+        $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
231
+        $stmt = oci_parse($connection, $query);
232
+        if (!$stmt) {
233
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
234
+            $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
235
+            $this->logger->warning($entry, ['app' => 'setup.oci']);
236
+        }
237
+        $result = oci_execute($stmt);
238
+        if(!$result) {
239
+            $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
240
+            $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
241
+                array($query, $name, $password)) . '<br />';
242
+            $this->logger->warning($entry, ['app' => 'setup.oci']);
243
+        }
244
+    }
245 245
 
246
-	/**
247
-	 * @param resource $connection
248
-	 * @return string
249
-	 */
250
-	protected function getLastError($connection = null) {
251
-		if ($connection) {
252
-			$error = oci_error($connection);
253
-		} else {
254
-			$error = oci_error();
255
-		}
256
-		foreach (array('message', 'code') as $key) {
257
-			if (isset($error[$key])) {
258
-				return $error[$key];
259
-			}
260
-		}
261
-		return '';
262
-	}
246
+    /**
247
+     * @param resource $connection
248
+     * @return string
249
+     */
250
+    protected function getLastError($connection = null) {
251
+        if ($connection) {
252
+            $error = oci_error($connection);
253
+        } else {
254
+            $error = oci_error();
255
+        }
256
+        foreach (array('message', 'code') as $key) {
257
+            if (isset($error[$key])) {
258
+                return $error[$key];
259
+            }
260
+        }
261
+        return '';
262
+    }
263 263
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 
54 54
 	public function validate($config) {
55 55
 		$errors = array();
56
-		if(empty($config['dbuser']) && empty($config['dbname'])) {
56
+		if (empty($config['dbuser']) && empty($config['dbname'])) {
57 57
 			$errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname));
58
-		} else if(empty($config['dbuser'])) {
58
+		} else if (empty($config['dbuser'])) {
59 59
 			$errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
60
-		} else if(empty($config['dbname'])) {
60
+		} else if (empty($config['dbname'])) {
61 61
 			$errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
62 62
 		}
63 63
 		return $errors;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	public function setupDatabase($username) {
67 67
 		$e_host = addslashes($this->dbHost);
68 68
 		// casting to int to avoid malicious input
69
-		$e_port = (int)$this->dbPort;
69
+		$e_port = (int) $this->dbPort;
70 70
 		$e_dbname = addslashes($this->dbName);
71 71
 		//check if the database user has admin right
72 72
 		if ($e_host == '') {
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 		} else {
75 75
 			$easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname;
76 76
 		}
77
-		$this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']);
77
+		$this->logger->debug('connect string: '.$easy_connect_string, ['app' => 'setup.oci']);
78 78
 		$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
79
-		if(!$connection) {
79
+		if (!$connection) {
80 80
 			$errorMessage = $this->getLastError();
81 81
 			if ($errorMessage) {
82 82
 				throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'),
@@ -84,41 +84,41 @@  discard block
 block discarded – undo
84 84
 							.' ORACLE_SID='.getenv('ORACLE_SID')
85 85
 							.' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
86 86
 							.' NLS_LANG='.getenv('NLS_LANG')
87
-							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
87
+							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora') ? '' : 'not ').'readable');
88 88
 			}
89 89
 			throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
90 90
 					'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
91 91
 							.' ORACLE_SID='.getenv('ORACLE_SID')
92 92
 							.' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH')
93 93
 							.' NLS_LANG='.getenv('NLS_LANG')
94
-							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable');
94
+							.' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora') ? '' : 'not ').'readable');
95 95
 		}
96 96
 		//check for roles creation rights in oracle
97 97
 
98
-		$query='SELECT count(*) FROM user_role_privs, role_sys_privs'
98
+		$query = 'SELECT count(*) FROM user_role_privs, role_sys_privs'
99 99
 			." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
100 100
 		$stmt = oci_parse($connection, $query);
101 101
 		if (!$stmt) {
102
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
103
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
102
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
103
+			$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
104 104
 			$this->logger->warning($entry, ['app' => 'setup.oci']);
105 105
 		}
106 106
 		$result = oci_execute($stmt);
107
-		if($result) {
107
+		if ($result) {
108 108
 			$row = oci_fetch_row($stmt);
109 109
 
110 110
 			if ($row[0] > 0) {
111 111
 				//use the admin login data for the new database user
112 112
 
113 113
 				//add prefix to the oracle user name to prevent collisions
114
-				$this->dbUser='oc_'.$username;
114
+				$this->dbUser = 'oc_'.$username;
115 115
 				//create a new password so we don't need to store the admin config in the config file
116 116
 				$this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
117 117
 
118 118
 				//oracle passwords are treated as identifiers:
119 119
 				//  must start with alphanumeric char
120 120
 				//  needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
121
-				$this->dbPassword=substr($this->dbPassword, 0, 30);
121
+				$this->dbPassword = substr($this->dbPassword, 0, 30);
122 122
 
123 123
 				$this->createDBUser($connection);
124 124
 			}
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
 		if ($e_host == '') {
150 150
 			$easy_connect_string = $e_dbname; // use dbname as easy connect name
151 151
 		} else {
152
-			$easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname;
152
+			$easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname;
153 153
 		}
154 154
 		$connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string);
155
-		if(!$connection) {
155
+		if (!$connection) {
156 156
 			throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'),
157 157
 					$this->trans->t('You need to enter details of an existing account.'));
158 158
 		}
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 		$un = $this->tablePrefix.'users';
162 162
 		oci_bind_by_name($stmt, ':un', $un);
163 163
 		if (!$stmt) {
164
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
165
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
166
-			$this->logger->warning( $entry, ['app' => 'setup.oci']);
164
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
165
+			$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
166
+			$this->logger->warning($entry, ['app' => 'setup.oci']);
167 167
 		}
168 168
 		oci_execute($stmt);
169 169
 	}
@@ -177,35 +177,35 @@  discard block
 block discarded – undo
177 177
 		$query = "SELECT * FROM all_users WHERE USERNAME = :un";
178 178
 		$stmt = oci_parse($connection, $query);
179 179
 		if (!$stmt) {
180
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
181
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
180
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
181
+			$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
182 182
 			$this->logger->warning($entry, ['app' => 'setup.oci']);
183 183
 		}
184 184
 		oci_bind_by_name($stmt, ':un', $name);
185 185
 		$result = oci_execute($stmt);
186
-		if(!$result) {
187
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
188
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
186
+		if (!$result) {
187
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
188
+			$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
189 189
 			$this->logger->warning($entry, ['app' => 'setup.oci']);
190 190
 		}
191 191
 
192
-		if(! oci_fetch_row($stmt)) {
192
+		if (!oci_fetch_row($stmt)) {
193 193
 			//user does not exists let's create it :)
194 194
 			//password must start with alphabetic character in oracle
195 195
 			$query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace;
196 196
 			$stmt = oci_parse($connection, $query);
197 197
 			if (!$stmt) {
198
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
199
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
198
+				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
199
+				$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
200 200
 				$this->logger->warning($entry, ['app' => 'setup.oci']);
201 201
 
202 202
 			}
203 203
 			//oci_bind_by_name($stmt, ':un', $name);
204 204
 			$result = oci_execute($stmt);
205
-			if(!$result) {
206
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
205
+			if (!$result) {
206
+				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
207 207
 				$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
208
-					array($query, $name, $password)) . '<br />';
208
+					array($query, $name, $password)).'<br />';
209 209
 				$this->logger->warning($entry, ['app' => 'setup.oci']);
210 210
 
211 211
 			}
@@ -213,16 +213,16 @@  discard block
 block discarded – undo
213 213
 			$query = "ALTER USER :un IDENTIFIED BY :pw";
214 214
 			$stmt = oci_parse($connection, $query);
215 215
 			if (!$stmt) {
216
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
217
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
216
+				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
217
+				$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
218 218
 				$this->logger->warning($entry, ['app' => 'setup.oci']);
219 219
 			}
220 220
 			oci_bind_by_name($stmt, ':un', $name);
221 221
 			oci_bind_by_name($stmt, ':pw', $password);
222 222
 			$result = oci_execute($stmt);
223
-			if(!$result) {
224
-				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
225
-				$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
223
+			if (!$result) {
224
+				$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
225
+				$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
226 226
 				$this->logger->warning($entry, ['app' => 'setup.oci']);
227 227
 			}
228 228
 		}
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
 		$query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name;
231 231
 		$stmt = oci_parse($connection, $query);
232 232
 		if (!$stmt) {
233
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
234
-			$entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />';
233
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
234
+			$entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />';
235 235
 			$this->logger->warning($entry, ['app' => 'setup.oci']);
236 236
 		}
237 237
 		$result = oci_execute($stmt);
238
-		if(!$result) {
239
-			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />';
238
+		if (!$result) {
239
+			$entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />';
240 240
 			$entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s',
241
-				array($query, $name, $password)) . '<br />';
241
+				array($query, $name, $password)).'<br />';
242 242
 			$this->logger->warning($entry, ['app' => 'setup.oci']);
243 243
 		}
244 244
 	}
Please login to merge, or discard this patch.
lib/private/Setup/Sqlite.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,23 +23,23 @@
 block discarded – undo
23 23
 namespace OC\Setup;
24 24
 
25 25
 class Sqlite extends AbstractDatabase {
26
-	public $dbprettyname = 'Sqlite';
26
+    public $dbprettyname = 'Sqlite';
27 27
 
28
-	public function validate($config) {
29
-		return array();
30
-	}
28
+    public function validate($config) {
29
+        return array();
30
+    }
31 31
 
32
-	public function initialize($config) {
33
-	}
32
+    public function initialize($config) {
33
+    }
34 34
 
35
-	public function setupDatabase($username) {
36
-		$datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
35
+    public function setupDatabase($username) {
36
+        $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
37 37
 
38
-		//delete the old sqlite database first, might cause infinte loops otherwise
39
-		if(file_exists("$datadir/owncloud.db")) {
40
-			unlink("$datadir/owncloud.db");
41
-		}
42
-		//in case of sqlite, we can always fill the database
43
-		error_log("creating sqlite db");
44
-	}
38
+        //delete the old sqlite database first, might cause infinte loops otherwise
39
+        if(file_exists("$datadir/owncloud.db")) {
40
+            unlink("$datadir/owncloud.db");
41
+        }
42
+        //in case of sqlite, we can always fill the database
43
+        error_log("creating sqlite db");
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/private/Setup/MySQL.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -31,139 +31,139 @@
 block discarded – undo
31 31
 use OCP\IDBConnection;
32 32
 
33 33
 class MySQL extends AbstractDatabase {
34
-	public $dbprettyname = 'MySQL/MariaDB';
35
-
36
-	public function setupDatabase($username) {
37
-		//check if the database user has admin right
38
-		$connection = $this->connect(['dbname' => null]);
39
-
40
-		// detect mb4
41
-		$tools = new MySqlTools();
42
-		if ($tools->supports4ByteCharset($connection)) {
43
-			$this->config->setValue('mysql.utf8mb4', true);
44
-			$connection = $this->connect(['dbname' => null]);
45
-		}
46
-
47
-		$this->createSpecificUser($username, $connection);
48
-
49
-		//create the database
50
-		$this->createDatabase($connection);
51
-
52
-		//fill the database if needed
53
-		$query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
54
-		$connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
55
-	}
56
-
57
-	/**
58
-	 * @param \OC\DB\Connection $connection
59
-	 */
60
-	private function createDatabase($connection) {
61
-		try{
62
-			$name = $this->dbName;
63
-			$user = $this->dbUser;
64
-			//we can't use OC_DB functions here because we need to connect as the administrative user.
65
-			$characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
66
-			$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
67
-			$connection->executeUpdate($query);
68
-		} catch (\Exception $ex) {
69
-			$this->logger->error('Database creation failed: {error}', [
70
-				'app' => 'mysql.setup',
71
-				'error' => $ex->getMessage()
72
-			]);
73
-			return;
74
-		}
75
-
76
-		try {
77
-			//this query will fail if there aren't the right permissions, ignore the error
78
-			$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
79
-			$connection->executeUpdate($query);
80
-		} catch (\Exception $ex) {
81
-			$this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges: {error}', [
82
-				'app' => 'mysql.setup',
83
-				'error' => $ex->getMessage()
84
-			]);
85
-		}
86
-	}
87
-
88
-	/**
89
-	 * @param IDBConnection $connection
90
-	 * @throws \OC\DatabaseSetupException
91
-	 */
92
-	private function createDBUser($connection) {
93
-		try{
94
-			$name = $this->dbUser;
95
-			$password = $this->dbPassword;
96
-			// we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
97
-			// the anonymous user would take precedence when there is one.
98
-			$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
99
-			$connection->executeUpdate($query);
100
-			$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
101
-			$connection->executeUpdate($query);
102
-		}
103
-		catch (\Exception $ex){
104
-			$this->logger->error('Database User creation failed: {error}', [
34
+    public $dbprettyname = 'MySQL/MariaDB';
35
+
36
+    public function setupDatabase($username) {
37
+        //check if the database user has admin right
38
+        $connection = $this->connect(['dbname' => null]);
39
+
40
+        // detect mb4
41
+        $tools = new MySqlTools();
42
+        if ($tools->supports4ByteCharset($connection)) {
43
+            $this->config->setValue('mysql.utf8mb4', true);
44
+            $connection = $this->connect(['dbname' => null]);
45
+        }
46
+
47
+        $this->createSpecificUser($username, $connection);
48
+
49
+        //create the database
50
+        $this->createDatabase($connection);
51
+
52
+        //fill the database if needed
53
+        $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
54
+        $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
55
+    }
56
+
57
+    /**
58
+     * @param \OC\DB\Connection $connection
59
+     */
60
+    private function createDatabase($connection) {
61
+        try{
62
+            $name = $this->dbName;
63
+            $user = $this->dbUser;
64
+            //we can't use OC_DB functions here because we need to connect as the administrative user.
65
+            $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8';
66
+            $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
67
+            $connection->executeUpdate($query);
68
+        } catch (\Exception $ex) {
69
+            $this->logger->error('Database creation failed: {error}', [
70
+                'app' => 'mysql.setup',
71
+                'error' => $ex->getMessage()
72
+            ]);
73
+            return;
74
+        }
75
+
76
+        try {
77
+            //this query will fail if there aren't the right permissions, ignore the error
78
+            $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
79
+            $connection->executeUpdate($query);
80
+        } catch (\Exception $ex) {
81
+            $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges: {error}', [
82
+                'app' => 'mysql.setup',
83
+                'error' => $ex->getMessage()
84
+            ]);
85
+        }
86
+    }
87
+
88
+    /**
89
+     * @param IDBConnection $connection
90
+     * @throws \OC\DatabaseSetupException
91
+     */
92
+    private function createDBUser($connection) {
93
+        try{
94
+            $name = $this->dbUser;
95
+            $password = $this->dbPassword;
96
+            // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
97
+            // the anonymous user would take precedence when there is one.
98
+            $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
99
+            $connection->executeUpdate($query);
100
+            $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
101
+            $connection->executeUpdate($query);
102
+        }
103
+        catch (\Exception $ex){
104
+            $this->logger->error('Database User creation failed: {error}', [
105 105
                                 'app' => 'mysql.setup',
106 106
                                 'error' => $ex->getMessage()
107 107
                         ]);
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * @param $username
113
-	 * @param IDBConnection $connection
114
-	 * @return array
115
-	 */
116
-	private function createSpecificUser($username, $connection) {
117
-		try {
118
-			//user already specified in config
119
-			$oldUser = $this->config->getValue('dbuser', false);
120
-
121
-			//we don't have a dbuser specified in config
122
-			if ($this->dbUser !== $oldUser) {
123
-				//add prefix to the admin username to prevent collisions
124
-				$adminUser = substr('oc_' . $username, 0, 16);
125
-
126
-				$i = 1;
127
-				while (true) {
128
-					//this should be enough to check for admin rights in mysql
129
-					$query = 'SELECT user FROM mysql.user WHERE user=?';
130
-					$result = $connection->executeQuery($query, [$adminUser]);
131
-
132
-					//current dbuser has admin rights
133
-					if ($result) {
134
-						$data = $result->fetchAll();
135
-						//new dbuser does not exist
136
-						if (count($data) === 0) {
137
-							//use the admin login data for the new database user
138
-							$this->dbUser = $adminUser;
139
-
140
-							//create a random password so we don't need to store the admin password in the config file
141
-							$this->dbPassword =  $this->random->generate(30);
142
-
143
-							$this->createDBUser($connection);
144
-
145
-							break;
146
-						} else {
147
-							//repeat with different username
148
-							$length = strlen((string)$i);
149
-							$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
150
-							$i++;
151
-						}
152
-					} else {
153
-						break;
154
-					}
155
-				};
156
-			}
157
-		} catch (\Exception $ex) {
158
-			$this->logger->info('Can not create a new MySQL user, will continue with the provided user: {error}', [
159
-				'app' => 'mysql.setup',
160
-				'error' => $ex->getMessage()
161
-			]);
162
-		}
163
-
164
-		$this->config->setValues([
165
-			'dbuser' => $this->dbUser,
166
-			'dbpassword' => $this->dbPassword,
167
-		]);
168
-	}
108
+        }
109
+    }
110
+
111
+    /**
112
+     * @param $username
113
+     * @param IDBConnection $connection
114
+     * @return array
115
+     */
116
+    private function createSpecificUser($username, $connection) {
117
+        try {
118
+            //user already specified in config
119
+            $oldUser = $this->config->getValue('dbuser', false);
120
+
121
+            //we don't have a dbuser specified in config
122
+            if ($this->dbUser !== $oldUser) {
123
+                //add prefix to the admin username to prevent collisions
124
+                $adminUser = substr('oc_' . $username, 0, 16);
125
+
126
+                $i = 1;
127
+                while (true) {
128
+                    //this should be enough to check for admin rights in mysql
129
+                    $query = 'SELECT user FROM mysql.user WHERE user=?';
130
+                    $result = $connection->executeQuery($query, [$adminUser]);
131
+
132
+                    //current dbuser has admin rights
133
+                    if ($result) {
134
+                        $data = $result->fetchAll();
135
+                        //new dbuser does not exist
136
+                        if (count($data) === 0) {
137
+                            //use the admin login data for the new database user
138
+                            $this->dbUser = $adminUser;
139
+
140
+                            //create a random password so we don't need to store the admin password in the config file
141
+                            $this->dbPassword =  $this->random->generate(30);
142
+
143
+                            $this->createDBUser($connection);
144
+
145
+                            break;
146
+                        } else {
147
+                            //repeat with different username
148
+                            $length = strlen((string)$i);
149
+                            $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
150
+                            $i++;
151
+                        }
152
+                    } else {
153
+                        break;
154
+                    }
155
+                };
156
+            }
157
+        } catch (\Exception $ex) {
158
+            $this->logger->info('Can not create a new MySQL user, will continue with the provided user: {error}', [
159
+                'app' => 'mysql.setup',
160
+                'error' => $ex->getMessage()
161
+            ]);
162
+        }
163
+
164
+        $this->config->setValues([
165
+            'dbuser' => $this->dbUser,
166
+            'dbpassword' => $this->dbPassword,
167
+        ]);
168
+    }
169 169
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		$this->createDatabase($connection);
51 51
 
52 52
 		//fill the database if needed
53
-		$query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
53
+		$query = 'select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
54 54
 		$connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
55 55
 	}
56 56
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @param \OC\DB\Connection $connection
59 59
 	 */
60 60
 	private function createDatabase($connection) {
61
-		try{
61
+		try {
62 62
 			$name = $this->dbName;
63 63
 			$user = $this->dbUser;
64 64
 			//we can't use OC_DB functions here because we need to connect as the administrative user.
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
 		try {
77 77
 			//this query will fail if there aren't the right permissions, ignore the error
78
-			$query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
78
+			$query = "GRANT ALL PRIVILEGES ON `$name` . * TO '$user'";
79 79
 			$connection->executeUpdate($query);
80 80
 		} catch (\Exception $ex) {
81 81
 			$this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges: {error}', [
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @throws \OC\DatabaseSetupException
91 91
 	 */
92 92
 	private function createDBUser($connection) {
93
-		try{
93
+		try {
94 94
 			$name = $this->dbUser;
95 95
 			$password = $this->dbPassword;
96 96
 			// we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
101 101
 			$connection->executeUpdate($query);
102 102
 		}
103
-		catch (\Exception $ex){
103
+		catch (\Exception $ex) {
104 104
 			$this->logger->error('Database User creation failed: {error}', [
105 105
                                 'app' => 'mysql.setup',
106 106
                                 'error' => $ex->getMessage()
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			//we don't have a dbuser specified in config
122 122
 			if ($this->dbUser !== $oldUser) {
123 123
 				//add prefix to the admin username to prevent collisions
124
-				$adminUser = substr('oc_' . $username, 0, 16);
124
+				$adminUser = substr('oc_'.$username, 0, 16);
125 125
 
126 126
 				$i = 1;
127 127
 				while (true) {
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 							$this->dbUser = $adminUser;
139 139
 
140 140
 							//create a random password so we don't need to store the admin password in the config file
141
-							$this->dbPassword =  $this->random->generate(30);
141
+							$this->dbPassword = $this->random->generate(30);
142 142
 
143 143
 							$this->createDBUser($connection);
144 144
 
145 145
 							break;
146 146
 						} else {
147 147
 							//repeat with different username
148
-							$length = strlen((string)$i);
149
-							$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
148
+							$length = strlen((string) $i);
149
+							$adminUser = substr('oc_'.$username, 0, 16 - $length).$i;
150 150
 							$i++;
151 151
 						}
152 152
 					} else {
Please login to merge, or discard this patch.
lib/private/Setup/AbstractDatabase.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -35,118 +35,118 @@
 block discarded – undo
35 35
 
36 36
 abstract class AbstractDatabase {
37 37
 
38
-	/** @var IL10N */
39
-	protected $trans;
40
-	/** @var string */
41
-	protected $dbUser;
42
-	/** @var string */
43
-	protected $dbPassword;
44
-	/** @var string */
45
-	protected $dbName;
46
-	/** @var string */
47
-	protected $dbHost;
48
-	/** @var string */
49
-	protected $dbPort;
50
-	/** @var string */
51
-	protected $tablePrefix;
52
-	/** @var SystemConfig */
53
-	protected $config;
54
-	/** @var ILogger */
55
-	protected $logger;
56
-	/** @var ISecureRandom */
57
-	protected $random;
38
+    /** @var IL10N */
39
+    protected $trans;
40
+    /** @var string */
41
+    protected $dbUser;
42
+    /** @var string */
43
+    protected $dbPassword;
44
+    /** @var string */
45
+    protected $dbName;
46
+    /** @var string */
47
+    protected $dbHost;
48
+    /** @var string */
49
+    protected $dbPort;
50
+    /** @var string */
51
+    protected $tablePrefix;
52
+    /** @var SystemConfig */
53
+    protected $config;
54
+    /** @var ILogger */
55
+    protected $logger;
56
+    /** @var ISecureRandom */
57
+    protected $random;
58 58
 
59
-	public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) {
60
-		$this->trans = $trans;
61
-		$this->config = $config;
62
-		$this->logger = $logger;
63
-		$this->random = $random;
64
-	}
59
+    public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) {
60
+        $this->trans = $trans;
61
+        $this->config = $config;
62
+        $this->logger = $logger;
63
+        $this->random = $random;
64
+    }
65 65
 
66
-	public function validate($config) {
67
-		$errors = array();
68
-		if(empty($config['dbuser']) && empty($config['dbname'])) {
69
-			$errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname));
70
-		} else if(empty($config['dbuser'])) {
71
-			$errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
72
-		} else if(empty($config['dbname'])) {
73
-			$errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
74
-		}
75
-		if(substr_count($config['dbname'], '.') >= 1) {
76
-			$errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname));
77
-		}
78
-		return $errors;
79
-	}
66
+    public function validate($config) {
67
+        $errors = array();
68
+        if(empty($config['dbuser']) && empty($config['dbname'])) {
69
+            $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname));
70
+        } else if(empty($config['dbuser'])) {
71
+            $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname));
72
+        } else if(empty($config['dbname'])) {
73
+            $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname));
74
+        }
75
+        if(substr_count($config['dbname'], '.') >= 1) {
76
+            $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname));
77
+        }
78
+        return $errors;
79
+    }
80 80
 
81
-	public function initialize($config) {
82
-		$dbUser = $config['dbuser'];
83
-		$dbPass = $config['dbpass'];
84
-		$dbName = $config['dbname'];
85
-		$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
86
-		$dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
87
-		$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
81
+    public function initialize($config) {
82
+        $dbUser = $config['dbuser'];
83
+        $dbPass = $config['dbpass'];
84
+        $dbName = $config['dbname'];
85
+        $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
86
+        $dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
87
+        $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
88 88
 
89
-		$this->config->setValues([
90
-			'dbname'		=> $dbName,
91
-			'dbhost'		=> $dbHost,
92
-			'dbport' => $dbPort,
93
-			'dbtableprefix'	=> $dbTablePrefix,
94
-		]);
89
+        $this->config->setValues([
90
+            'dbname'		=> $dbName,
91
+            'dbhost'		=> $dbHost,
92
+            'dbport' => $dbPort,
93
+            'dbtableprefix'	=> $dbTablePrefix,
94
+        ]);
95 95
 
96
-		$this->dbUser = $dbUser;
97
-		$this->dbPassword = $dbPass;
98
-		$this->dbName = $dbName;
99
-		$this->dbHost = $dbHost;
100
-		$this->dbPort = $dbPort;
101
-		$this->tablePrefix = $dbTablePrefix;
102
-	}
96
+        $this->dbUser = $dbUser;
97
+        $this->dbPassword = $dbPass;
98
+        $this->dbName = $dbName;
99
+        $this->dbHost = $dbHost;
100
+        $this->dbPort = $dbPort;
101
+        $this->tablePrefix = $dbTablePrefix;
102
+    }
103 103
 
104
-	/**
105
-	 * @param array $configOverwrite
106
-	 * @return \OC\DB\Connection
107
-	 */
108
-	protected function connect(array $configOverwrite = []) {
109
-		$connectionParams = array(
110
-			'host' => $this->dbHost,
111
-			'user' => $this->dbUser,
112
-			'password' => $this->dbPassword,
113
-			'tablePrefix' => $this->tablePrefix,
114
-			'dbname' => $this->dbName
115
-		);
104
+    /**
105
+     * @param array $configOverwrite
106
+     * @return \OC\DB\Connection
107
+     */
108
+    protected function connect(array $configOverwrite = []) {
109
+        $connectionParams = array(
110
+            'host' => $this->dbHost,
111
+            'user' => $this->dbUser,
112
+            'password' => $this->dbPassword,
113
+            'tablePrefix' => $this->tablePrefix,
114
+            'dbname' => $this->dbName
115
+        );
116 116
 
117
-		// adding port support through installer
118
-		if (!empty($this->dbPort)) {
119
-			if (ctype_digit($this->dbPort)) {
120
-				$connectionParams['port'] = $this->dbPort;
121
-			} else {
122
-				$connectionParams['unix_socket'] = $this->dbPort;
123
-			}
124
-		} else if (strpos($this->dbHost, ':')) {
125
-			// Host variable may carry a port or socket.
126
-			list($host, $portOrSocket) = explode(':', $this->dbHost, 2);
127
-			if (ctype_digit($portOrSocket)) {
128
-				$connectionParams['port'] = $portOrSocket;
129
-			} else {
130
-				$connectionParams['unix_socket'] = $portOrSocket;
131
-			}
132
-			$connectionParams['host'] = $host;
133
-		}
117
+        // adding port support through installer
118
+        if (!empty($this->dbPort)) {
119
+            if (ctype_digit($this->dbPort)) {
120
+                $connectionParams['port'] = $this->dbPort;
121
+            } else {
122
+                $connectionParams['unix_socket'] = $this->dbPort;
123
+            }
124
+        } else if (strpos($this->dbHost, ':')) {
125
+            // Host variable may carry a port or socket.
126
+            list($host, $portOrSocket) = explode(':', $this->dbHost, 2);
127
+            if (ctype_digit($portOrSocket)) {
128
+                $connectionParams['port'] = $portOrSocket;
129
+            } else {
130
+                $connectionParams['unix_socket'] = $portOrSocket;
131
+            }
132
+            $connectionParams['host'] = $host;
133
+        }
134 134
 
135
-		$connectionParams = array_merge($connectionParams, $configOverwrite);
136
-		$cf = new ConnectionFactory($this->config);
137
-		return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams);
138
-	}
135
+        $connectionParams = array_merge($connectionParams, $configOverwrite);
136
+        $cf = new ConnectionFactory($this->config);
137
+        return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams);
138
+    }
139 139
 
140
-	/**
141
-	 * @param string $userName
142
-	 */
143
-	abstract public function setupDatabase($userName);
140
+    /**
141
+     * @param string $userName
142
+     */
143
+    abstract public function setupDatabase($userName);
144 144
 
145
-	public function runMigrations() {
146
-		if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) {
147
-			return;
148
-		}
149
-		$ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
150
-		$ms->migrate();
151
-	}
145
+    public function runMigrations() {
146
+        if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) {
147
+            return;
148
+        }
149
+        $ms = new MigrationService('core', \OC::$server->getDatabaseConnection());
150
+        $ms->migrate();
151
+    }
152 152
 }
Please login to merge, or discard this patch.
lib/private/Setup/PostgreSQL.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -32,132 +32,132 @@
 block discarded – undo
32 32
 use OCP\IDBConnection;
33 33
 
34 34
 class PostgreSQL extends AbstractDatabase {
35
-	public $dbprettyname = 'PostgreSQL';
36
-
37
-	public function setupDatabase($username) {
38
-		try {
39
-			$connection = $this->connect([
40
-				'dbname' => 'postgres'
41
-			]);
42
-			//check for roles creation rights in postgresql
43
-			$builder = $connection->getQueryBuilder();
44
-			$builder->automaticTablePrefix(false);
45
-			$query = $builder
46
-				->select('rolname')
47
-				->from('pg_roles')
48
-				->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE')))
49
-				->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser)));
50
-
51
-			try {
52
-				$result = $query->execute();
53
-				$canCreateRoles = $result->rowCount() > 0;
54
-			} catch (DatabaseException $e) {
55
-				$canCreateRoles = false;
56
-			}
57
-
58
-			if ($canCreateRoles) {
59
-				//use the admin login data for the new database user
60
-
61
-				//add prefix to the postgresql user name to prevent collisions
62
-				$this->dbUser = 'oc_' . strtolower($username);
63
-				//create a new password so we don't need to store the admin config in the config file
64
-				$this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
65
-
66
-				$this->createDBUser($connection);
67
-			}
68
-
69
-			$this->config->setValues([
70
-				'dbuser' => $this->dbUser,
71
-				'dbpassword' => $this->dbPassword,
72
-			]);
73
-
74
-			//create the database
75
-			$this->createDatabase($connection);
76
-			$query = $connection->prepare("select count(*) FROM pg_class WHERE relname=? limit 1");
77
-			$query->execute([$this->tablePrefix . "users"]);
78
-			$tablesSetup = $query->fetchColumn() > 0;
79
-
80
-			// the connection to dbname=postgres is not needed anymore
81
-			$connection->close();
82
-		} catch (\Exception $e) {
83
-			$this->logger->logException($e);
84
-			$this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created');
85
-			$tablesSetup = false;
86
-			$this->config->setValues([
87
-				'dbuser' => $this->dbUser,
88
-				'dbpassword' => $this->dbPassword,
89
-			]);
90
-		}
91
-
92
-		// connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled
93
-		$this->dbUser = $this->config->getValue('dbuser');
94
-		$this->dbPassword = $this->config->getValue('dbpassword');
95
-		$connection = $this->connect();
96
-		try {
97
-			$connection->connect();
98
-		} catch (\Exception $e) {
99
-			$this->logger->logException($e);
100
-			throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
101
-				$this->trans->t('You need to enter details of an existing account.'));
102
-		}
103
-	}
104
-
105
-	private function createDatabase(IDBConnection $connection) {
106
-		if (!$this->databaseExists($connection)) {
107
-			//The database does not exists... let's create it
108
-			$query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser));
109
-			try {
110
-				$query->execute();
111
-			} catch (DatabaseException $e) {
112
-				$this->logger->error('Error while trying to create database');
113
-				$this->logger->logException($e);
114
-			}
115
-		} else {
116
-			$query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
117
-			try {
118
-				$query->execute();
119
-			} catch (DatabaseException $e) {
120
-				$this->logger->error('Error while trying to restrict database permissions');
121
-				$this->logger->logException($e);
122
-			}
123
-		}
124
-	}
125
-
126
-	private function userExists(IDBConnection $connection) {
127
-		$builder = $connection->getQueryBuilder();
128
-		$builder->automaticTablePrefix(false);
129
-		$query = $builder->select('*')
130
-			->from('pg_roles')
131
-			->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser)));
132
-		$result = $query->execute();
133
-		return $result->rowCount() > 0;
134
-	}
135
-
136
-	private function databaseExists(IDBConnection $connection) {
137
-		$builder = $connection->getQueryBuilder();
138
-		$builder->automaticTablePrefix(false);
139
-		$query = $builder->select('datname')
140
-			->from('pg_database')
141
-			->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName)));
142
-		$result = $query->execute();
143
-		return $result->rowCount() > 0;
144
-	}
145
-
146
-	private function createDBUser(IDBConnection $connection) {
147
-		$dbUser = $this->dbUser;
148
-		try {
149
-			$i = 1;
150
-			while ($this->userExists($connection)) {
151
-				$i++;
152
-				$this->dbUser = $dbUser . $i;
153
-			};
154
-
155
-			// create the user
156
-			$query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
157
-			$query->execute();
158
-		} catch (DatabaseException $e) {
159
-			$this->logger->error('Error while trying to create database user');
160
-			$this->logger->logException($e);
161
-		}
162
-	}
35
+    public $dbprettyname = 'PostgreSQL';
36
+
37
+    public function setupDatabase($username) {
38
+        try {
39
+            $connection = $this->connect([
40
+                'dbname' => 'postgres'
41
+            ]);
42
+            //check for roles creation rights in postgresql
43
+            $builder = $connection->getQueryBuilder();
44
+            $builder->automaticTablePrefix(false);
45
+            $query = $builder
46
+                ->select('rolname')
47
+                ->from('pg_roles')
48
+                ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE')))
49
+                ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser)));
50
+
51
+            try {
52
+                $result = $query->execute();
53
+                $canCreateRoles = $result->rowCount() > 0;
54
+            } catch (DatabaseException $e) {
55
+                $canCreateRoles = false;
56
+            }
57
+
58
+            if ($canCreateRoles) {
59
+                //use the admin login data for the new database user
60
+
61
+                //add prefix to the postgresql user name to prevent collisions
62
+                $this->dbUser = 'oc_' . strtolower($username);
63
+                //create a new password so we don't need to store the admin config in the config file
64
+                $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
65
+
66
+                $this->createDBUser($connection);
67
+            }
68
+
69
+            $this->config->setValues([
70
+                'dbuser' => $this->dbUser,
71
+                'dbpassword' => $this->dbPassword,
72
+            ]);
73
+
74
+            //create the database
75
+            $this->createDatabase($connection);
76
+            $query = $connection->prepare("select count(*) FROM pg_class WHERE relname=? limit 1");
77
+            $query->execute([$this->tablePrefix . "users"]);
78
+            $tablesSetup = $query->fetchColumn() > 0;
79
+
80
+            // the connection to dbname=postgres is not needed anymore
81
+            $connection->close();
82
+        } catch (\Exception $e) {
83
+            $this->logger->logException($e);
84
+            $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created');
85
+            $tablesSetup = false;
86
+            $this->config->setValues([
87
+                'dbuser' => $this->dbUser,
88
+                'dbpassword' => $this->dbPassword,
89
+            ]);
90
+        }
91
+
92
+        // connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled
93
+        $this->dbUser = $this->config->getValue('dbuser');
94
+        $this->dbPassword = $this->config->getValue('dbpassword');
95
+        $connection = $this->connect();
96
+        try {
97
+            $connection->connect();
98
+        } catch (\Exception $e) {
99
+            $this->logger->logException($e);
100
+            throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
101
+                $this->trans->t('You need to enter details of an existing account.'));
102
+        }
103
+    }
104
+
105
+    private function createDatabase(IDBConnection $connection) {
106
+        if (!$this->databaseExists($connection)) {
107
+            //The database does not exists... let's create it
108
+            $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser));
109
+            try {
110
+                $query->execute();
111
+            } catch (DatabaseException $e) {
112
+                $this->logger->error('Error while trying to create database');
113
+                $this->logger->logException($e);
114
+            }
115
+        } else {
116
+            $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
117
+            try {
118
+                $query->execute();
119
+            } catch (DatabaseException $e) {
120
+                $this->logger->error('Error while trying to restrict database permissions');
121
+                $this->logger->logException($e);
122
+            }
123
+        }
124
+    }
125
+
126
+    private function userExists(IDBConnection $connection) {
127
+        $builder = $connection->getQueryBuilder();
128
+        $builder->automaticTablePrefix(false);
129
+        $query = $builder->select('*')
130
+            ->from('pg_roles')
131
+            ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser)));
132
+        $result = $query->execute();
133
+        return $result->rowCount() > 0;
134
+    }
135
+
136
+    private function databaseExists(IDBConnection $connection) {
137
+        $builder = $connection->getQueryBuilder();
138
+        $builder->automaticTablePrefix(false);
139
+        $query = $builder->select('datname')
140
+            ->from('pg_database')
141
+            ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName)));
142
+        $result = $query->execute();
143
+        return $result->rowCount() > 0;
144
+    }
145
+
146
+    private function createDBUser(IDBConnection $connection) {
147
+        $dbUser = $this->dbUser;
148
+        try {
149
+            $i = 1;
150
+            while ($this->userExists($connection)) {
151
+                $i++;
152
+                $this->dbUser = $dbUser . $i;
153
+            };
154
+
155
+            // create the user
156
+            $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
157
+            $query->execute();
158
+        } catch (DatabaseException $e) {
159
+            $this->logger->error('Error while trying to create database user');
160
+            $this->logger->logException($e);
161
+        }
162
+    }
163 163
 }
Please login to merge, or discard this patch.
apps/theming/lib/ThemingDefaults.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 
117 117
 	public function getShortFooter() {
118 118
 		$slogan = $this->getSlogan();
119
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
120
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
121
-			($slogan !== '' ? ' – ' . $slogan : '');
119
+		$footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'.
120
+			' rel="noreferrer">'.$this->getEntity().'</a>'.
121
+			($slogan !== '' ? ' – '.$slogan : '');
122 122
 
123 123
 		return $footer;
124 124
 	}
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
152 152
 
153
-		if(!$logo || !$logoExists) {
154
-			if($useSvg) {
153
+		if (!$logo || !$logoExists) {
154
+			if ($useSvg) {
155 155
 				$logo = $this->urlGenerator->imagePath('core', 'logo.svg');
156 156
 			} else {
157 157
 				$logo = $this->urlGenerator->imagePath('core', 'logo.png');
158 158
 			}
159
-			return $logo . '?v=' . $cacheBusterCounter;
159
+			return $logo.'?v='.$cacheBusterCounter;
160 160
 		}
161 161
 
162
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
162
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo').'?v='.$cacheBusterCounter;
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @return string
169 169
 	 */
170 170
 	public function getBackground() {
171
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
171
+		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
172 172
 
173 173
 		$backgroundExists = true;
174 174
 		try {
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 
180 180
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
181 181
 
182
-		if(!$backgroundLogo || !$backgroundExists) {
183
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
182
+		if (!$backgroundLogo || !$backgroundExists) {
183
+			return $this->urlGenerator->imagePath('core', 'background.jpg').'?v='.$cacheBusterCounter;
184 184
 		}
185 185
 
186
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
186
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground').'?v='.$cacheBusterCounter;
187 187
 	}
188 188
 
189 189
 	/**
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 		}
212 212
 
213 213
 		$variables = [
214
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
215
-			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
216
-			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
214
+			'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'",
215
+			'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime', '')."'",
216
+			'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime', '')."'"
217 217
 		];
218 218
 
219 219
 		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	public function shouldReplaceIcons() {
247 247
 		$cache = $this->cacheFactory->create('theming');
248
-		if($value = $cache->get('shouldReplaceIcons')) {
249
-			return (bool)$value;
248
+		if ($value = $cache->get('shouldReplaceIcons')) {
249
+			return (bool) $value;
250 250
 		}
251 251
 		$value = false;
252
-		if(extension_loaded('imagick')) {
252
+		if (extension_loaded('imagick')) {
253 253
 			$checkImagick = new \Imagick();
254 254
 			if (count($checkImagick->queryFormats('SVG')) >= 1) {
255 255
 				$value = true;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 */
266 266
 	private function increaseCacheBuster() {
267 267
 		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
268
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
268
+		$this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1);
269 269
 		$this->cacheFactory->create('theming')->clear('getScssVariables');
270 270
 	}
271 271
 
Please login to merge, or discard this patch.
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -31,293 +31,293 @@
 block discarded – undo
31 31
 
32 32
 class ThemingDefaults extends \OC_Defaults {
33 33
 
34
-	/** @var IConfig */
35
-	private $config;
36
-	/** @var IL10N */
37
-	private $l;
38
-	/** @var IURLGenerator */
39
-	private $urlGenerator;
40
-	/** @var IAppData */
41
-	private $appData;
42
-	/** @var ICacheFactory */
43
-	private $cacheFactory;
44
-	/** @var string */
45
-	private $name;
46
-	/** @var string */
47
-	private $url;
48
-	/** @var string */
49
-	private $slogan;
50
-	/** @var string */
51
-	private $color;
52
-	/** @var Util */
53
-	private $util;
54
-	/** @var string */
55
-	private $iTunesAppId;
56
-	/** @var string */
57
-	private $iOSClientUrl;
58
-	/** @var string */
59
-	private $AndroidClientUrl;
60
-
61
-	/**
62
-	 * ThemingDefaults constructor.
63
-	 *
64
-	 * @param IConfig $config
65
-	 * @param IL10N $l
66
-	 * @param IURLGenerator $urlGenerator
67
-	 * @param \OC_Defaults $defaults
68
-	 * @param IAppData $appData
69
-	 * @param ICacheFactory $cacheFactory
70
-	 * @param Util $util
71
-	 */
72
-	public function __construct(IConfig $config,
73
-								IL10N $l,
74
-								IURLGenerator $urlGenerator,
75
-								IAppData $appData,
76
-								ICacheFactory $cacheFactory,
77
-								Util $util
78
-	) {
79
-		parent::__construct();
80
-		$this->config = $config;
81
-		$this->l = $l;
82
-		$this->urlGenerator = $urlGenerator;
83
-		$this->appData = $appData;
84
-		$this->cacheFactory = $cacheFactory;
85
-		$this->util = $util;
86
-
87
-		$this->name = parent::getName();
88
-		$this->url = parent::getBaseUrl();
89
-		$this->slogan = parent::getSlogan();
90
-		$this->color = parent::getColorPrimary();
91
-		$this->iTunesAppId = parent::getiTunesAppId();
92
-		$this->iOSClientUrl = parent::getiOSClientUrl();
93
-		$this->AndroidClientUrl = parent::getAndroidClientUrl();
94
-	}
95
-
96
-	public function getName() {
97
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
98
-	}
99
-
100
-	public function getHTMLName() {
101
-		return $this->config->getAppValue('theming', 'name', $this->name);
102
-	}
103
-
104
-	public function getTitle() {
105
-		return $this->getName();
106
-	}
107
-
108
-	public function getEntity() {
109
-		return $this->getName();
110
-	}
111
-
112
-	public function getBaseUrl() {
113
-		return $this->config->getAppValue('theming', 'url', $this->url);
114
-	}
115
-
116
-	public function getSlogan() {
117
-		return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
118
-	}
119
-
120
-	public function getShortFooter() {
121
-		$slogan = $this->getSlogan();
122
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
123
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
124
-			($slogan !== '' ? ' – ' . $slogan : '');
125
-
126
-		return $footer;
127
-	}
128
-
129
-	/**
130
-	 * Color that is used for the header as well as for mail headers
131
-	 *
132
-	 * @return string
133
-	 */
134
-	public function getColorPrimary() {
135
-		return $this->config->getAppValue('theming', 'color', $this->color);
136
-	}
137
-
138
-	/**
139
-	 * Themed logo url
140
-	 *
141
-	 * @param bool $useSvg Whether to point to the SVG image or a fallback
142
-	 * @return string
143
-	 */
144
-	public function getLogo($useSvg = true) {
145
-		$logo = $this->config->getAppValue('theming', 'logoMime', false);
146
-
147
-		$logoExists = true;
148
-		try {
149
-			$this->appData->getFolder('images')->getFile('logo');
150
-		} catch (\Exception $e) {
151
-			$logoExists = false;
152
-		}
153
-
154
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
155
-
156
-		if(!$logo || !$logoExists) {
157
-			if($useSvg) {
158
-				$logo = $this->urlGenerator->imagePath('core', 'logo.svg');
159
-			} else {
160
-				$logo = $this->urlGenerator->imagePath('core', 'logo.png');
161
-			}
162
-			return $logo . '?v=' . $cacheBusterCounter;
163
-		}
164
-
165
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
166
-	}
167
-
168
-	/**
169
-	 * Themed background image url
170
-	 *
171
-	 * @return string
172
-	 */
173
-	public function getBackground() {
174
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
175
-
176
-		$backgroundExists = true;
177
-		try {
178
-			$this->appData->getFolder('images')->getFile('background');
179
-		} catch (\Exception $e) {
180
-			$backgroundExists = false;
181
-		}
182
-
183
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
184
-
185
-		if(!$backgroundLogo || !$backgroundExists) {
186
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
187
-		}
188
-
189
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
190
-	}
191
-
192
-	/**
193
-	 * @return string
194
-	 */
195
-	public function getiTunesAppId() {
196
-		return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
197
-	}
198
-
199
-	/**
200
-	 * @return string
201
-	 */
202
-	public function getiOSClientUrl() {
203
-		return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
204
-	}
205
-
206
-	/**
207
-	 * @return string
208
-	 */
209
-	public function getAndroidClientUrl() {
210
-		return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
211
-	}
212
-
213
-
214
-	/**
215
-	 * @return array scss variables to overwrite
216
-	 */
217
-	public function getScssVariables() {
218
-		$cache = $this->cacheFactory->create('theming');
219
-		if ($value = $cache->get('getScssVariables')) {
220
-			return $value;
221
-		}
222
-
223
-		$variables = [
224
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
225
-			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
226
-			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
227
-		];
228
-
229
-		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
230
-		$variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
231
-		$variables['image-login-plain'] = 'false';
232
-
233
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
234
-			if ($this->util->invertTextColor($this->getColorPrimary())) {
235
-				$colorPrimaryText = '#000000';
236
-			} else {
237
-				$colorPrimaryText = '#ffffff';
238
-			}
239
-			$variables['color-primary'] = $this->getColorPrimary();
240
-			$variables['color-primary-text'] = $colorPrimaryText;
241
-		}
242
-
243
-		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
244
-			$variables['image-login-plain'] = 'true';
245
-		}
246
-		$cache->set('getScssVariables', $variables);
247
-		return $variables;
248
-	}
249
-
250
-	/**
251
-	 * Check if Imagemagick is enabled and if SVG is supported
252
-	 * otherwise we can't render custom icons
253
-	 *
254
-	 * @return bool
255
-	 */
256
-	public function shouldReplaceIcons() {
257
-		$cache = $this->cacheFactory->create('theming');
258
-		if($value = $cache->get('shouldReplaceIcons')) {
259
-			return (bool)$value;
260
-		}
261
-		$value = false;
262
-		if(extension_loaded('imagick')) {
263
-			$checkImagick = new \Imagick();
264
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
265
-				$value = true;
266
-			}
267
-			$checkImagick->clear();
268
-		}
269
-		$cache->set('shouldReplaceIcons', $value);
270
-		return $value;
271
-	}
272
-
273
-	/**
274
-	 * Increases the cache buster key
275
-	 */
276
-	private function increaseCacheBuster() {
277
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
278
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
279
-		$this->cacheFactory->create('theming')->clear('getScssVariables');
280
-	}
281
-
282
-	/**
283
-	 * Update setting in the database
284
-	 *
285
-	 * @param string $setting
286
-	 * @param string $value
287
-	 */
288
-	public function set($setting, $value) {
289
-		$this->config->setAppValue('theming', $setting, $value);
290
-		$this->increaseCacheBuster();
291
-	}
292
-
293
-	/**
294
-	 * Revert settings to the default value
295
-	 *
296
-	 * @param string $setting setting which should be reverted
297
-	 * @return string default value
298
-	 */
299
-	public function undo($setting) {
300
-		$this->config->deleteAppValue('theming', $setting);
301
-		$this->increaseCacheBuster();
302
-
303
-		switch ($setting) {
304
-			case 'name':
305
-				$returnValue = $this->getEntity();
306
-				break;
307
-			case 'url':
308
-				$returnValue = $this->getBaseUrl();
309
-				break;
310
-			case 'slogan':
311
-				$returnValue = $this->getSlogan();
312
-				break;
313
-			case 'color':
314
-				$returnValue = $this->getColorPrimary();
315
-				break;
316
-			default:
317
-				$returnValue = '';
318
-				break;
319
-		}
320
-
321
-		return $returnValue;
322
-	}
34
+    /** @var IConfig */
35
+    private $config;
36
+    /** @var IL10N */
37
+    private $l;
38
+    /** @var IURLGenerator */
39
+    private $urlGenerator;
40
+    /** @var IAppData */
41
+    private $appData;
42
+    /** @var ICacheFactory */
43
+    private $cacheFactory;
44
+    /** @var string */
45
+    private $name;
46
+    /** @var string */
47
+    private $url;
48
+    /** @var string */
49
+    private $slogan;
50
+    /** @var string */
51
+    private $color;
52
+    /** @var Util */
53
+    private $util;
54
+    /** @var string */
55
+    private $iTunesAppId;
56
+    /** @var string */
57
+    private $iOSClientUrl;
58
+    /** @var string */
59
+    private $AndroidClientUrl;
60
+
61
+    /**
62
+     * ThemingDefaults constructor.
63
+     *
64
+     * @param IConfig $config
65
+     * @param IL10N $l
66
+     * @param IURLGenerator $urlGenerator
67
+     * @param \OC_Defaults $defaults
68
+     * @param IAppData $appData
69
+     * @param ICacheFactory $cacheFactory
70
+     * @param Util $util
71
+     */
72
+    public function __construct(IConfig $config,
73
+                                IL10N $l,
74
+                                IURLGenerator $urlGenerator,
75
+                                IAppData $appData,
76
+                                ICacheFactory $cacheFactory,
77
+                                Util $util
78
+    ) {
79
+        parent::__construct();
80
+        $this->config = $config;
81
+        $this->l = $l;
82
+        $this->urlGenerator = $urlGenerator;
83
+        $this->appData = $appData;
84
+        $this->cacheFactory = $cacheFactory;
85
+        $this->util = $util;
86
+
87
+        $this->name = parent::getName();
88
+        $this->url = parent::getBaseUrl();
89
+        $this->slogan = parent::getSlogan();
90
+        $this->color = parent::getColorPrimary();
91
+        $this->iTunesAppId = parent::getiTunesAppId();
92
+        $this->iOSClientUrl = parent::getiOSClientUrl();
93
+        $this->AndroidClientUrl = parent::getAndroidClientUrl();
94
+    }
95
+
96
+    public function getName() {
97
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
98
+    }
99
+
100
+    public function getHTMLName() {
101
+        return $this->config->getAppValue('theming', 'name', $this->name);
102
+    }
103
+
104
+    public function getTitle() {
105
+        return $this->getName();
106
+    }
107
+
108
+    public function getEntity() {
109
+        return $this->getName();
110
+    }
111
+
112
+    public function getBaseUrl() {
113
+        return $this->config->getAppValue('theming', 'url', $this->url);
114
+    }
115
+
116
+    public function getSlogan() {
117
+        return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
118
+    }
119
+
120
+    public function getShortFooter() {
121
+        $slogan = $this->getSlogan();
122
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
123
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
124
+            ($slogan !== '' ? ' – ' . $slogan : '');
125
+
126
+        return $footer;
127
+    }
128
+
129
+    /**
130
+     * Color that is used for the header as well as for mail headers
131
+     *
132
+     * @return string
133
+     */
134
+    public function getColorPrimary() {
135
+        return $this->config->getAppValue('theming', 'color', $this->color);
136
+    }
137
+
138
+    /**
139
+     * Themed logo url
140
+     *
141
+     * @param bool $useSvg Whether to point to the SVG image or a fallback
142
+     * @return string
143
+     */
144
+    public function getLogo($useSvg = true) {
145
+        $logo = $this->config->getAppValue('theming', 'logoMime', false);
146
+
147
+        $logoExists = true;
148
+        try {
149
+            $this->appData->getFolder('images')->getFile('logo');
150
+        } catch (\Exception $e) {
151
+            $logoExists = false;
152
+        }
153
+
154
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
155
+
156
+        if(!$logo || !$logoExists) {
157
+            if($useSvg) {
158
+                $logo = $this->urlGenerator->imagePath('core', 'logo.svg');
159
+            } else {
160
+                $logo = $this->urlGenerator->imagePath('core', 'logo.png');
161
+            }
162
+            return $logo . '?v=' . $cacheBusterCounter;
163
+        }
164
+
165
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
166
+    }
167
+
168
+    /**
169
+     * Themed background image url
170
+     *
171
+     * @return string
172
+     */
173
+    public function getBackground() {
174
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
175
+
176
+        $backgroundExists = true;
177
+        try {
178
+            $this->appData->getFolder('images')->getFile('background');
179
+        } catch (\Exception $e) {
180
+            $backgroundExists = false;
181
+        }
182
+
183
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
184
+
185
+        if(!$backgroundLogo || !$backgroundExists) {
186
+            return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
187
+        }
188
+
189
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
190
+    }
191
+
192
+    /**
193
+     * @return string
194
+     */
195
+    public function getiTunesAppId() {
196
+        return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
197
+    }
198
+
199
+    /**
200
+     * @return string
201
+     */
202
+    public function getiOSClientUrl() {
203
+        return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
204
+    }
205
+
206
+    /**
207
+     * @return string
208
+     */
209
+    public function getAndroidClientUrl() {
210
+        return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
211
+    }
212
+
213
+
214
+    /**
215
+     * @return array scss variables to overwrite
216
+     */
217
+    public function getScssVariables() {
218
+        $cache = $this->cacheFactory->create('theming');
219
+        if ($value = $cache->get('getScssVariables')) {
220
+            return $value;
221
+        }
222
+
223
+        $variables = [
224
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
225
+            'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
226
+            'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
227
+        ];
228
+
229
+        $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
230
+        $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
231
+        $variables['image-login-plain'] = 'false';
232
+
233
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
234
+            if ($this->util->invertTextColor($this->getColorPrimary())) {
235
+                $colorPrimaryText = '#000000';
236
+            } else {
237
+                $colorPrimaryText = '#ffffff';
238
+            }
239
+            $variables['color-primary'] = $this->getColorPrimary();
240
+            $variables['color-primary-text'] = $colorPrimaryText;
241
+        }
242
+
243
+        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
244
+            $variables['image-login-plain'] = 'true';
245
+        }
246
+        $cache->set('getScssVariables', $variables);
247
+        return $variables;
248
+    }
249
+
250
+    /**
251
+     * Check if Imagemagick is enabled and if SVG is supported
252
+     * otherwise we can't render custom icons
253
+     *
254
+     * @return bool
255
+     */
256
+    public function shouldReplaceIcons() {
257
+        $cache = $this->cacheFactory->create('theming');
258
+        if($value = $cache->get('shouldReplaceIcons')) {
259
+            return (bool)$value;
260
+        }
261
+        $value = false;
262
+        if(extension_loaded('imagick')) {
263
+            $checkImagick = new \Imagick();
264
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
265
+                $value = true;
266
+            }
267
+            $checkImagick->clear();
268
+        }
269
+        $cache->set('shouldReplaceIcons', $value);
270
+        return $value;
271
+    }
272
+
273
+    /**
274
+     * Increases the cache buster key
275
+     */
276
+    private function increaseCacheBuster() {
277
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
278
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
279
+        $this->cacheFactory->create('theming')->clear('getScssVariables');
280
+    }
281
+
282
+    /**
283
+     * Update setting in the database
284
+     *
285
+     * @param string $setting
286
+     * @param string $value
287
+     */
288
+    public function set($setting, $value) {
289
+        $this->config->setAppValue('theming', $setting, $value);
290
+        $this->increaseCacheBuster();
291
+    }
292
+
293
+    /**
294
+     * Revert settings to the default value
295
+     *
296
+     * @param string $setting setting which should be reverted
297
+     * @return string default value
298
+     */
299
+    public function undo($setting) {
300
+        $this->config->deleteAppValue('theming', $setting);
301
+        $this->increaseCacheBuster();
302
+
303
+        switch ($setting) {
304
+            case 'name':
305
+                $returnValue = $this->getEntity();
306
+                break;
307
+            case 'url':
308
+                $returnValue = $this->getBaseUrl();
309
+                break;
310
+            case 'slogan':
311
+                $returnValue = $this->getSlogan();
312
+                break;
313
+            case 'color':
314
+                $returnValue = $this->getColorPrimary();
315
+                break;
316
+            default:
317
+                $returnValue = '';
318
+                break;
319
+        }
320
+
321
+        return $returnValue;
322
+    }
323 323
 }
Please login to merge, or discard this patch.