@@ -32,33 +32,33 @@ |
||
32 | 32 | |
33 | 33 | class Version14000Date20180522074438 extends SimpleMigrationStep { |
34 | 34 | |
35 | - public function changeSchema(IOutput $output, Closure $schemaClosure, |
|
36 | - array $options): ISchemaWrapper { |
|
35 | + public function changeSchema(IOutput $output, Closure $schemaClosure, |
|
36 | + array $options): ISchemaWrapper { |
|
37 | 37 | |
38 | - $schema = $schemaClosure(); |
|
38 | + $schema = $schemaClosure(); |
|
39 | 39 | |
40 | - if (!$schema->hasTable('twofactor_providers')) { |
|
41 | - $table = $schema->createTable('twofactor_providers'); |
|
42 | - $table->addColumn('provider_id', 'string', |
|
43 | - [ |
|
44 | - 'notnull' => true, |
|
45 | - 'length' => 32, |
|
46 | - ]); |
|
47 | - $table->addColumn('uid', 'string', |
|
48 | - [ |
|
49 | - 'notnull' => true, |
|
50 | - 'length' => 64, |
|
51 | - ]); |
|
52 | - $table->addColumn('enabled', 'smallint', |
|
53 | - [ |
|
54 | - 'notnull' => true, |
|
55 | - 'length' => 1, |
|
56 | - ]); |
|
57 | - $table->setPrimaryKey(['provider_id', 'uid']); |
|
58 | - $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
59 | - } |
|
40 | + if (!$schema->hasTable('twofactor_providers')) { |
|
41 | + $table = $schema->createTable('twofactor_providers'); |
|
42 | + $table->addColumn('provider_id', 'string', |
|
43 | + [ |
|
44 | + 'notnull' => true, |
|
45 | + 'length' => 32, |
|
46 | + ]); |
|
47 | + $table->addColumn('uid', 'string', |
|
48 | + [ |
|
49 | + 'notnull' => true, |
|
50 | + 'length' => 64, |
|
51 | + ]); |
|
52 | + $table->addColumn('enabled', 'smallint', |
|
53 | + [ |
|
54 | + 'notnull' => true, |
|
55 | + 'length' => 1, |
|
56 | + ]); |
|
57 | + $table->setPrimaryKey(['provider_id', 'uid']); |
|
58 | + $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
59 | + } |
|
60 | 60 | |
61 | - return $schema; |
|
62 | - } |
|
61 | + return $schema; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -42,58 +42,58 @@ |
||
42 | 42 | */ |
43 | 43 | class Application extends App { |
44 | 44 | |
45 | - public function __construct() { |
|
46 | - parent::__construct('core'); |
|
45 | + public function __construct() { |
|
46 | + parent::__construct('core'); |
|
47 | 47 | |
48 | - $container = $this->getContainer(); |
|
48 | + $container = $this->getContainer(); |
|
49 | 49 | |
50 | - $container->registerService('defaultMailAddress', function () { |
|
51 | - return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
52 | - }); |
|
50 | + $container->registerService('defaultMailAddress', function () { |
|
51 | + return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
52 | + }); |
|
53 | 53 | |
54 | - $server = $container->getServer(); |
|
55 | - $eventDispatcher = $server->getEventDispatcher(); |
|
54 | + $server = $container->getServer(); |
|
55 | + $eventDispatcher = $server->getEventDispatcher(); |
|
56 | 56 | |
57 | - $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
58 | - function(GenericEvent $event) use ($container) { |
|
59 | - /** @var MissingIndexInformation $subject */ |
|
60 | - $subject = $event->getSubject(); |
|
57 | + $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
58 | + function(GenericEvent $event) use ($container) { |
|
59 | + /** @var MissingIndexInformation $subject */ |
|
60 | + $subject = $event->getSubject(); |
|
61 | 61 | |
62 | - $schema = new SchemaWrapper($container->query(IDBConnection::class)); |
|
62 | + $schema = new SchemaWrapper($container->query(IDBConnection::class)); |
|
63 | 63 | |
64 | - if ($schema->hasTable('share')) { |
|
65 | - $table = $schema->getTable('share'); |
|
64 | + if ($schema->hasTable('share')) { |
|
65 | + $table = $schema->getTable('share'); |
|
66 | 66 | |
67 | - if (!$table->hasIndex('share_with_index')) { |
|
68 | - $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
69 | - } |
|
70 | - if (!$table->hasIndex('parent_index')) { |
|
71 | - $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
72 | - } |
|
73 | - if (!$table->hasIndex('owner_index')) { |
|
74 | - $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
75 | - } |
|
76 | - if (!$table->hasIndex('initiator_index')) { |
|
77 | - $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
78 | - } |
|
79 | - } |
|
67 | + if (!$table->hasIndex('share_with_index')) { |
|
68 | + $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
69 | + } |
|
70 | + if (!$table->hasIndex('parent_index')) { |
|
71 | + $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
72 | + } |
|
73 | + if (!$table->hasIndex('owner_index')) { |
|
74 | + $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
75 | + } |
|
76 | + if (!$table->hasIndex('initiator_index')) { |
|
77 | + $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - if ($schema->hasTable('filecache')) { |
|
82 | - $table = $schema->getTable('filecache'); |
|
81 | + if ($schema->hasTable('filecache')) { |
|
82 | + $table = $schema->getTable('filecache'); |
|
83 | 83 | |
84 | - if (!$table->hasIndex('fs_mtime')) { |
|
85 | - $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
86 | - } |
|
87 | - } |
|
84 | + if (!$table->hasIndex('fs_mtime')) { |
|
85 | + $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - if ($schema->hasTable('twofactor_providers')) { |
|
90 | - $table = $schema->getTable('twofactor_providers'); |
|
89 | + if ($schema->hasTable('twofactor_providers')) { |
|
90 | + $table = $schema->getTable('twofactor_providers'); |
|
91 | 91 | |
92 | - if (!$table->hasIndex('twofactor_providers_uid')) { |
|
93 | - $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - ); |
|
98 | - } |
|
92 | + if (!$table->hasIndex('twofactor_providers_uid')) { |
|
93 | + $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | } |
@@ -41,107 +41,107 @@ |
||
41 | 41 | */ |
42 | 42 | class AddMissingIndices extends Command { |
43 | 43 | |
44 | - /** @var IDBConnection */ |
|
45 | - private $connection; |
|
46 | - |
|
47 | - /** @var EventDispatcherInterface */ |
|
48 | - private $dispatcher; |
|
49 | - |
|
50 | - public function __construct(IDBConnection $connection, EventDispatcherInterface $dispatcher) { |
|
51 | - parent::__construct(); |
|
52 | - |
|
53 | - $this->connection = $connection; |
|
54 | - $this->dispatcher = $dispatcher; |
|
55 | - } |
|
56 | - |
|
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('db:add-missing-indices') |
|
60 | - ->setDescription('Add missing indices to the database tables'); |
|
61 | - } |
|
62 | - |
|
63 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
64 | - $this->addCoreIndexes($output); |
|
65 | - |
|
66 | - // Dispatch event so apps can also update indexes if needed |
|
67 | - $event = new GenericEvent($output); |
|
68 | - $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * add missing indices to the share table |
|
73 | - * |
|
74 | - * @param OutputInterface $output |
|
75 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
76 | - */ |
|
77 | - private function addCoreIndexes(OutputInterface $output) { |
|
78 | - |
|
79 | - $output->writeln('<info>Check indices of the share table.</info>'); |
|
80 | - |
|
81 | - $schema = new SchemaWrapper($this->connection); |
|
82 | - $updated = false; |
|
83 | - |
|
84 | - if ($schema->hasTable('share')) { |
|
85 | - $table = $schema->getTable('share'); |
|
86 | - if (!$table->hasIndex('share_with_index')) { |
|
87 | - $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>'); |
|
88 | - $table->addIndex(['share_with'], 'share_with_index'); |
|
89 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
90 | - $updated = true; |
|
91 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
92 | - } |
|
93 | - |
|
94 | - if (!$table->hasIndex('parent_index')) { |
|
95 | - $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>'); |
|
96 | - $table->addIndex(['parent'], 'parent_index'); |
|
97 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
98 | - $updated = true; |
|
99 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
100 | - } |
|
101 | - |
|
102 | - if (!$table->hasIndex('owner_index')) { |
|
103 | - $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>'); |
|
104 | - $table->addIndex(['uid_owner'], 'owner_index'); |
|
105 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
106 | - $updated = true; |
|
107 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
108 | - } |
|
109 | - |
|
110 | - if (!$table->hasIndex('initiator_index')) { |
|
111 | - $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>'); |
|
112 | - $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
113 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
114 | - $updated = true; |
|
115 | - $output->writeln('<info>Share table updated successfully.</info>'); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - $output->writeln('<info>Check indices of the filecache table.</info>'); |
|
120 | - if ($schema->hasTable('filecache')) { |
|
121 | - $table = $schema->getTable('filecache'); |
|
122 | - if (!$table->hasIndex('fs_mtime')) { |
|
123 | - $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>'); |
|
124 | - $table->addIndex(['mtime'], 'fs_mtime'); |
|
125 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
126 | - $updated = true; |
|
127 | - $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - $output->writeln('<info>Check indices of the twofactor_providers table.</info>'); |
|
132 | - if ($schema->hasTable('twofactor_providers')) { |
|
133 | - $table = $schema->getTable('twofactor_providers'); |
|
134 | - if (!$table->hasIndex('twofactor_providers_uid')) { |
|
135 | - $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>'); |
|
136 | - $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
137 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
138 | - $updated = true; |
|
139 | - $output->writeln('<info>Twofactor_providers table updated successfully.</info>'); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - if (!$updated) { |
|
144 | - $output->writeln('<info>Done.</info>'); |
|
145 | - } |
|
146 | - } |
|
44 | + /** @var IDBConnection */ |
|
45 | + private $connection; |
|
46 | + |
|
47 | + /** @var EventDispatcherInterface */ |
|
48 | + private $dispatcher; |
|
49 | + |
|
50 | + public function __construct(IDBConnection $connection, EventDispatcherInterface $dispatcher) { |
|
51 | + parent::__construct(); |
|
52 | + |
|
53 | + $this->connection = $connection; |
|
54 | + $this->dispatcher = $dispatcher; |
|
55 | + } |
|
56 | + |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('db:add-missing-indices') |
|
60 | + ->setDescription('Add missing indices to the database tables'); |
|
61 | + } |
|
62 | + |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
64 | + $this->addCoreIndexes($output); |
|
65 | + |
|
66 | + // Dispatch event so apps can also update indexes if needed |
|
67 | + $event = new GenericEvent($output); |
|
68 | + $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * add missing indices to the share table |
|
73 | + * |
|
74 | + * @param OutputInterface $output |
|
75 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
76 | + */ |
|
77 | + private function addCoreIndexes(OutputInterface $output) { |
|
78 | + |
|
79 | + $output->writeln('<info>Check indices of the share table.</info>'); |
|
80 | + |
|
81 | + $schema = new SchemaWrapper($this->connection); |
|
82 | + $updated = false; |
|
83 | + |
|
84 | + if ($schema->hasTable('share')) { |
|
85 | + $table = $schema->getTable('share'); |
|
86 | + if (!$table->hasIndex('share_with_index')) { |
|
87 | + $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>'); |
|
88 | + $table->addIndex(['share_with'], 'share_with_index'); |
|
89 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
90 | + $updated = true; |
|
91 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
92 | + } |
|
93 | + |
|
94 | + if (!$table->hasIndex('parent_index')) { |
|
95 | + $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>'); |
|
96 | + $table->addIndex(['parent'], 'parent_index'); |
|
97 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
98 | + $updated = true; |
|
99 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
100 | + } |
|
101 | + |
|
102 | + if (!$table->hasIndex('owner_index')) { |
|
103 | + $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>'); |
|
104 | + $table->addIndex(['uid_owner'], 'owner_index'); |
|
105 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
106 | + $updated = true; |
|
107 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
108 | + } |
|
109 | + |
|
110 | + if (!$table->hasIndex('initiator_index')) { |
|
111 | + $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>'); |
|
112 | + $table->addIndex(['uid_initiator'], 'initiator_index'); |
|
113 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
114 | + $updated = true; |
|
115 | + $output->writeln('<info>Share table updated successfully.</info>'); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + $output->writeln('<info>Check indices of the filecache table.</info>'); |
|
120 | + if ($schema->hasTable('filecache')) { |
|
121 | + $table = $schema->getTable('filecache'); |
|
122 | + if (!$table->hasIndex('fs_mtime')) { |
|
123 | + $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>'); |
|
124 | + $table->addIndex(['mtime'], 'fs_mtime'); |
|
125 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
126 | + $updated = true; |
|
127 | + $output->writeln('<info>Filecache table updated successfully.</info>'); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + $output->writeln('<info>Check indices of the twofactor_providers table.</info>'); |
|
132 | + if ($schema->hasTable('twofactor_providers')) { |
|
133 | + $table = $schema->getTable('twofactor_providers'); |
|
134 | + if (!$table->hasIndex('twofactor_providers_uid')) { |
|
135 | + $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>'); |
|
136 | + $table->addIndex(['uid'], 'twofactor_providers_uid'); |
|
137 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
138 | + $updated = true; |
|
139 | + $output->writeln('<info>Twofactor_providers table updated successfully.</info>'); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + if (!$updated) { |
|
144 | + $output->writeln('<info>Done.</info>'); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | } |