Passed
Push — master ( 181fce...839cdd )
by Christoph
11:22
created

Application   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 20

1 Method

Rating   Name   Duplication   Size   Complexity  
D __construct() 0 87 20
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
5
 *
6
 * @author Bernhard Posselt <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Lukas Reschke <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Victor Dubiniuk <[email protected]>
12
 *
13
 * @license AGPL-3.0
14
 *
15
 * This code is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License, version 3,
17
 * as published by the Free Software Foundation.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License, version 3,
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
26
 *
27
 */
28
29
namespace OC\Core;
30
31
use OC\DB\MissingIndexInformation;
32
use OC\DB\SchemaWrapper;
33
use OCP\AppFramework\App;
34
use OCP\IDBConnection;
35
use OCP\Util;
36
use Symfony\Component\EventDispatcher\GenericEvent;
37
38
/**
39
 * Class Application
40
 *
41
 * @package OC\Core
42
 */
43
class Application extends App {
44
45
	public function __construct() {
46
		parent::__construct('core');
47
48
		$container = $this->getContainer();
49
50
		$container->registerService('defaultMailAddress', function () {
51
			return Util::getDefaultEmailAddress('lostpassword-noreply');
52
		});
53
54
		$server = $container->getServer();
55
		$eventDispatcher = $server->getEventDispatcher();
56
57
		$eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
58
			function(GenericEvent $event) use ($container) {
59
				/** @var MissingIndexInformation $subject */
60
				$subject = $event->getSubject();
61
62
				$schema = new SchemaWrapper($container->query(IDBConnection::class));
63
64
				if ($schema->hasTable('share')) {
65
					$table = $schema->getTable('share');
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
				}
80
81
				if ($schema->hasTable('filecache')) {
82
					$table = $schema->getTable('filecache');
83
84
					if (!$table->hasIndex('fs_mtime')) {
85
						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
86
					}
87
				}
88
89
				if ($schema->hasTable('twofactor_providers')) {
90
					$table = $schema->getTable('twofactor_providers');
91
92
					if (!$table->hasIndex('twofactor_providers_uid')) {
93
						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
94
					}
95
				}
96
97
				if ($schema->hasTable('login_flow_v2')) {
98
					$table = $schema->getTable('login_flow_v2');
99
100
					if (!$table->hasIndex('poll_token')) {
101
						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
102
					}
103
					if (!$table->hasIndex('login_token')) {
104
						$subject->addHintForMissingSubject($table->getName(), 'login_token');
105
					}
106
					if (!$table->hasIndex('timestamp')) {
107
						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
108
					}
109
				}
110
111
				if ($schema->hasTable('whats_new')) {
112
					$table = $schema->getTable('whats_new');
113
114
					if (!$table->hasIndex('version')) {
115
						$subject->addHintForMissingSubject($table->getName(), 'version');
116
					}
117
				}
118
119
				if ($schema->hasTable('cards')) {
120
					$table = $schema->getTable('cards');
121
122
					if (!$table->hasIndex('cards_abid')) {
123
						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
124
					}
125
				}
126
127
				if ($schema->hasTable('cards_properties')) {
128
					$table = $schema->getTable('cards_properties');
129
130
					if (!$table->hasIndex('cards_prop_abid')) {
131
						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
132
					}
133
				}
134
			}
135
		);
136
	}
137
}
138