Completed
Push — master ( c4929a...3bd4fb )
by Julius
19:34 queued 18:15
created

Version2060Date20200302131958::changeSchema()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 155

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 155
ccs 0
cts 151
cp 0
rs 8
c 0
b 0
f 0
cc 4
nc 8
nop 3
crap 20

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
2
3
declare(strict_types=1);
4
5
namespace OCA\Richdocuments\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version2060Date20200302131958 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 * @return null|ISchemaWrapper
22
	 */
23
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
24
		/** @var ISchemaWrapper $schema */
25
		$schema = $schemaClosure();
26
27
		if (!$schema->hasTable('richdocuments_wopi')) {
28
			$table = $schema->createTable('richdocuments_wopi');
29
			$table->addColumn('id', 'integer', [
30
				'autoincrement' => true,
31
				'notnull' => true,
32
				'length' => 4,
33
				'unsigned' => true,
34
			]);
35
			$table->addColumn('owner_uid', 'string', [
36
				'notnull' => false,
37
				'length' => 64,
38
			]);
39
			$table->addColumn('editor_uid', 'string', [
40
				'notnull' => false,
41
				'length' => 64,
42
			]);
43
			$table->addColumn('guest_displayname', 'string', [
44
				'notnull' => false,
45
				'length' => 64,
46
			]);
47
			$table->addColumn('fileid', 'integer', [
48
				'notnull' => true,
49
				'length' => 4,
50
			]);
51
			$table->addColumn('version', 'integer', [
52
				'notnull' => true,
53
				'length' => 4,
54
				'default' => 0,
55
			]);
56
			$table->addColumn('canwrite', 'boolean', [
57
				'notnull' => true,
58
				'default' => false,
59
			]);
60
			$table->addColumn('server_host', 'string', [
61
				'notnull' => true,
62
				'default' => 'localhost',
63
			]);
64
			$table->addColumn('token', 'string', [
65
				'notnull' => true,
66
				'length' => 32,
67
				'default' => '',
68
			]);
69
			$table->addColumn('expiry', 'integer', [
70
				'notnull' => false,
71
				'length' => 4,
72
				'unsigned' => true,
73
			]);
74
			$table->addColumn('template_destination', 'integer', [
75
				'notnull' => false,
76
				'length' => 4,
77
			]);
78
			$table->addColumn('template_id', 'integer', [
79
				'notnull' => false,
80
				'length' => 4,
81
			]);
82
			$table->addColumn('hide_download', 'boolean', [
83
				'notnull' => true,
84
				'default' => false,
85
			]);
86
			$table->addColumn('direct', 'boolean', [
87
				'notnull' => true,
88
				'default' => false,
89
			]);
90
			$table->addColumn('is_remote_token', 'boolean', [
91
				'notnull' => true,
92
				'default' => false,
93
			]);
94
			$table->addColumn('remote_server', 'string', [
95
				'notnull' => true,
96
				'default' => '',
97
			]);
98
			$table->addColumn('remote_server_token', 'string', [
99
				'notnull' => true,
100
				'length' => 32,
101
				'default' => '',
102
			]);
103
			$table->setPrimaryKey(['id']);
104
			$table->addUniqueIndex(['token'], 'rd_wopi_token_idx');
105
		}
106
107
		if (!$schema->hasTable('richdocuments_direct')) {
108
			$table = $schema->createTable('richdocuments_direct');
109
			$table->addColumn('id', 'integer', [
110
				'autoincrement' => true,
111
				'notnull' => true,
112
				'length' => 4,
113
				'unsigned' => true,
114
			]);
115
			$table->addColumn('token', 'string', [
116
				'notnull' => false,
117
				'length' => 64,
118
			]);
119
			$table->addColumn('uid', 'string', [
120
				'notnull' => false,
121
				'length' => 64,
122
			]);
123
			$table->addColumn('fileid', 'integer', [
124
				'notnull' => true,
125
				'length' => 4,
126
			]);
127
			$table->addColumn('timestamp', 'integer', [
128
				'notnull' => true,
129
				'length' => 4,
130
				'default' => 0,
131
				'unsigned' => true,
132
			]);
133
			$table->addColumn('template_destination', 'integer', [
134
				'notnull' => false,
135
				'length' => 4,
136
			]);
137
			$table->addColumn('template_id', 'integer', [
138
				'notnull' => false,
139
				'length' => 4,
140
			]);
141
			$table->setPrimaryKey(['id']);
142
			$table->addUniqueIndex(['token'], 'rd_direct_token_idx');
143
			$table->addIndex(['timestamp'], 'rd_direct_timestamp_idx');
144
		}
145
146
		if (!$schema->hasTable('richdocuments_assets')) {
147
			$table = $schema->createTable('richdocuments_assets');
148
			$table->addColumn('id', 'integer', [
149
				'autoincrement' => true,
150
				'notnull' => true,
151
				'length' => 4,
152
				'unsigned' => true,
153
			]);
154
			$table->addColumn('uid', 'string', [
155
				'notnull' => false,
156
				'length' => 64,
157
			]);
158
			$table->addColumn('fileid', 'integer', [
159
				'notnull' => true,
160
				'length' => 4,
161
			]);
162
			$table->addColumn('token', 'string', [
163
				'notnull' => false,
164
				'length' => 64,
165
			]);
166
			$table->addColumn('timestamp', 'integer', [
167
				'notnull' => true,
168
				'length' => 4,
169
				'default' => 0,
170
				'unsigned' => true,
171
			]);
172
			$table->setPrimaryKey(['id']);
173
			$table->addUniqueIndex(['token'], 'rd_assets_token_idx');
174
			$table->addUniqueIndex(['timestamp'], 'rd_assets_timestamp_idx');
175
		}
176
		return $schema;
177
	}
178
179
}
180