Passed
Push — master ( cdfad9...e39d65 )
by Joas
12:09 queued 10s
created

Application::__construct()   F

Complexity

Conditions 41
Paths 1

Size

Total Lines 207
Code Lines 110

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 41
eloc 110
nc 1
nop 0
dl 0
loc 207
rs 3.3333
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
5
 *
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Mario Danic <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Roeland Jago Douma <[email protected]>
13
 * @author Thomas Citharel <[email protected]>
14
 * @author Victor Dubiniuk <[email protected]>
15
 *
16
 * @license AGPL-3.0
17
 *
18
 * This code is free software: you can redistribute it and/or modify
19
 * it under the terms of the GNU Affero General Public License, version 3,
20
 * as published by the Free Software Foundation.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License, version 3,
28
 * along with this program. If not, see <http://www.gnu.org/licenses/>
29
 *
30
 */
31
32
namespace OC\Core;
33
34
use OC\Authentication\Events\RemoteWipeFinished;
35
use OC\Authentication\Events\RemoteWipeStarted;
36
use OC\Authentication\Listeners\RemoteWipeActivityListener;
37
use OC\Authentication\Listeners\RemoteWipeEmailListener;
38
use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
39
use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
40
use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
41
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
42
use OC\Core\Notification\RemoveLinkSharesNotifier;
43
use OC\DB\MissingColumnInformation;
44
use OC\DB\MissingIndexInformation;
45
use OC\DB\MissingPrimaryKeyInformation;
46
use OC\DB\SchemaWrapper;
47
use OCP\AppFramework\App;
48
use OCP\EventDispatcher\IEventDispatcher;
49
use OCP\IDBConnection;
50
use OCP\User\Events\UserDeletedEvent;
51
use OCP\Util;
52
use Symfony\Component\EventDispatcher\GenericEvent;
53
54
/**
55
 * Class Application
56
 *
57
 * @package OC\Core
58
 */
59
class Application extends App {
60
	public function __construct() {
61
		parent::__construct('core');
62
63
		$container = $this->getContainer();
64
65
		$container->registerService('defaultMailAddress', function () {
66
			return Util::getDefaultEmailAddress('lostpassword-noreply');
67
		});
68
69
		$server = $container->getServer();
70
		/** @var IEventDispatcher $eventDispatcher */
71
		$eventDispatcher = $server->query(IEventDispatcher::class);
72
73
		$notificationManager = $server->getNotificationManager();
74
		$notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class);
75
		$notificationManager->registerNotifierService(AuthenticationNotifier::class);
76
77
		$oldEventDispatcher = $server->getEventDispatcher();
78
79
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
80
			function (GenericEvent $event) use ($container) {
81
				/** @var MissingIndexInformation $subject */
82
				$subject = $event->getSubject();
83
84
				$schema = new SchemaWrapper($container->query(IDBConnection::class));
85
86
				if ($schema->hasTable('share')) {
87
					$table = $schema->getTable('share');
88
89
					if (!$table->hasIndex('share_with_index')) {
90
						$subject->addHintForMissingSubject($table->getName(), 'share_with_index');
91
					}
92
					if (!$table->hasIndex('parent_index')) {
93
						$subject->addHintForMissingSubject($table->getName(), 'parent_index');
94
					}
95
					if (!$table->hasIndex('owner_index')) {
96
						$subject->addHintForMissingSubject($table->getName(), 'owner_index');
97
					}
98
					if (!$table->hasIndex('initiator_index')) {
99
						$subject->addHintForMissingSubject($table->getName(), 'initiator_index');
100
					}
101
				}
102
103
				if ($schema->hasTable('filecache')) {
104
					$table = $schema->getTable('filecache');
105
106
					if (!$table->hasIndex('fs_mtime')) {
107
						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
108
					}
109
110
					if (!$table->hasIndex('fs_size')) {
111
						$subject->addHintForMissingSubject($table->getName(), 'fs_size');
112
					}
113
				}
114
115
				if ($schema->hasTable('twofactor_providers')) {
116
					$table = $schema->getTable('twofactor_providers');
117
118
					if (!$table->hasIndex('twofactor_providers_uid')) {
119
						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
120
					}
121
				}
122
123
				if ($schema->hasTable('login_flow_v2')) {
124
					$table = $schema->getTable('login_flow_v2');
125
126
					if (!$table->hasIndex('poll_token')) {
127
						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
128
					}
129
					if (!$table->hasIndex('login_token')) {
130
						$subject->addHintForMissingSubject($table->getName(), 'login_token');
131
					}
132
					if (!$table->hasIndex('timestamp')) {
133
						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
134
					}
135
				}
136
137
				if ($schema->hasTable('whats_new')) {
138
					$table = $schema->getTable('whats_new');
139
140
					if (!$table->hasIndex('version')) {
141
						$subject->addHintForMissingSubject($table->getName(), 'version');
142
					}
143
				}
144
145
				if ($schema->hasTable('cards')) {
146
					$table = $schema->getTable('cards');
147
148
					if (!$table->hasIndex('cards_abid')) {
149
						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
150
					}
151
				}
152
153
				if ($schema->hasTable('cards_properties')) {
154
					$table = $schema->getTable('cards_properties');
155
156
					if (!$table->hasIndex('cards_prop_abid')) {
157
						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
158
					}
159
				}
160
161
				if ($schema->hasTable('calendarobjects_props')) {
162
					$table = $schema->getTable('calendarobjects_props');
163
164
					if (!$table->hasIndex('calendarobject_calid_index')) {
165
						$subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
166
					}
167
				}
168
169
				if ($schema->hasTable('schedulingobjects')) {
170
					$table = $schema->getTable('schedulingobjects');
171
					if (!$table->hasIndex('schedulobj_principuri_index')) {
172
						$subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
173
					}
174
				}
175
176
				if ($schema->hasTable('properties')) {
177
					$table = $schema->getTable('properties');
178
					if (!$table->hasIndex('properties_path_index')) {
179
						$subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
180
					}
181
				}
182
			}
183
		);
