Passed
Pull Request — master (#292)
by René
03:08
created

Version009000Date20171202105141   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 177
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
dl 0
loc 177
rs 10
ccs 0
cts 160
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D changeSchema() 0 168 8
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 René Gieling <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Migration;
25
26
use Doctrine\DBAL\Types\Type;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Types\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use OCP\DB\ISchemaWrapper;
0 ignored issues
show
Bug introduced by
The type OCP\DB\ISchemaWrapper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use OCP\Migration\SimpleMigrationStep;
0 ignored issues
show
Bug introduced by
The type OCP\Migration\SimpleMigrationStep was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use OCP\Migration\IOutput;
30
31
/**
32
 * Installation class for the polls app.
33
 */
34
class Version009000Date20171202105141 extends SimpleMigrationStep {
35
36
	/**
37
	 * @param IOutput $output
38
	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
	 * @param array $options
40
	 * @return null|ISchemaWrapper
41
	 * @since 13.0.0
42
	 */
43
	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
44
		/** @var ISchemaWrapper $schema */
45
		$schema = $schemaClosure();
46
47
		if (!$schema->hasTable('polls_events')) {
48
			$table = $schema->createTable('polls_events');
49
			$table->addColumn('id', Type::INTEGER, [
50
				'autoincrement' => true,
51
				'notnull' => true,
52
			]);
53
			$table->addColumn('hash', Type::STRING, [
54
				'notnull' => false,
55
				'length' => 64,
56
			]);
57
			$table->addColumn('type', Type::BIGINT, [
58
				'notnull' => false,
59
				'length' => 16,
60
			]);
61
			$table->addColumn('title', Type::STRING, [
62
				'notnull' => true,
63
				'length' => 128,
64
			]);
65
			$table->addColumn('description', Type::STRING, [
66
				'notnull' => true,
67
				'length' => 1024,
68
			]);
69
			$table->addColumn('owner', Type::STRING, [
70
				'notnull' => true,
71
				'length' => 64,
72
			]);
73
			$table->addColumn('created', Type::DATETIME, [
74
				'notnull' => false,
75
			]);
76
			$table->addColumn('access', Type::STRING, [
77
				'notnull' => false,
78
				'length' => 1024,
79
			]);
80
			$table->addColumn('expire', Type::DATETIME, [
81
				'notnull' => false,
82
			]);
83
			$table->addColumn('is_anonymous', Type::INTEGER, [
84
				'notnull' => false,
85
				'default' => 0,
86
			]);
87
			$table->addColumn('full_anonymous', Type::INTEGER, [
88
				'notnull' => false,
89
				'default' => 0,
90
			]);
91
			$table->setPrimaryKey(['id']);
92
		}
93
94
		if (!$schema->hasTable('polls_dts')) {
95
			$table = $schema->createTable('polls_dts');
96
			$table->addColumn('id', Type::INTEGER, [
97
				'autoincrement' => true,
98
				'notnull' => true,
99
			]);
100
			$table->addColumn('poll_id', Type::INTEGER, [
101
				'notnull' => false,
102
			]);
103
			$table->addColumn('dt', Type::DATETIME, [
104
				'notnull' => false,
105
				'length' => 32,
106
			]);
107
			$table->setPrimaryKey(['id']);
108
		}
109
110
		if (!$schema->hasTable('polls_txts')) {
111
			$table = $schema->createTable('polls_txts');
112
			$table->addColumn('id', Type::INTEGER, [
113
				'autoincrement' => true,
114
				'notnull' => true,
115
			]);
116
			$table->addColumn('poll_id', Type::INTEGER, [
117
				'notnull' => false,
118
			]);
119
			$table->addColumn('text', Type::STRING, [
120
				'notnull' => false,
121
				'length' => 256,
122
			]);
123
			$table->setPrimaryKey(['id']);
124
		}
125
126
		if (!$schema->hasTable('polls_particip')) {
127
			$table = $schema->createTable('polls_particip');
128
			$table->addColumn('id', Type::INTEGER, [
129
				'autoincrement' => true,
130
				'notnull' => true,
131
			]);
132
			$table->addColumn('poll_id', Type::INTEGER, [
133
				'notnull' => false,
134
			]);
135
			$table->addColumn('dt', Type::DATETIME, [
136
				'notnull' => false,
137
			]);
138
			$table->addColumn('type', Type::INTEGER, [
139
				'notnull' => false,
140
			]);
141
			$table->addColumn('user_id', Type::STRING, [
142
				'notnull' => true,
143
				'length' => 64,
144
			]);
145
			$table->setPrimaryKey(['id']);
146
		}
147
148
		if (!$schema->hasTable('polls_particip_text')) {
149
			$table = $schema->createTable('polls_particip_text');
150
			$table->addColumn('id', Type::INTEGER, [
151
				'autoincrement' => true,
152
				'notnull' => true,
153
			]);
154
			$table->addColumn('poll_id', Type::INTEGER, [
155
				'notnull' => false,
156
			]);
157
			$table->addColumn('text', Type::STRING, [
158
				'notnull' => false,
159
				'length' => 256,
160
			]);
161
			$table->addColumn('user_id', Type::STRING, [
162
				'notnull' => true,
163
				'length' => 64,
164
			]);
165
			$table->addColumn('type', Type::INTEGER, [
166
				'notnull' => false,
167
			]);
168
			$table->setPrimaryKey(['id']);
169
		}
170
171
		if (!$schema->hasTable('polls_comments')) {
172
			$table = $schema->createTable('polls_comments');
173
			$table->addColumn('id', Type::INTEGER, [
174
				'autoincrement' => true,
175
				'notnull' => true,
176
			]);
177
			$table->addColumn('poll_id', Type::INTEGER, [
178
				'notnull' => false,
179
			]);
180
			$table->addColumn('user_id', Type::STRING, [
181
				'notnull' => true,
182
				'length' => 64,
183
			]);
184
			$table->addColumn('dt', Type::STRING, [
185
				'notnull' => true,
186
				'length' => 32,
187
			]);
188
			$table->addColumn('comment', Type::STRING, [
189
				'notnull' => false,
190
				'length' => 1024,
191
			]);
192
			$table->setPrimaryKey(['id']);
193
		}
194
195
		if (!$schema->hasTable('polls_notif')) {
196
			$table = $schema->createTable('polls_notif');
197
			$table->addColumn('id', Type::INTEGER, [
198
				'autoincrement' => true,
199
				'notnull' => true,
200
			]);
201
			$table->addColumn('poll_id', Type::INTEGER, [
202
				'notnull' => false,
203
			]);
204
			$table->addColumn('user_id', Type::STRING, [
205
				'notnull' => true,
206
				'length' => 64,
207
			]);
208
			$table->setPrimaryKey(['id']);
209
		}
210
		return $schema;
211
	}
212
213
}
214