Completed
Pull Request — master (#362)
by Maxence
01:46
created

Version0017Date20191210153032::changeSchema()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 113

Duplication

Lines 39
Ratio 34.51 %

Importance

Changes 0
Metric Value
dl 39
loc 113
rs 8
c 0
b 0
f 0
cc 4
nc 8
nop 3

How to fix   Long Method   

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 declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2019
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
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
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\Migration;
31
32
33
use Closure;
34
use Doctrine\DBAL\Schema\SchemaException;
35
use OCP\DB\ISchemaWrapper;
36
use OCP\Migration\IOutput;
37
use OCP\Migration\SimpleMigrationStep;
38
39
40
class Version0017Date20191210153032 extends SimpleMigrationStep {
41
42
	/**
43
	 * @param IOutput $output
44
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
45
	 * @param array $options
46
	 */
47
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
48
	}
49
50
	/**
51
	 * @param IOutput $output
52
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
53
	 * @param array $options
54
	 *
55
	 * @return null|ISchemaWrapper
56
	 * @throws SchemaException
57
	 */
58
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
59
		/** @var ISchemaWrapper $schema */
60
		$schema = $schemaClosure();
61
62
		$table = $schema->getTable('circles_members');
63
		if (!$table->hasColumn('instance')) {
64
			$table->addColumn(
65
				'instance', 'string', [
66
							  'notnull' => false,
67
							  'length'  => 255,
68
						  ]
69
			);
70
			$table->dropPrimaryKey();
71
			$table->setPrimaryKey(['circle_id', 'user_id', 'user_type', 'instance']);
72
		}
73
74 View Code Duplication
		if (!$schema->hasTable('circles_gsevents')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
			$table = $schema->createTable('circles_gsevents');
76
			$table->addColumn(
77
				'token', 'string', [
78
						   'notnull' => false,
79
						   'length'  => 63,
80
					   ]
81
			);
82
			$table->addColumn(
83
				'event', 'text', [
84
						   'notnull' => false
85
					   ]
86
			);
87
			$table->addColumn(
88
				'instance', 'string', [
89
							  'length'  => 255,
90
							  'notnull' => false
91
						  ]
92
			);
93
			$table->addColumn(
94
				'severity', 'integer', [
95
							  'length'  => 3,
96
							  'notnull' => false
97
						  ]
98
			);
99
			$table->addColumn(
100
				'status', 'integer', [
101
							'length'  => 3,
102
							'notnull' => false
103
						]
104
			);
105
			$table->addColumn(
106
				'creation', 'bigint', [
107
							  'length'  => 14,
108
							  'notnull' => false
109
						  ]
110
			);
111
			$table->addUniqueIndex(['token', 'instance']);
112
		}
113
114
		if (!$schema->hasTable('circles_gsshares')) {
115
			$table = $schema->createTable('circles_gsshares');
116
			$table->addColumn(
117
				'id', 'integer', [
118
						'notnull' => false,
119
						'length'  => 11,
120
						'autoincrement' => true,
121
						'unsigned' => true
122
					]
123
			);
124
			$table->addColumn(
125
				'circle_id', 'string', [
126
									  'length'  => 15,
127
									  'notnull' => false
128
								  ]
129
			);
130
			$table->addColumn(
131
				'owner', 'string', [
132
						   'length'  => 15,
133
						   'notnull' => false
134
					   ]
135
			);
136
			$table->addColumn(
137
				'instance', 'string', [
138
							  'length'  => 255,
139
							  'notnull' => false
140
						  ]
141
			);
142
			$table->addColumn(
143
				'token', 'string', [
144
						   'notnull' => false,
145
						   'length'  => 63
146
					   ]
147
			);
148
			$table->addColumn(
149
				'parent', 'integer', [
150
							'notnull' => false,
151
							'length'  => 11,
152
						]
153
			);
154
			$table->addColumn(
155
				'mountpoint', 'text', [
156
								'notnull' => false
157
							]
158
			);
159
			$table->addColumn(
160
				'mountpoint_hash', 'string', [
161
									 'length'  => 64,
162
									 'notnull' => false
163
								 ]
164
			);
165
			$table->setPrimaryKey(['id']);
166
			$table->addUniqueIndex(['circle_id', 'mountpoint_hash']);
167
		}
168
169
		return $schema;
170
	}
171
172
173
	/**
174
	 * @param IOutput $output
175
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
176
	 * @param array $options
177
	 */
178
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
179
	}
180
181
}
182
183