Conditions | 29 |
Paths | > 20000 |
Total Lines | 149 |
Code Lines | 102 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | $output->writeln('<info>Check indices of the login_flow_v2 table.</info>'); |
||
144 | if ($schema->hasTable('login_flow_v2')) { |
||
145 | $table = $schema->getTable('login_flow_v2'); |
||
146 | if (!$table->hasIndex('poll_token')) { |
||
147 | $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>'); |
||
148 | |||
149 | foreach ($table->getIndexes() as $index) { |
||
150 | $columns = $index->getColumns(); |
||
151 | if ($columns === ['poll_token'] || |
||
152 | $columns === ['login_token'] || |
||
153 | $columns === ['timestamp']) { |
||
154 | $table->dropIndex($index->getName()); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $table->addUniqueIndex(['poll_token'], 'poll_token'); |
||
159 | $table->addUniqueIndex(['login_token'], 'login_token'); |
||
160 | $table->addIndex(['timestamp'], 'timestamp'); |
||
161 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
162 | $updated = true; |
||
163 | $output->writeln('<info>login_flow_v2 table updated successfully.</info>'); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | $output->writeln('<info>Check indices of the whats_new table.</info>'); |
||
168 | if ($schema->hasTable('whats_new')) { |
||
169 | $table = $schema->getTable('whats_new'); |
||
170 | if (!$table->hasIndex('version')) { |
||
171 | $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>'); |
||
172 | |||
173 | foreach ($table->getIndexes() as $index) { |
||
174 | if ($index->getColumns() === ['version']) { |
||
175 | $table->dropIndex($index->getName()); |
||
176 | } |
||
177 | } |
||
178 | |||
179 | $table->addUniqueIndex(['version'], 'version'); |
||
180 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
181 | $updated = true; |
||
182 | $output->writeln('<info>whats_new table updated successfully.</info>'); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | $output->writeln('<info>Check indices of the cards table.</info>'); |
||
187 | if ($schema->hasTable('cards')) { |
||
188 | $table = $schema->getTable('cards'); |
||
189 | if (!$table->hasIndex('cards_abid')) { |
||
190 | $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>'); |
||
191 | |||
192 | foreach ($table->getIndexes() as $index) { |
||
193 | if ($index->getColumns() === ['addressbookid']) { |
||
194 | $table->dropIndex($index->getName()); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | $table->addIndex(['addressbookid'], 'cards_abid'); |
||
199 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
200 | $updated = true; |
||
201 | $output->writeln('<info>cards table updated successfully.</info>'); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | $output->writeln('<info>Check indices of the cards_properties table.</info>'); |
||
206 | if ($schema->hasTable('cards_properties')) { |
||
207 | $table = $schema->getTable('cards_properties'); |
||
208 | if (!$table->hasIndex('cards_prop_abid')) { |
||
209 | $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>'); |
||
210 | |||
211 | foreach ($table->getIndexes() as $index) { |
||
212 | if ($index->getColumns() === ['addressbookid']) { |
||
213 | $table->dropIndex($index->getName()); |
||
214 | } |
||
215 | } |
||
216 | |||
217 | $table->addIndex(['addressbookid'], 'cards_prop_abid'); |
||
218 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
219 | $updated = true; |
||
220 | $output->writeln('<info>cards_properties table updated successfully.</info>'); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | if (!$updated) { |
||
225 | $output->writeln('<info>Done.</info>'); |
||
226 | } |
||
229 |