1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Circles - Bring cloud-users closer together. |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. See the COPYING file. |
10
|
|
|
* |
11
|
|
|
* @author Maxence Lange <[email protected]> |
12
|
|
|
* @copyright 2021 |
13
|
|
|
* @license GNU AGPL version 3 or any later version |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace OCA\Circles\Migration; |
31
|
|
|
|
32
|
|
|
use Closure; |
33
|
|
|
use Doctrine\DBAL\Schema\SchemaException; |
34
|
|
|
use OCP\DB\ISchemaWrapper; |
35
|
|
|
use OCP\IDBConnection; |
36
|
|
|
use OCP\Migration\IOutput; |
37
|
|
|
use OCP\Migration\SimpleMigrationStep; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Class Version0021Date20210105123456 |
42
|
|
|
* |
43
|
|
|
* @package OCA\Circles\Migration |
44
|
|
|
*/ |
45
|
|
|
class Version0021Date20210105123456 extends SimpleMigrationStep { |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** @var IDBConnection */ |
49
|
|
|
private $connection; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param IDBConnection $connection |
54
|
|
|
*/ |
55
|
|
|
public function __construct(IDBConnection $connection) { |
56
|
|
|
$this->connection = $connection; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param IOutput $output |
62
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
63
|
|
|
* @param array $options |
64
|
|
|
* |
65
|
|
|
* @return null|ISchemaWrapper |
66
|
|
|
*/ |
67
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
68
|
|
|
/** @var ISchemaWrapper $schema */ |
69
|
|
|
$schema = $schemaClosure(); |
70
|
|
|
|
71
|
|
|
try { |
72
|
|
|
$circles = $schema->getTable('circle_circles'); |
73
|
|
|
if (!$circles->hasColumn('config')) { |
74
|
|
|
$circles->addColumn( |
75
|
|
|
'config', 'integer', [ |
76
|
|
|
'notnull' => false, |
77
|
|
|
'length' => 11, |
78
|
|
|
'unsigned' => true, |
79
|
|
|
] |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
if (!$circles->hasColumn('instance')) { |
83
|
|
|
$circles->addColumn( |
84
|
|
|
'instance', 'string', [ |
85
|
|
|
'notnull' => true, |
86
|
|
|
'default' => '', |
87
|
|
|
'length' => 255 |
88
|
|
|
] |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
$circles->addIndex(['config']); |
92
|
|
|
} catch (SchemaException $e) { |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
try { |
97
|
|
|
$circles = $schema->getTable('circle_members'); |
98
|
|
|
if (!$circles->hasColumn('single_id')) { |
99
|
|
|
$circles->addColumn( |
100
|
|
|
'single_id', 'string', [ |
101
|
|
|
'notnull' => false, |
102
|
|
|
'length' => 15 |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
} catch (SchemaException $e) { |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
if (!$schema->hasTable('circle_remotes')) { |
111
|
|
|
$table = $schema->createTable('circle_remotes'); |
112
|
|
|
$table->addColumn( |
113
|
|
|
'id', 'integer', [ |
114
|
|
|
'autoincrement' => true, |
115
|
|
|
'notnull' => true, |
116
|
|
|
'length' => 4, |
117
|
|
|
'unsigned' => true, |
118
|
|
|
] |
119
|
|
|
); |
120
|
|
|
$table->addColumn( |
121
|
|
|
'type', 'string', [ |
122
|
|
|
'notnull' => true, |
123
|
|
|
'length' => 15, |
124
|
|
|
'default' => 'Unknown' |
125
|
|
|
] |
126
|
|
|
); |
127
|
|
|
$table->addColumn( |
128
|
|
|
'uid', 'string', [ |
129
|
|
|
'notnull' => false, |
130
|
|
|
'length' => 20, |
131
|
|
|
] |
132
|
|
|
); |
133
|
|
|
$table->addColumn( |
134
|
|
|
'instance', 'string', [ |
135
|
|
|
'notnull' => false, |
136
|
|
|
'length' => 127, |
137
|
|
|
] |
138
|
|
|
); |
139
|
|
|
$table->addColumn( |
140
|
|
|
'href', 'string', [ |
141
|
|
|
'notnull' => false, |
142
|
|
|
'length' => 254, |
143
|
|
|
] |
144
|
|
|
); |
145
|
|
|
$table->addColumn( |
146
|
|
|
'item', 'text', [ |
147
|
|
|
'notnull' => false, |
148
|
|
|
] |
149
|
|
|
); |
150
|
|
|
$table->addColumn( |
151
|
|
|
'creation', 'datetime', [ |
152
|
|
|
'notnull' => false, |
153
|
|
|
] |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$table->setPrimaryKey(['id']); |
157
|
|
|
$table->addUniqueIndex(['instance']); |
158
|
|
|
$table->addIndex(['uid']); |
159
|
|
|
$table->addIndex(['href']); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
View Code Duplication |
if (!$schema->hasTable('circle_membership')) { |
|
|
|
|
163
|
|
|
$table = $schema->createTable('circle_membership'); |
164
|
|
|
|
165
|
|
|
$table->addColumn( |
166
|
|
|
'id', 'string', [ |
167
|
|
|
'notnull' => true, |
168
|
|
|
'length' => 15, |
169
|
|
|
] |
170
|
|
|
); |
171
|
|
|
$table->addColumn( |
172
|
|
|
'circle_id', 'string', [ |
173
|
|
|
'notnull' => true, |
174
|
|
|
'length' => 15, |
175
|
|
|
] |
176
|
|
|
); |
177
|
|
|
$table->addColumn( |
178
|
|
|
'member_id', 'string', [ |
179
|
|
|
'notnull' => true, |
180
|
|
|
'length' => 15, |
181
|
|
|
] |
182
|
|
|
); |
183
|
|
|
$table->addColumn( |
184
|
|
|
'level', 'integer', [ |
185
|
|
|
'notnull' => true, |
186
|
|
|
'length' => 1, |
187
|
|
|
'unsigned' => true |
188
|
|
|
] |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
$table->addIndex(['id']); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
if (!$schema->hasTable('circle_share_locks')) { |
196
|
|
|
$table = $schema->createTable('circle_share_locks'); |
197
|
|
|
$table->addColumn( |
198
|
|
|
'id', 'integer', [ |
199
|
|
|
'autoincrement' => true, |
200
|
|
|
'notnull' => true, |
201
|
|
|
'length' => 4, |
202
|
|
|
'unsigned' => true, |
203
|
|
|
] |
204
|
|
|
); |
205
|
|
|
$table->addColumn( |
206
|
|
|
'item_id', 'string', [ |
207
|
|
|
'notnull' => true, |
208
|
|
|
'length' => 15 |
209
|
|
|
] |
210
|
|
|
); |
211
|
|
|
$table->addColumn( |
212
|
|
|
'circle_id', 'string', [ |
213
|
|
|
'notnull' => true, |
214
|
|
|
'length' => 15 |
215
|
|
|
] |
216
|
|
|
); |
217
|
|
|
$table->addColumn( |
218
|
|
|
'instance', 'string', [ |
219
|
|
|
'notnull' => true, |
220
|
|
|
'length' => 127, |
221
|
|
|
] |
222
|
|
|
); |
223
|
|
|
|
224
|
|
|
$table->setPrimaryKey(['id']); |
225
|
|
|
$table->addUniqueIndex(['item_id', 'circle_id']); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
return $schema; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
} |
233
|
|
|
|