184
185
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
186
			function (GenericEvent $event) use ($container) {
187
				/** @var MissingPrimaryKeyInformation $subject */
188
				$subject = $event->getSubject();
189
190
				$schema = new SchemaWrapper($container->query(IDBConnection::class));
191
192
				if ($schema->hasTable('federated_reshares')) {
193
					$table = $schema->getTable('federated_reshares');
194
195
					if (!$table->hasPrimaryKey()) {
196
						$subject->addHintForMissingSubject($table->getName());
197
					}
198
				}
199
200
				if ($schema->hasTable('systemtag_object_mapping')) {
201
					$table = $schema->getTable('systemtag_object_mapping');
202
203
					if (!$table->hasPrimaryKey()) {
204
						$subject->addHintForMissingSubject($table->getName());
205
					}
206
				}
207
208
				if ($schema->hasTable('comments_read_markers')) {
209
					$table = $schema->getTable('comments_read_markers');
210
211
					if (!$table->hasPrimaryKey()) {
212
						$subject->addHintForMissingSubject($table->getName());
213
					}
214
				}
215
216
				if ($schema->hasTable('collres_resources')) {
217
					$table = $schema->getTable('collres_resources');
218
219
					if (!$table->hasPrimaryKey()) {
220
						$subject->addHintForMissingSubject($table->getName());
221
					}
222
				}
223
224
				if ($schema->hasTable('collres_accesscache')) {
225
					$table = $schema->getTable('collres_accesscache');
226
227
					if (!$table->hasPrimaryKey()) {
228
						$subject->addHintForMissingSubject($table->getName());
229
					}
230
				}
231
232
				if ($schema->hasTable('filecache_extended')) {
233
					$table = $schema->getTable('filecache_extended');
234
235
					if (!$table->hasPrimaryKey()) {
236
						$subject->addHintForMissingSubject($table->getName());
237
					}
238
				}
239
			}
240
		);
241
242
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
243
			function (GenericEvent $event) use ($container) {
244
				/** @var MissingColumnInformation $subject */
245
				$subject = $event->getSubject();
246
247
				$schema = new SchemaWrapper($container->query(IDBConnection::class));
248
249
				if ($schema->hasTable('comments')) {
250
					$table = $schema->getTable('comments');
251
252
					if (!$table->hasColumn('reference_id')) {
253
						$subject->addHintForMissingColumn($table->getName(), 'reference_id');
254
					}
255
				}
256
			}
257
		);
258
259
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
260
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
261
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
262
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
263
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
264
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
265
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
266
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
267
	}
268
}
269