@@ -29,30 +29,30 @@ |
||
29 | 29 | |
30 | 30 | class Version1004Date20170919104507 extends SimpleMigrationStep { |
31 | 31 | |
32 | - /** |
|
33 | - * @param IOutput $output |
|
34 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | - * @param array $options |
|
36 | - * @return null|ISchemaWrapper |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | - /** @var ISchemaWrapper $schema */ |
|
41 | - $schema = $schemaClosure(); |
|
42 | - |
|
43 | - $table = $schema->getTable('addressbooks'); |
|
44 | - $column = $table->getColumn('id'); |
|
45 | - $column->setUnsigned(true); |
|
46 | - |
|
47 | - $table = $schema->getTable('calendarobjects'); |
|
48 | - $column = $table->getColumn('id'); |
|
49 | - $column->setUnsigned(true); |
|
50 | - |
|
51 | - $table = $schema->getTable('calendarchanges'); |
|
52 | - $column = $table->getColumn('id'); |
|
53 | - $column->setUnsigned(true); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
32 | + /** |
|
33 | + * @param IOutput $output |
|
34 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | + * @param array $options |
|
36 | + * @return null|ISchemaWrapper |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | + /** @var ISchemaWrapper $schema */ |
|
41 | + $schema = $schemaClosure(); |
|
42 | + |
|
43 | + $table = $schema->getTable('addressbooks'); |
|
44 | + $column = $table->getColumn('id'); |
|
45 | + $column->setUnsigned(true); |
|
46 | + |
|
47 | + $table = $schema->getTable('calendarobjects'); |
|
48 | + $column = $table->getColumn('id'); |
|
49 | + $column->setUnsigned(true); |
|
50 | + |
|
51 | + $table = $schema->getTable('calendarchanges'); |
|
52 | + $column = $table->getColumn('id'); |
|
53 | + $column->setUnsigned(true); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -28,454 +28,454 @@ |
||
28 | 28 | use OCP\Migration\IOutput; |
29 | 29 | |
30 | 30 | class Version1004Date20170825134824 extends SimpleMigrationStep { |
31 | - /** |
|
32 | - * @param IOutput $output |
|
33 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
34 | - * @param array $options |
|
35 | - * @return null|ISchemaWrapper |
|
36 | - * @since 13.0.0 |
|
37 | - */ |
|
38 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | - /** @var ISchemaWrapper $schema */ |
|
40 | - $schema = $schemaClosure(); |
|
31 | + /** |
|
32 | + * @param IOutput $output |
|
33 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
34 | + * @param array $options |
|
35 | + * @return null|ISchemaWrapper |
|
36 | + * @since 13.0.0 |
|
37 | + */ |
|
38 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | + /** @var ISchemaWrapper $schema */ |
|
40 | + $schema = $schemaClosure(); |
|
41 | 41 | |
42 | - if (!$schema->hasTable('addressbooks')) { |
|
43 | - $table = $schema->createTable('addressbooks'); |
|
44 | - $table->addColumn('id', 'bigint', [ |
|
45 | - 'autoincrement' => true, |
|
46 | - 'notnull' => true, |
|
47 | - 'length' => 11, |
|
48 | - 'unsigned' => true, |
|
49 | - ]); |
|
50 | - $table->addColumn('principaluri', 'string', [ |
|
51 | - 'notnull' => false, |
|
52 | - 'length' => 255, |
|
53 | - ]); |
|
54 | - $table->addColumn('displayname', 'string', [ |
|
55 | - 'notnull' => false, |
|
56 | - 'length' => 255, |
|
57 | - ]); |
|
58 | - $table->addColumn('uri', 'string', [ |
|
59 | - 'notnull' => false, |
|
60 | - 'length' => 255, |
|
61 | - ]); |
|
62 | - $table->addColumn('description', 'string', [ |
|
63 | - 'notnull' => false, |
|
64 | - 'length' => 255, |
|
65 | - ]); |
|
66 | - $table->addColumn('synctoken', 'integer', [ |
|
67 | - 'notnull' => true, |
|
68 | - 'default' => 1, |
|
69 | - 'length' => 10, |
|
70 | - 'unsigned' => true, |
|
71 | - ]); |
|
72 | - $table->setPrimaryKey(['id']); |
|
73 | - $table->addUniqueIndex(['principaluri', 'uri'], 'addressbook_index'); |
|
74 | - } |
|
42 | + if (!$schema->hasTable('addressbooks')) { |
|
43 | + $table = $schema->createTable('addressbooks'); |
|
44 | + $table->addColumn('id', 'bigint', [ |
|
45 | + 'autoincrement' => true, |
|
46 | + 'notnull' => true, |
|
47 | + 'length' => 11, |
|
48 | + 'unsigned' => true, |
|
49 | + ]); |
|
50 | + $table->addColumn('principaluri', 'string', [ |
|
51 | + 'notnull' => false, |
|
52 | + 'length' => 255, |
|
53 | + ]); |
|
54 | + $table->addColumn('displayname', 'string', [ |
|
55 | + 'notnull' => false, |
|
56 | + 'length' => 255, |
|
57 | + ]); |
|
58 | + $table->addColumn('uri', 'string', [ |
|
59 | + 'notnull' => false, |
|
60 | + 'length' => 255, |
|
61 | + ]); |
|
62 | + $table->addColumn('description', 'string', [ |
|
63 | + 'notnull' => false, |
|
64 | + 'length' => 255, |
|
65 | + ]); |
|
66 | + $table->addColumn('synctoken', 'integer', [ |
|
67 | + 'notnull' => true, |
|
68 | + 'default' => 1, |
|
69 | + 'length' => 10, |
|
70 | + 'unsigned' => true, |
|
71 | + ]); |
|
72 | + $table->setPrimaryKey(['id']); |
|
73 | + $table->addUniqueIndex(['principaluri', 'uri'], 'addressbook_index'); |
|
74 | + } |
|
75 | 75 | |
76 | - if (!$schema->hasTable('cards')) { |
|
77 | - $table = $schema->createTable('cards'); |
|
78 | - $table->addColumn('id', 'bigint', [ |
|
79 | - 'autoincrement' => true, |
|
80 | - 'notnull' => true, |
|
81 | - 'length' => 11, |
|
82 | - 'unsigned' => true, |
|
83 | - ]); |
|
84 | - $table->addColumn('addressbookid', 'integer', [ |
|
85 | - 'notnull' => true, |
|
86 | - 'default' => 0, |
|
87 | - ]); |
|
88 | - $table->addColumn('carddata', 'blob', [ |
|
89 | - 'notnull' => false, |
|
90 | - ]); |
|
91 | - $table->addColumn('uri', 'string', [ |
|
92 | - 'notnull' => false, |
|
93 | - 'length' => 255, |
|
94 | - ]); |
|
95 | - $table->addColumn('lastmodified', 'bigint', [ |
|
96 | - 'notnull' => false, |
|
97 | - 'length' => 11, |
|
98 | - 'unsigned' => true, |
|
99 | - ]); |
|
100 | - $table->addColumn('etag', 'string', [ |
|
101 | - 'notnull' => false, |
|
102 | - 'length' => 32, |
|
103 | - ]); |
|
104 | - $table->addColumn('size', 'bigint', [ |
|
105 | - 'notnull' => true, |
|
106 | - 'length' => 11, |
|
107 | - 'unsigned' => true, |
|
108 | - ]); |
|
109 | - $table->setPrimaryKey(['id']); |
|
110 | - } |
|
76 | + if (!$schema->hasTable('cards')) { |
|
77 | + $table = $schema->createTable('cards'); |
|
78 | + $table->addColumn('id', 'bigint', [ |
|
79 | + 'autoincrement' => true, |
|
80 | + 'notnull' => true, |
|
81 | + 'length' => 11, |
|
82 | + 'unsigned' => true, |
|
83 | + ]); |
|
84 | + $table->addColumn('addressbookid', 'integer', [ |
|
85 | + 'notnull' => true, |
|
86 | + 'default' => 0, |
|
87 | + ]); |
|
88 | + $table->addColumn('carddata', 'blob', [ |
|
89 | + 'notnull' => false, |
|
90 | + ]); |
|
91 | + $table->addColumn('uri', 'string', [ |
|
92 | + 'notnull' => false, |
|
93 | + 'length' => 255, |
|
94 | + ]); |
|
95 | + $table->addColumn('lastmodified', 'bigint', [ |
|
96 | + 'notnull' => false, |
|
97 | + 'length' => 11, |
|
98 | + 'unsigned' => true, |
|
99 | + ]); |
|
100 | + $table->addColumn('etag', 'string', [ |
|
101 | + 'notnull' => false, |
|
102 | + 'length' => 32, |
|
103 | + ]); |
|
104 | + $table->addColumn('size', 'bigint', [ |
|
105 | + 'notnull' => true, |
|
106 | + 'length' => 11, |
|
107 | + 'unsigned' => true, |
|
108 | + ]); |
|
109 | + $table->setPrimaryKey(['id']); |
|
110 | + } |
|
111 | 111 | |
112 | - if (!$schema->hasTable('addressbookchanges')) { |
|
113 | - $table = $schema->createTable('addressbookchanges'); |
|
114 | - $table->addColumn('id', 'bigint', [ |
|
115 | - 'autoincrement' => true, |
|
116 | - 'notnull' => true, |
|
117 | - 'length' => 11, |
|
118 | - 'unsigned' => true, |
|
119 | - ]); |
|
120 | - $table->addColumn('uri', 'string', [ |
|
121 | - 'notnull' => false, |
|
122 | - 'length' => 255, |
|
123 | - ]); |
|
124 | - $table->addColumn('synctoken', 'integer', [ |
|
125 | - 'notnull' => true, |
|
126 | - 'default' => 1, |
|
127 | - 'length' => 10, |
|
128 | - 'unsigned' => true, |
|
129 | - ]); |
|
130 | - $table->addColumn('addressbookid', 'integer', [ |
|
131 | - 'notnull' => true, |
|
132 | - ]); |
|
133 | - $table->addColumn('operation', 'smallint', [ |
|
134 | - 'notnull' => true, |
|
135 | - 'length' => 1, |
|
136 | - ]); |
|
137 | - $table->setPrimaryKey(['id']); |
|
138 | - $table->addIndex(['addressbookid', 'synctoken'], 'addressbookid_synctoken'); |
|
139 | - } |
|
112 | + if (!$schema->hasTable('addressbookchanges')) { |
|
113 | + $table = $schema->createTable('addressbookchanges'); |
|
114 | + $table->addColumn('id', 'bigint', [ |
|
115 | + 'autoincrement' => true, |
|
116 | + 'notnull' => true, |
|
117 | + 'length' => 11, |
|
118 | + 'unsigned' => true, |
|
119 | + ]); |
|
120 | + $table->addColumn('uri', 'string', [ |
|
121 | + 'notnull' => false, |
|
122 | + 'length' => 255, |
|
123 | + ]); |
|
124 | + $table->addColumn('synctoken', 'integer', [ |
|
125 | + 'notnull' => true, |
|
126 | + 'default' => 1, |
|
127 | + 'length' => 10, |
|
128 | + 'unsigned' => true, |
|
129 | + ]); |
|
130 | + $table->addColumn('addressbookid', 'integer', [ |
|
131 | + 'notnull' => true, |
|
132 | + ]); |
|
133 | + $table->addColumn('operation', 'smallint', [ |
|
134 | + 'notnull' => true, |
|
135 | + 'length' => 1, |
|
136 | + ]); |
|
137 | + $table->setPrimaryKey(['id']); |
|
138 | + $table->addIndex(['addressbookid', 'synctoken'], 'addressbookid_synctoken'); |
|
139 | + } |
|
140 | 140 | |
141 | - if (!$schema->hasTable('calendarobjects')) { |
|
142 | - $table = $schema->createTable('calendarobjects'); |
|
143 | - $table->addColumn('id', 'bigint', [ |
|
144 | - 'autoincrement' => true, |
|
145 | - 'notnull' => true, |
|
146 | - 'length' => 11, |
|
147 | - 'unsigned' => true, |
|
148 | - ]); |
|
149 | - $table->addColumn('calendardata', 'blob', [ |
|
150 | - 'notnull' => false, |
|
151 | - ]); |
|
152 | - $table->addColumn('uri', 'string', [ |
|
153 | - 'notnull' => false, |
|
154 | - 'length' => 255, |
|
155 | - ]); |
|
156 | - $table->addColumn('calendarid', 'integer', [ |
|
157 | - 'notnull' => true, |
|
158 | - 'length' => 10, |
|
159 | - 'unsigned' => true, |
|
160 | - ]); |
|
161 | - $table->addColumn('lastmodified', 'integer', [ |
|
162 | - 'notnull' => false, |
|
163 | - 'length' => 10, |
|
164 | - 'unsigned' => true, |
|
165 | - ]); |
|
166 | - $table->addColumn('etag', 'string', [ |
|
167 | - 'notnull' => false, |
|
168 | - 'length' => 32, |
|
169 | - ]); |
|
170 | - $table->addColumn('size', 'bigint', [ |
|
171 | - 'notnull' => true, |
|
172 | - 'length' => 11, |
|
173 | - 'unsigned' => true, |
|
174 | - ]); |
|
175 | - $table->addColumn('componenttype', 'string', [ |
|
176 | - 'notnull' => false, |
|
177 | - 'length' => 8, |
|
178 | - ]); |
|
179 | - $table->addColumn('firstoccurence', 'bigint', [ |
|
180 | - 'notnull' => false, |
|
181 | - 'length' => 11, |
|
182 | - 'unsigned' => true, |
|
183 | - ]); |
|
184 | - $table->addColumn('lastoccurence', 'bigint', [ |
|
185 | - 'notnull' => false, |
|
186 | - 'length' => 11, |
|
187 | - 'unsigned' => true, |
|
188 | - ]); |
|
189 | - $table->addColumn('uid', 'string', [ |
|
190 | - 'notnull' => false, |
|
191 | - 'length' => 255, |
|
192 | - ]); |
|
193 | - $table->addColumn('classification', 'integer', [ |
|
194 | - 'notnull' => false, |
|
195 | - 'default' => 0, |
|
196 | - ]); |
|
197 | - $table->setPrimaryKey(['id']); |
|
198 | - $table->addUniqueIndex(['calendarid', 'uri'], 'calobjects_index'); |
|
199 | - } |
|
141 | + if (!$schema->hasTable('calendarobjects')) { |
|
142 | + $table = $schema->createTable('calendarobjects'); |
|
143 | + $table->addColumn('id', 'bigint', [ |
|
144 | + 'autoincrement' => true, |
|
145 | + 'notnull' => true, |
|
146 | + 'length' => 11, |
|
147 | + 'unsigned' => true, |
|
148 | + ]); |
|
149 | + $table->addColumn('calendardata', 'blob', [ |
|
150 | + 'notnull' => false, |
|
151 | + ]); |
|
152 | + $table->addColumn('uri', 'string', [ |
|
153 | + 'notnull' => false, |
|
154 | + 'length' => 255, |
|
155 | + ]); |
|
156 | + $table->addColumn('calendarid', 'integer', [ |
|
157 | + 'notnull' => true, |
|
158 | + 'length' => 10, |
|
159 | + 'unsigned' => true, |
|
160 | + ]); |
|
161 | + $table->addColumn('lastmodified', 'integer', [ |
|
162 | + 'notnull' => false, |
|
163 | + 'length' => 10, |
|
164 | + 'unsigned' => true, |
|
165 | + ]); |
|
166 | + $table->addColumn('etag', 'string', [ |
|
167 | + 'notnull' => false, |
|
168 | + 'length' => 32, |
|
169 | + ]); |
|
170 | + $table->addColumn('size', 'bigint', [ |
|
171 | + 'notnull' => true, |
|
172 | + 'length' => 11, |
|
173 | + 'unsigned' => true, |
|
174 | + ]); |
|
175 | + $table->addColumn('componenttype', 'string', [ |
|
176 | + 'notnull' => false, |
|
177 | + 'length' => 8, |
|
178 | + ]); |
|
179 | + $table->addColumn('firstoccurence', 'bigint', [ |
|
180 | + 'notnull' => false, |
|
181 | + 'length' => 11, |
|
182 | + 'unsigned' => true, |
|
183 | + ]); |
|
184 | + $table->addColumn('lastoccurence', 'bigint', [ |
|
185 | + 'notnull' => false, |
|
186 | + 'length' => 11, |
|
187 | + 'unsigned' => true, |
|
188 | + ]); |
|
189 | + $table->addColumn('uid', 'string', [ |
|
190 | + 'notnull' => false, |
|
191 | + 'length' => 255, |
|
192 | + ]); |
|
193 | + $table->addColumn('classification', 'integer', [ |
|
194 | + 'notnull' => false, |
|
195 | + 'default' => 0, |
|
196 | + ]); |
|
197 | + $table->setPrimaryKey(['id']); |
|
198 | + $table->addUniqueIndex(['calendarid', 'uri'], 'calobjects_index'); |
|
199 | + } |
|
200 | 200 | |
201 | - if (!$schema->hasTable('calendars')) { |
|
202 | - $table = $schema->createTable('calendars'); |
|
203 | - $table->addColumn('id', 'bigint', [ |
|
204 | - 'autoincrement' => true, |
|
205 | - 'notnull' => true, |
|
206 | - 'length' => 11, |
|
207 | - 'unsigned' => true, |
|
208 | - ]); |
|
209 | - $table->addColumn('principaluri', 'string', [ |
|
210 | - 'notnull' => false, |
|
211 | - 'length' => 255, |
|
212 | - ]); |
|
213 | - $table->addColumn('displayname', 'string', [ |
|
214 | - 'notnull' => false, |
|
215 | - 'length' => 255, |
|
216 | - ]); |
|
217 | - $table->addColumn('uri', 'string', [ |
|
218 | - 'notnull' => false, |
|
219 | - 'length' => 255, |
|
220 | - ]); |
|
221 | - $table->addColumn('synctoken', 'integer', [ |
|
222 | - 'notnull' => true, |
|
223 | - 'default' => 1, |
|
224 | - 'unsigned' => true, |
|
225 | - ]); |
|
226 | - $table->addColumn('description', 'string', [ |
|
227 | - 'notnull' => false, |
|
228 | - 'length' => 255, |
|
229 | - ]); |
|
230 | - $table->addColumn('calendarorder', 'integer', [ |
|
231 | - 'notnull' => true, |
|
232 | - 'default' => 0, |
|
233 | - 'unsigned' => true, |
|
234 | - ]); |
|
235 | - $table->addColumn('calendarcolor', 'string', [ |
|
236 | - 'notnull' => false, |
|
237 | - ]); |
|
238 | - $table->addColumn('timezone', 'text', [ |
|
239 | - 'notnull' => false, |
|
240 | - ]); |
|
241 | - $table->addColumn('components', 'string', [ |
|
242 | - 'notnull' => false, |
|
243 | - 'length' => 64, |
|
244 | - ]); |
|
245 | - $table->addColumn('transparent', 'smallint', [ |
|
246 | - 'notnull' => true, |
|
247 | - 'length' => 1, |
|
248 | - 'default' => 0, |
|
249 | - ]); |
|
250 | - $table->setPrimaryKey(['id']); |
|
251 | - $table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index'); |
|
252 | - } |
|
201 | + if (!$schema->hasTable('calendars')) { |
|
202 | + $table = $schema->createTable('calendars'); |
|
203 | + $table->addColumn('id', 'bigint', [ |
|
204 | + 'autoincrement' => true, |
|
205 | + 'notnull' => true, |
|
206 | + 'length' => 11, |
|
207 | + 'unsigned' => true, |
|
208 | + ]); |
|
209 | + $table->addColumn('principaluri', 'string', [ |
|
210 | + 'notnull' => false, |
|
211 | + 'length' => 255, |
|
212 | + ]); |
|
213 | + $table->addColumn('displayname', 'string', [ |
|
214 | + 'notnull' => false, |
|
215 | + 'length' => 255, |
|
216 | + ]); |
|
217 | + $table->addColumn('uri', 'string', [ |
|
218 | + 'notnull' => false, |
|
219 | + 'length' => 255, |
|
220 | + ]); |
|
221 | + $table->addColumn('synctoken', 'integer', [ |
|
222 | + 'notnull' => true, |
|
223 | + 'default' => 1, |
|
224 | + 'unsigned' => true, |
|
225 | + ]); |
|
226 | + $table->addColumn('description', 'string', [ |
|
227 | + 'notnull' => false, |
|
228 | + 'length' => 255, |
|
229 | + ]); |
|
230 | + $table->addColumn('calendarorder', 'integer', [ |
|
231 | + 'notnull' => true, |
|
232 | + 'default' => 0, |
|
233 | + 'unsigned' => true, |
|
234 | + ]); |
|
235 | + $table->addColumn('calendarcolor', 'string', [ |
|
236 | + 'notnull' => false, |
|
237 | + ]); |
|
238 | + $table->addColumn('timezone', 'text', [ |
|
239 | + 'notnull' => false, |
|
240 | + ]); |
|
241 | + $table->addColumn('components', 'string', [ |
|
242 | + 'notnull' => false, |
|
243 | + 'length' => 64, |
|
244 | + ]); |
|
245 | + $table->addColumn('transparent', 'smallint', [ |
|
246 | + 'notnull' => true, |
|
247 | + 'length' => 1, |
|
248 | + 'default' => 0, |
|
249 | + ]); |
|
250 | + $table->setPrimaryKey(['id']); |
|
251 | + $table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index'); |
|
252 | + } |
|
253 | 253 | |
254 | - if (!$schema->hasTable('calendarchanges')) { |
|
255 | - $table = $schema->createTable('calendarchanges'); |
|
256 | - $table->addColumn('id', 'bigint', [ |
|
257 | - 'autoincrement' => true, |
|
258 | - 'notnull' => true, |
|
259 | - 'length' => 11, |
|
260 | - 'unsigned' => true, |
|
261 | - ]); |
|
262 | - $table->addColumn('uri', 'string', [ |
|
263 | - 'notnull' => false, |
|
264 | - 'length' => 255, |
|
265 | - ]); |
|
266 | - $table->addColumn('synctoken', 'integer', [ |
|
267 | - 'notnull' => true, |
|
268 | - 'default' => 1, |
|
269 | - 'length' => 10, |
|
270 | - 'unsigned' => true, |
|
271 | - ]); |
|
272 | - $table->addColumn('calendarid', 'integer', [ |
|
273 | - 'notnull' => true, |
|
274 | - ]); |
|
275 | - $table->addColumn('operation', 'smallint', [ |
|
276 | - 'notnull' => true, |
|
277 | - 'length' => 1, |
|
278 | - ]); |
|
279 | - $table->setPrimaryKey(['id']); |
|
280 | - $table->addIndex(['calendarid', 'synctoken'], 'calendarid_synctoken'); |
|
281 | - } |
|
254 | + if (!$schema->hasTable('calendarchanges')) { |
|
255 | + $table = $schema->createTable('calendarchanges'); |
|
256 | + $table->addColumn('id', 'bigint', [ |
|
257 | + 'autoincrement' => true, |
|
258 | + 'notnull' => true, |
|
259 | + 'length' => 11, |
|
260 | + 'unsigned' => true, |
|
261 | + ]); |
|
262 | + $table->addColumn('uri', 'string', [ |
|
263 | + 'notnull' => false, |
|
264 | + 'length' => 255, |
|
265 | + ]); |
|
266 | + $table->addColumn('synctoken', 'integer', [ |
|
267 | + 'notnull' => true, |
|
268 | + 'default' => 1, |
|
269 | + 'length' => 10, |
|
270 | + 'unsigned' => true, |
|
271 | + ]); |
|
272 | + $table->addColumn('calendarid', 'integer', [ |
|
273 | + 'notnull' => true, |
|
274 | + ]); |
|
275 | + $table->addColumn('operation', 'smallint', [ |
|
276 | + 'notnull' => true, |
|
277 | + 'length' => 1, |
|
278 | + ]); |
|
279 | + $table->setPrimaryKey(['id']); |
|
280 | + $table->addIndex(['calendarid', 'synctoken'], 'calendarid_synctoken'); |
|
281 | + } |
|
282 | 282 | |
283 | - if (!$schema->hasTable('calendarsubscriptions')) { |
|
284 | - $table = $schema->createTable('calendarsubscriptions'); |
|
285 | - $table->addColumn('id', 'bigint', [ |
|
286 | - 'autoincrement' => true, |
|
287 | - 'notnull' => true, |
|
288 | - 'length' => 11, |
|
289 | - 'unsigned' => true, |
|
290 | - ]); |
|
291 | - $table->addColumn('uri', 'string', [ |
|
292 | - 'notnull' => false, |
|
293 | - ]); |
|
294 | - $table->addColumn('principaluri', 'string', [ |
|
295 | - 'notnull' => false, |
|
296 | - 'length' => 255, |
|
297 | - ]); |
|
298 | - $table->addColumn('source', 'string', [ |
|
299 | - 'notnull' => false, |
|
300 | - 'length' => 255, |
|
301 | - ]); |
|
302 | - $table->addColumn('displayname', 'string', [ |
|
303 | - 'notnull' => false, |
|
304 | - 'length' => 100, |
|
305 | - ]); |
|
306 | - $table->addColumn('refreshrate', 'string', [ |
|
307 | - 'notnull' => false, |
|
308 | - 'length' => 10, |
|
309 | - ]); |
|
310 | - $table->addColumn('calendarorder', 'integer', [ |
|
311 | - 'notnull' => true, |
|
312 | - 'default' => 0, |
|
313 | - 'unsigned' => true, |
|
314 | - ]); |
|
315 | - $table->addColumn('calendarcolor', 'string', [ |
|
316 | - 'notnull' => false, |
|
317 | - ]); |
|
318 | - $table->addColumn('striptodos', 'smallint', [ |
|
319 | - 'notnull' => false, |
|
320 | - 'length' => 1, |
|
321 | - ]); |
|
322 | - $table->addColumn('stripalarms', 'smallint', [ |
|
323 | - 'notnull' => false, |
|
324 | - 'length' => 1, |
|
325 | - ]); |
|
326 | - $table->addColumn('stripattachments', 'smallint', [ |
|
327 | - 'notnull' => false, |
|
328 | - 'length' => 1, |
|
329 | - ]); |
|
330 | - $table->addColumn('lastmodified', 'integer', [ |
|
331 | - 'notnull' => false, |
|
332 | - 'unsigned' => true, |
|
333 | - ]); |
|
334 | - $table->setPrimaryKey(['id']); |
|
335 | - $table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index'); |
|
336 | - } |
|
283 | + if (!$schema->hasTable('calendarsubscriptions')) { |
|
284 | + $table = $schema->createTable('calendarsubscriptions'); |
|
285 | + $table->addColumn('id', 'bigint', [ |
|
286 | + 'autoincrement' => true, |
|
287 | + 'notnull' => true, |
|
288 | + 'length' => 11, |
|
289 | + 'unsigned' => true, |
|
290 | + ]); |
|
291 | + $table->addColumn('uri', 'string', [ |
|
292 | + 'notnull' => false, |
|
293 | + ]); |
|
294 | + $table->addColumn('principaluri', 'string', [ |
|
295 | + 'notnull' => false, |
|
296 | + 'length' => 255, |
|
297 | + ]); |
|
298 | + $table->addColumn('source', 'string', [ |
|
299 | + 'notnull' => false, |
|
300 | + 'length' => 255, |
|
301 | + ]); |
|
302 | + $table->addColumn('displayname', 'string', [ |
|
303 | + 'notnull' => false, |
|
304 | + 'length' => 100, |
|
305 | + ]); |
|
306 | + $table->addColumn('refreshrate', 'string', [ |
|
307 | + 'notnull' => false, |
|
308 | + 'length' => 10, |
|
309 | + ]); |
|
310 | + $table->addColumn('calendarorder', 'integer', [ |
|
311 | + 'notnull' => true, |
|
312 | + 'default' => 0, |
|
313 | + 'unsigned' => true, |
|
314 | + ]); |
|
315 | + $table->addColumn('calendarcolor', 'string', [ |
|
316 | + 'notnull' => false, |
|
317 | + ]); |
|
318 | + $table->addColumn('striptodos', 'smallint', [ |
|
319 | + 'notnull' => false, |
|
320 | + 'length' => 1, |
|
321 | + ]); |
|
322 | + $table->addColumn('stripalarms', 'smallint', [ |
|
323 | + 'notnull' => false, |
|
324 | + 'length' => 1, |
|
325 | + ]); |
|
326 | + $table->addColumn('stripattachments', 'smallint', [ |
|
327 | + 'notnull' => false, |
|
328 | + 'length' => 1, |
|
329 | + ]); |
|
330 | + $table->addColumn('lastmodified', 'integer', [ |
|
331 | + 'notnull' => false, |
|
332 | + 'unsigned' => true, |
|
333 | + ]); |
|
334 | + $table->setPrimaryKey(['id']); |
|
335 | + $table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index'); |
|
336 | + } |
|
337 | 337 | |
338 | - if (!$schema->hasTable('schedulingobjects')) { |
|
339 | - $table = $schema->createTable('schedulingobjects'); |
|
340 | - $table->addColumn('id', 'bigint', [ |
|
341 | - 'autoincrement' => true, |
|
342 | - 'notnull' => true, |
|
343 | - 'length' => 11, |
|
344 | - 'unsigned' => true, |
|
345 | - ]); |
|
346 | - $table->addColumn('principaluri', 'string', [ |
|
347 | - 'notnull' => false, |
|
348 | - 'length' => 255, |
|
349 | - ]); |
|
350 | - $table->addColumn('calendardata', 'blob', [ |
|
351 | - 'notnull' => false, |
|
352 | - ]); |
|
353 | - $table->addColumn('uri', 'string', [ |
|
354 | - 'notnull' => false, |
|
355 | - 'length' => 255, |
|
356 | - ]); |
|
357 | - $table->addColumn('lastmodified', 'integer', [ |
|
358 | - 'notnull' => false, |
|
359 | - 'unsigned' => true, |
|
360 | - ]); |
|
361 | - $table->addColumn('etag', 'string', [ |
|
362 | - 'notnull' => false, |
|
363 | - 'length' => 32, |
|
364 | - ]); |
|
365 | - $table->addColumn('size', 'bigint', [ |
|
366 | - 'notnull' => true, |
|
367 | - 'length' => 11, |
|
368 | - 'unsigned' => true, |
|
369 | - ]); |
|
370 | - $table->setPrimaryKey(['id']); |
|
371 | - } |
|
338 | + if (!$schema->hasTable('schedulingobjects')) { |
|
339 | + $table = $schema->createTable('schedulingobjects'); |
|
340 | + $table->addColumn('id', 'bigint', [ |
|
341 | + 'autoincrement' => true, |
|
342 | + 'notnull' => true, |
|
343 | + 'length' => 11, |
|
344 | + 'unsigned' => true, |
|
345 | + ]); |
|
346 | + $table->addColumn('principaluri', 'string', [ |
|
347 | + 'notnull' => false, |
|
348 | + 'length' => 255, |
|
349 | + ]); |
|
350 | + $table->addColumn('calendardata', 'blob', [ |
|
351 | + 'notnull' => false, |
|
352 | + ]); |
|
353 | + $table->addColumn('uri', 'string', [ |
|
354 | + 'notnull' => false, |
|
355 | + 'length' => 255, |
|
356 | + ]); |
|
357 | + $table->addColumn('lastmodified', 'integer', [ |
|
358 | + 'notnull' => false, |
|
359 | + 'unsigned' => true, |
|
360 | + ]); |
|
361 | + $table->addColumn('etag', 'string', [ |
|
362 | + 'notnull' => false, |
|
363 | + 'length' => 32, |
|
364 | + ]); |
|
365 | + $table->addColumn('size', 'bigint', [ |
|
366 | + 'notnull' => true, |
|
367 | + 'length' => 11, |
|
368 | + 'unsigned' => true, |
|
369 | + ]); |
|
370 | + $table->setPrimaryKey(['id']); |
|
371 | + } |
|
372 | 372 | |
373 | - if (!$schema->hasTable('cards_properties')) { |
|
374 | - $table = $schema->createTable('cards_properties'); |
|
375 | - $table->addColumn('id', 'bigint', [ |
|
376 | - 'autoincrement' => true, |
|
377 | - 'notnull' => true, |
|
378 | - 'length' => 11, |
|
379 | - 'unsigned' => true, |
|
380 | - ]); |
|
381 | - $table->addColumn('addressbookid', 'bigint', [ |
|
382 | - 'notnull' => true, |
|
383 | - 'length' => 11, |
|
384 | - 'default' => 0, |
|
385 | - ]); |
|
386 | - $table->addColumn('cardid', 'bigint', [ |
|
387 | - 'notnull' => true, |
|
388 | - 'length' => 11, |
|
389 | - 'default' => 0, |
|
390 | - 'unsigned' => true, |
|
391 | - ]); |
|
392 | - $table->addColumn('name', 'string', [ |
|
393 | - 'notnull' => false, |
|
394 | - 'length' => 64, |
|
395 | - ]); |
|
396 | - $table->addColumn('value', 'string', [ |
|
397 | - 'notnull' => false, |
|
398 | - 'length' => 255, |
|
399 | - ]); |
|
400 | - $table->addColumn('preferred', 'integer', [ |
|
401 | - 'notnull' => true, |
|
402 | - 'length' => 4, |
|
403 | - 'default' => 1, |
|
404 | - ]); |
|
405 | - $table->setPrimaryKey(['id']); |
|
406 | - $table->addIndex(['cardid'], 'card_contactid_index'); |
|
407 | - $table->addIndex(['name'], 'card_name_index'); |
|
408 | - $table->addIndex(['value'], 'card_value_index'); |
|
409 | - } |
|
373 | + if (!$schema->hasTable('cards_properties')) { |
|
374 | + $table = $schema->createTable('cards_properties'); |
|
375 | + $table->addColumn('id', 'bigint', [ |
|
376 | + 'autoincrement' => true, |
|
377 | + 'notnull' => true, |
|
378 | + 'length' => 11, |
|
379 | + 'unsigned' => true, |
|
380 | + ]); |
|
381 | + $table->addColumn('addressbookid', 'bigint', [ |
|
382 | + 'notnull' => true, |
|
383 | + 'length' => 11, |
|
384 | + 'default' => 0, |
|
385 | + ]); |
|
386 | + $table->addColumn('cardid', 'bigint', [ |
|
387 | + 'notnull' => true, |
|
388 | + 'length' => 11, |
|
389 | + 'default' => 0, |
|
390 | + 'unsigned' => true, |
|
391 | + ]); |
|
392 | + $table->addColumn('name', 'string', [ |
|
393 | + 'notnull' => false, |
|
394 | + 'length' => 64, |
|
395 | + ]); |
|
396 | + $table->addColumn('value', 'string', [ |
|
397 | + 'notnull' => false, |
|
398 | + 'length' => 255, |
|
399 | + ]); |
|
400 | + $table->addColumn('preferred', 'integer', [ |
|
401 | + 'notnull' => true, |
|
402 | + 'length' => 4, |
|
403 | + 'default' => 1, |
|
404 | + ]); |
|
405 | + $table->setPrimaryKey(['id']); |
|
406 | + $table->addIndex(['cardid'], 'card_contactid_index'); |
|
407 | + $table->addIndex(['name'], 'card_name_index'); |
|
408 | + $table->addIndex(['value'], 'card_value_index'); |
|
409 | + } |
|
410 | 410 | |
411 | - if (!$schema->hasTable('calendarobjects_props')) { |
|
412 | - $table = $schema->createTable('calendarobjects_props'); |
|
413 | - $table->addColumn('id', 'bigint', [ |
|
414 | - 'autoincrement' => true, |
|
415 | - 'notnull' => true, |
|
416 | - 'length' => 11, |
|
417 | - 'unsigned' => true, |
|
418 | - ]); |
|
419 | - $table->addColumn('calendarid', 'bigint', [ |
|
420 | - 'notnull' => true, |
|
421 | - 'length' => 11, |
|
422 | - 'default' => 0, |
|
423 | - ]); |
|
424 | - $table->addColumn('objectid', 'bigint', [ |
|
425 | - 'notnull' => true, |
|
426 | - 'length' => 11, |
|
427 | - 'default' => 0, |
|
428 | - 'unsigned' => true, |
|
429 | - ]); |
|
430 | - $table->addColumn('name', 'string', [ |
|
431 | - 'notnull' => false, |
|
432 | - 'length' => 64, |
|
433 | - ]); |
|
434 | - $table->addColumn('parameter', 'string', [ |
|
435 | - 'notnull' => false, |
|
436 | - 'length' => 64, |
|
437 | - ]); |
|
438 | - $table->addColumn('value', 'string', [ |
|
439 | - 'notnull' => false, |
|
440 | - 'length' => 255, |
|
441 | - ]); |
|
442 | - $table->setPrimaryKey(['id']); |
|
443 | - $table->addIndex(['objectid'], 'calendarobject_index'); |
|
444 | - $table->addIndex(['name'], 'calendarobject_name_index'); |
|
445 | - $table->addIndex(['value'], 'calendarobject_value_index'); |
|
446 | - } |
|
411 | + if (!$schema->hasTable('calendarobjects_props')) { |
|
412 | + $table = $schema->createTable('calendarobjects_props'); |
|
413 | + $table->addColumn('id', 'bigint', [ |
|
414 | + 'autoincrement' => true, |
|
415 | + 'notnull' => true, |
|
416 | + 'length' => 11, |
|
417 | + 'unsigned' => true, |
|
418 | + ]); |
|
419 | + $table->addColumn('calendarid', 'bigint', [ |
|
420 | + 'notnull' => true, |
|
421 | + 'length' => 11, |
|
422 | + 'default' => 0, |
|
423 | + ]); |
|
424 | + $table->addColumn('objectid', 'bigint', [ |
|
425 | + 'notnull' => true, |
|
426 | + 'length' => 11, |
|
427 | + 'default' => 0, |
|
428 | + 'unsigned' => true, |
|
429 | + ]); |
|
430 | + $table->addColumn('name', 'string', [ |
|
431 | + 'notnull' => false, |
|
432 | + 'length' => 64, |
|
433 | + ]); |
|
434 | + $table->addColumn('parameter', 'string', [ |
|
435 | + 'notnull' => false, |
|
436 | + 'length' => 64, |
|
437 | + ]); |
|
438 | + $table->addColumn('value', 'string', [ |
|
439 | + 'notnull' => false, |
|
440 | + 'length' => 255, |
|
441 | + ]); |
|
442 | + $table->setPrimaryKey(['id']); |
|
443 | + $table->addIndex(['objectid'], 'calendarobject_index'); |
|
444 | + $table->addIndex(['name'], 'calendarobject_name_index'); |
|
445 | + $table->addIndex(['value'], 'calendarobject_value_index'); |
|
446 | + } |
|
447 | 447 | |
448 | - if (!$schema->hasTable('dav_shares')) { |
|
449 | - $table = $schema->createTable('dav_shares'); |
|
450 | - $table->addColumn('id', 'bigint', [ |
|
451 | - 'autoincrement' => true, |
|
452 | - 'notnull' => true, |
|
453 | - 'length' => 11, |
|
454 | - 'unsigned' => true, |
|
455 | - ]); |
|
456 | - $table->addColumn('principaluri', 'string', [ |
|
457 | - 'notnull' => false, |
|
458 | - 'length' => 255, |
|
459 | - ]); |
|
460 | - $table->addColumn('type', 'string', [ |
|
461 | - 'notnull' => false, |
|
462 | - 'length' => 255, |
|
463 | - ]); |
|
464 | - $table->addColumn('access', 'smallint', [ |
|
465 | - 'notnull' => false, |
|
466 | - 'length' => 1, |
|
467 | - ]); |
|
468 | - $table->addColumn('resourceid', 'integer', [ |
|
469 | - 'notnull' => true, |
|
470 | - 'unsigned' => true, |
|
471 | - ]); |
|
472 | - $table->addColumn('publicuri', 'string', [ |
|
473 | - 'notnull' => false, |
|
474 | - 'length' => 255, |
|
475 | - ]); |
|
476 | - $table->setPrimaryKey(['id']); |
|
477 | - $table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index'); |
|
478 | - } |
|
479 | - return $schema; |
|
480 | - } |
|
448 | + if (!$schema->hasTable('dav_shares')) { |
|
449 | + $table = $schema->createTable('dav_shares'); |
|
450 | + $table->addColumn('id', 'bigint', [ |
|
451 | + 'autoincrement' => true, |
|
452 | + 'notnull' => true, |
|
453 | + 'length' => 11, |
|
454 | + 'unsigned' => true, |
|
455 | + ]); |
|
456 | + $table->addColumn('principaluri', 'string', [ |
|
457 | + 'notnull' => false, |
|
458 | + 'length' => 255, |
|
459 | + ]); |
|
460 | + $table->addColumn('type', 'string', [ |
|
461 | + 'notnull' => false, |
|
462 | + 'length' => 255, |
|
463 | + ]); |
|
464 | + $table->addColumn('access', 'smallint', [ |
|
465 | + 'notnull' => false, |
|
466 | + 'length' => 1, |
|
467 | + ]); |
|
468 | + $table->addColumn('resourceid', 'integer', [ |
|
469 | + 'notnull' => true, |
|
470 | + 'unsigned' => true, |
|
471 | + ]); |
|
472 | + $table->addColumn('publicuri', 'string', [ |
|
473 | + 'notnull' => false, |
|
474 | + 'length' => 255, |
|
475 | + ]); |
|
476 | + $table->setPrimaryKey(['id']); |
|
477 | + $table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index'); |
|
478 | + } |
|
479 | + return $schema; |
|
480 | + } |
|
481 | 481 | } |
@@ -30,107 +30,107 @@ |
||
30 | 30 | |
31 | 31 | class SchemaWrapper implements ISchemaWrapper { |
32 | 32 | |
33 | - /** @var IDBConnection|Connection */ |
|
34 | - protected $connection; |
|
35 | - |
|
36 | - /** @var Schema */ |
|
37 | - protected $schema; |
|
38 | - |
|
39 | - /** @var array */ |
|
40 | - protected $tablesToDelete = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IDBConnection $connection |
|
44 | - */ |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - $this->schema = $this->connection->createSchema(); |
|
48 | - } |
|
49 | - |
|
50 | - public function getWrappedSchema() { |
|
51 | - return $this->schema; |
|
52 | - } |
|
53 | - |
|
54 | - public function performDropTableCalls() { |
|
55 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | - $this->connection->dropTable($tableName); |
|
57 | - unset($this->tablesToDelete[$tableName]); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Gets all table names |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getTableNamesWithoutPrefix() { |
|
67 | - $tableNames = $this->schema->getTableNames(); |
|
68 | - return array_map(function($tableName) { |
|
69 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | - } |
|
72 | - |
|
73 | - return $tableName; |
|
74 | - }, $tableNames); |
|
75 | - } |
|
76 | - |
|
77 | - // Overwritten methods |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getTableNames() { |
|
83 | - return $this->schema->getTableNames(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $tableName |
|
88 | - * |
|
89 | - * @return \Doctrine\DBAL\Schema\Table |
|
90 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | - */ |
|
92 | - public function getTable($tableName) { |
|
93 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Does this schema have a table with the given name? |
|
98 | - * |
|
99 | - * @param string $tableName |
|
100 | - * |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function hasTable($tableName) { |
|
104 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Creates a new table. |
|
109 | - * |
|
110 | - * @param string $tableName |
|
111 | - * @return \Doctrine\DBAL\Schema\Table |
|
112 | - */ |
|
113 | - public function createTable($tableName) { |
|
114 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Drops a table from the schema. |
|
119 | - * |
|
120 | - * @param string $tableName |
|
121 | - * @return \Doctrine\DBAL\Schema\Schema |
|
122 | - */ |
|
123 | - public function dropTable($tableName) { |
|
124 | - $this->tablesToDelete[$tableName] = true; |
|
125 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets all tables of this schema. |
|
130 | - * |
|
131 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | - */ |
|
133 | - public function getTables() { |
|
134 | - return $this->schema->getTables(); |
|
135 | - } |
|
33 | + /** @var IDBConnection|Connection */ |
|
34 | + protected $connection; |
|
35 | + |
|
36 | + /** @var Schema */ |
|
37 | + protected $schema; |
|
38 | + |
|
39 | + /** @var array */ |
|
40 | + protected $tablesToDelete = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IDBConnection $connection |
|
44 | + */ |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + $this->schema = $this->connection->createSchema(); |
|
48 | + } |
|
49 | + |
|
50 | + public function getWrappedSchema() { |
|
51 | + return $this->schema; |
|
52 | + } |
|
53 | + |
|
54 | + public function performDropTableCalls() { |
|
55 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | + $this->connection->dropTable($tableName); |
|
57 | + unset($this->tablesToDelete[$tableName]); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Gets all table names |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getTableNamesWithoutPrefix() { |
|
67 | + $tableNames = $this->schema->getTableNames(); |
|
68 | + return array_map(function($tableName) { |
|
69 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | + } |
|
72 | + |
|
73 | + return $tableName; |
|
74 | + }, $tableNames); |
|
75 | + } |
|
76 | + |
|
77 | + // Overwritten methods |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getTableNames() { |
|
83 | + return $this->schema->getTableNames(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $tableName |
|
88 | + * |
|
89 | + * @return \Doctrine\DBAL\Schema\Table |
|
90 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | + */ |
|
92 | + public function getTable($tableName) { |
|
93 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Does this schema have a table with the given name? |
|
98 | + * |
|
99 | + * @param string $tableName |
|
100 | + * |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function hasTable($tableName) { |
|
104 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Creates a new table. |
|
109 | + * |
|
110 | + * @param string $tableName |
|
111 | + * @return \Doctrine\DBAL\Schema\Table |
|
112 | + */ |
|
113 | + public function createTable($tableName) { |
|
114 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Drops a table from the schema. |
|
119 | + * |
|
120 | + * @param string $tableName |
|
121 | + * @return \Doctrine\DBAL\Schema\Schema |
|
122 | + */ |
|
123 | + public function dropTable($tableName) { |
|
124 | + $this->tablesToDelete[$tableName] = true; |
|
125 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets all tables of this schema. |
|
130 | + * |
|
131 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | + */ |
|
133 | + public function getTables() { |
|
134 | + return $this->schema->getTables(); |
|
135 | + } |
|
136 | 136 | } |
@@ -37,414 +37,414 @@ |
||
37 | 37 | |
38 | 38 | class MigrationService { |
39 | 39 | |
40 | - /** @var boolean */ |
|
41 | - private $migrationTableCreated; |
|
42 | - /** @var array */ |
|
43 | - private $migrations; |
|
44 | - /** @var IOutput */ |
|
45 | - private $output; |
|
46 | - /** @var Connection */ |
|
47 | - private $connection; |
|
48 | - /** @var string */ |
|
49 | - private $appName; |
|
50 | - |
|
51 | - /** |
|
52 | - * MigrationService constructor. |
|
53 | - * |
|
54 | - * @param $appName |
|
55 | - * @param IDBConnection $connection |
|
56 | - * @param AppLocator $appLocator |
|
57 | - * @param IOutput|null $output |
|
58 | - * @throws \Exception |
|
59 | - */ |
|
60 | - public function __construct($appName, IDBConnection $connection, IOutput $output = null, AppLocator $appLocator = null) { |
|
61 | - $this->appName = $appName; |
|
62 | - $this->connection = $connection; |
|
63 | - $this->output = $output; |
|
64 | - if (null === $this->output) { |
|
65 | - $this->output = new SimpleOutput(\OC::$server->getLogger(), $appName); |
|
66 | - } |
|
67 | - |
|
68 | - if ($appName === 'core') { |
|
69 | - $this->migrationsPath = \OC::$SERVERROOT . '/core/Migrations'; |
|
70 | - $this->migrationsNamespace = 'OC\\Core\\Migrations'; |
|
71 | - } else { |
|
72 | - if (null === $appLocator) { |
|
73 | - $appLocator = new AppLocator(); |
|
74 | - } |
|
75 | - $appPath = $appLocator->getAppPath($appName); |
|
76 | - $namespace = App::buildAppNamespace($appName); |
|
77 | - $this->migrationsPath = "$appPath/lib/Migration"; |
|
78 | - $this->migrationsNamespace = $namespace . '\\Migration'; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the name of the app for which this migration is executed |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function getApp() { |
|
88 | - return $this->appName; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return bool |
|
93 | - * @codeCoverageIgnore - this will implicitly tested on installation |
|
94 | - */ |
|
95 | - private function createMigrationTable() { |
|
96 | - if ($this->migrationTableCreated) { |
|
97 | - return false; |
|
98 | - } |
|
99 | - |
|
100 | - $schema = new SchemaWrapper($this->connection); |
|
101 | - |
|
102 | - /** |
|
103 | - * We drop the table when it has different columns or the definition does not |
|
104 | - * match. E.g. ownCloud uses a length of 177 for app and 14 for version. |
|
105 | - */ |
|
106 | - try { |
|
107 | - $table = $schema->getTable('migrations'); |
|
108 | - $columns = $table->getColumns(); |
|
109 | - |
|
110 | - if (count($columns) === 2) { |
|
111 | - try { |
|
112 | - $column = $table->getColumn('app'); |
|
113 | - $schemaMismatch = $column->getLength() !== 255; |
|
114 | - |
|
115 | - if (!$schemaMismatch) { |
|
116 | - $column = $table->getColumn('version'); |
|
117 | - $schemaMismatch = $column->getLength() !== 255; |
|
118 | - } |
|
119 | - } catch (SchemaException $e) { |
|
120 | - // One of the columns is missing |
|
121 | - $schemaMismatch = true; |
|
122 | - } |
|
123 | - |
|
124 | - if (!$schemaMismatch) { |
|
125 | - // Table exists and schema matches: return back! |
|
126 | - $this->migrationTableCreated = true; |
|
127 | - return false; |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - // Drop the table, when it didn't match our expectations. |
|
132 | - $this->connection->dropTable($this->connection->getPrefix() . 'migrations'); |
|
133 | - } catch (SchemaException $e) { |
|
134 | - // Table not found, no need to panic, we will create it. |
|
135 | - } |
|
136 | - |
|
137 | - $tableName = $this->connection->getPrefix() . 'migrations'; |
|
138 | - $tableName = $this->connection->getDatabasePlatform()->quoteIdentifier($tableName); |
|
139 | - |
|
140 | - $columns = [ |
|
141 | - 'app' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('app'), Type::getType('string'), ['length' => 255]), |
|
142 | - 'version' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('version'), Type::getType('string'), ['length' => 255]), |
|
143 | - ]; |
|
144 | - $table = new Table($tableName, $columns); |
|
145 | - $table->setPrimaryKey([ |
|
146 | - $this->connection->getDatabasePlatform()->quoteIdentifier('app'), |
|
147 | - $this->connection->getDatabasePlatform()->quoteIdentifier('version')]); |
|
148 | - $this->connection->getSchemaManager()->createTable($table); |
|
149 | - |
|
150 | - $this->migrationTableCreated = true; |
|
151 | - |
|
152 | - return true; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Returns all versions which have already been applied |
|
157 | - * |
|
158 | - * @return string[] |
|
159 | - * @codeCoverageIgnore - no need to test this |
|
160 | - */ |
|
161 | - public function getMigratedVersions() { |
|
162 | - $this->createMigrationTable(); |
|
163 | - $qb = $this->connection->getQueryBuilder(); |
|
164 | - |
|
165 | - $qb->select('version') |
|
166 | - ->from('migrations') |
|
167 | - ->where($qb->expr()->eq('app', $qb->createNamedParameter($this->getApp()))) |
|
168 | - ->orderBy('version'); |
|
169 | - |
|
170 | - $result = $qb->execute(); |
|
171 | - $rows = $result->fetchAll(\PDO::FETCH_COLUMN); |
|
172 | - $result->closeCursor(); |
|
173 | - |
|
174 | - return $rows; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns all versions which are available in the migration folder |
|
179 | - * |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public function getAvailableVersions() { |
|
183 | - $this->ensureMigrationsAreLoaded(); |
|
184 | - return array_map('strval', array_keys($this->migrations)); |
|
185 | - } |
|
186 | - |
|
187 | - protected function findMigrations() { |
|
188 | - $directory = realpath($this->migrationsPath); |
|
189 | - if ($directory === false || !file_exists($directory) || !is_dir($directory)) { |
|
190 | - return []; |
|
191 | - } |
|
192 | - |
|
193 | - $iterator = new \RegexIterator( |
|
194 | - new \RecursiveIteratorIterator( |
|
195 | - new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), |
|
196 | - \RecursiveIteratorIterator::LEAVES_ONLY |
|
197 | - ), |
|
198 | - '#^.+\\/Version[^\\/]{1,255}\\.php$#i', |
|
199 | - \RegexIterator::GET_MATCH); |
|
200 | - |
|
201 | - $files = array_keys(iterator_to_array($iterator)); |
|
202 | - uasort($files, function ($a, $b) { |
|
203 | - preg_match('/^Version(\d+)Date(\d+)\\.php$/', basename($a), $matchA); |
|
204 | - preg_match('/^Version(\d+)Date(\d+)\\.php$/', basename($b), $matchB); |
|
205 | - if (!empty($matchA) && !empty($matchB)) { |
|
206 | - if ($matchA[1] !== $matchB[1]) { |
|
207 | - return ($matchA[1] < $matchB[1]) ? -1 : 1; |
|
208 | - } |
|
209 | - return ($matchA[2] < $matchB[2]) ? -1 : 1; |
|
210 | - } |
|
211 | - return (basename($a) < basename($b)) ? -1 : 1; |
|
212 | - }); |
|
213 | - |
|
214 | - $migrations = []; |
|
215 | - |
|
216 | - foreach ($files as $file) { |
|
217 | - $className = basename($file, '.php'); |
|
218 | - $version = (string) substr($className, 7); |
|
219 | - if ($version === '0') { |
|
220 | - throw new \InvalidArgumentException( |
|
221 | - "Cannot load a migrations with the name '$version' because it is a reserved number" |
|
222 | - ); |
|
223 | - } |
|
224 | - $migrations[$version] = sprintf('%s\\%s', $this->migrationsNamespace, $className); |
|
225 | - } |
|
226 | - |
|
227 | - return $migrations; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param string $to |
|
232 | - * @return string[] |
|
233 | - */ |
|
234 | - private function getMigrationsToExecute($to) { |
|
235 | - $knownMigrations = $this->getMigratedVersions(); |
|
236 | - $availableMigrations = $this->getAvailableVersions(); |
|
237 | - |
|
238 | - $toBeExecuted = []; |
|
239 | - foreach ($availableMigrations as $v) { |
|
240 | - if ($to !== 'latest' && $v > $to) { |
|
241 | - continue; |
|
242 | - } |
|
243 | - if ($this->shallBeExecuted($v, $knownMigrations)) { |
|
244 | - $toBeExecuted[] = $v; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - return $toBeExecuted; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @param string $m |
|
253 | - * @param string[] $knownMigrations |
|
254 | - * @return bool |
|
255 | - */ |
|
256 | - private function shallBeExecuted($m, $knownMigrations) { |
|
257 | - if (in_array($m, $knownMigrations)) { |
|
258 | - return false; |
|
259 | - } |
|
260 | - |
|
261 | - return true; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $version |
|
266 | - */ |
|
267 | - private function markAsExecuted($version) { |
|
268 | - $this->connection->insertIfNotExist('*PREFIX*migrations', [ |
|
269 | - 'app' => $this->appName, |
|
270 | - 'version' => $version |
|
271 | - ]); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Returns the name of the table which holds the already applied versions |
|
276 | - * |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function getMigrationsTableName() { |
|
280 | - return $this->connection->getPrefix() . 'migrations'; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Returns the namespace of the version classes |
|
285 | - * |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function getMigrationsNamespace() { |
|
289 | - return $this->migrationsNamespace; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Returns the directory which holds the versions |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function getMigrationsDirectory() { |
|
298 | - return $this->migrationsPath; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Return the explicit version for the aliases; current, next, prev, latest |
|
303 | - * |
|
304 | - * @param string $alias |
|
305 | - * @return mixed|null|string |
|
306 | - */ |
|
307 | - public function getMigration($alias) { |
|
308 | - switch($alias) { |
|
309 | - case 'current': |
|
310 | - return $this->getCurrentVersion(); |
|
311 | - case 'next': |
|
312 | - return $this->getRelativeVersion($this->getCurrentVersion(), 1); |
|
313 | - case 'prev': |
|
314 | - return $this->getRelativeVersion($this->getCurrentVersion(), -1); |
|
315 | - case 'latest': |
|
316 | - $this->ensureMigrationsAreLoaded(); |
|
317 | - |
|
318 | - $migrations = $this->getAvailableVersions(); |
|
319 | - return @end($migrations); |
|
320 | - } |
|
321 | - return '0'; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $version |
|
326 | - * @param int $delta |
|
327 | - * @return null|string |
|
328 | - */ |
|
329 | - private function getRelativeVersion($version, $delta) { |
|
330 | - $this->ensureMigrationsAreLoaded(); |
|
331 | - |
|
332 | - $versions = $this->getAvailableVersions(); |
|
333 | - array_unshift($versions, 0); |
|
334 | - $offset = array_search($version, $versions, true); |
|
335 | - if ($offset === false || !isset($versions[$offset + $delta])) { |
|
336 | - // Unknown version or delta out of bounds. |
|
337 | - return null; |
|
338 | - } |
|
339 | - |
|
340 | - return (string) $versions[$offset + $delta]; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - private function getCurrentVersion() { |
|
347 | - $m = $this->getMigratedVersions(); |
|
348 | - if (count($m) === 0) { |
|
349 | - return '0'; |
|
350 | - } |
|
351 | - $migrations = array_values($m); |
|
352 | - return @end($migrations); |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * @param string $version |
|
357 | - * @return string |
|
358 | - * @throws \InvalidArgumentException |
|
359 | - */ |
|
360 | - private function getClass($version) { |
|
361 | - $this->ensureMigrationsAreLoaded(); |
|
362 | - |
|
363 | - if (isset($this->migrations[$version])) { |
|
364 | - return $this->migrations[$version]; |
|
365 | - } |
|
366 | - |
|
367 | - throw new \InvalidArgumentException("Version $version is unknown."); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Allows to set an IOutput implementation which is used for logging progress and messages |
|
372 | - * |
|
373 | - * @param IOutput $output |
|
374 | - */ |
|
375 | - public function setOutput(IOutput $output) { |
|
376 | - $this->output = $output; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Applies all not yet applied versions up to $to |
|
381 | - * |
|
382 | - * @param string $to |
|
383 | - * @throws \InvalidArgumentException |
|
384 | - */ |
|
385 | - public function migrate($to = 'latest') { |
|
386 | - // read known migrations |
|
387 | - $toBeExecuted = $this->getMigrationsToExecute($to); |
|
388 | - foreach ($toBeExecuted as $version) { |
|
389 | - $this->executeStep($version); |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @param string $version |
|
395 | - * @return mixed |
|
396 | - * @throws \InvalidArgumentException |
|
397 | - */ |
|
398 | - protected function createInstance($version) { |
|
399 | - $class = $this->getClass($version); |
|
400 | - try { |
|
401 | - $s = \OC::$server->query($class); |
|
402 | - } catch (QueryException $e) { |
|
403 | - if (class_exists($class)) { |
|
404 | - $s = new $class(); |
|
405 | - } else { |
|
406 | - throw new \InvalidArgumentException("Migration step '$class' is unknown"); |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - return $s; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Executes one explicit version |
|
415 | - * |
|
416 | - * @param string $version |
|
417 | - * @throws \InvalidArgumentException |
|
418 | - */ |
|
419 | - public function executeStep($version) { |
|
420 | - $instance = $this->createInstance($version); |
|
421 | - if (!$instance instanceof IMigrationStep) { |
|
422 | - throw new \InvalidArgumentException('Not a valid migration'); |
|
423 | - } |
|
424 | - |
|
425 | - $instance->preSchemaChange($this->output, function() { |
|
426 | - return new SchemaWrapper($this->connection); |
|
427 | - }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
428 | - |
|
429 | - $toSchema = $instance->changeSchema($this->output, function() { |
|
430 | - return new SchemaWrapper($this->connection); |
|
431 | - }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
432 | - |
|
433 | - if ($toSchema instanceof SchemaWrapper) { |
|
434 | - $this->connection->migrateToSchema($toSchema->getWrappedSchema()); |
|
435 | - $toSchema->performDropTableCalls(); |
|
436 | - } |
|
437 | - |
|
438 | - $instance->postSchemaChange($this->output, function() { |
|
439 | - return new SchemaWrapper($this->connection); |
|
440 | - }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
441 | - |
|
442 | - $this->markAsExecuted($version); |
|
443 | - } |
|
444 | - |
|
445 | - private function ensureMigrationsAreLoaded() { |
|
446 | - if (empty($this->migrations)) { |
|
447 | - $this->migrations = $this->findMigrations(); |
|
448 | - } |
|
449 | - } |
|
40 | + /** @var boolean */ |
|
41 | + private $migrationTableCreated; |
|
42 | + /** @var array */ |
|
43 | + private $migrations; |
|
44 | + /** @var IOutput */ |
|
45 | + private $output; |
|
46 | + /** @var Connection */ |
|
47 | + private $connection; |
|
48 | + /** @var string */ |
|
49 | + private $appName; |
|
50 | + |
|
51 | + /** |
|
52 | + * MigrationService constructor. |
|
53 | + * |
|
54 | + * @param $appName |
|
55 | + * @param IDBConnection $connection |
|
56 | + * @param AppLocator $appLocator |
|
57 | + * @param IOutput|null $output |
|
58 | + * @throws \Exception |
|
59 | + */ |
|
60 | + public function __construct($appName, IDBConnection $connection, IOutput $output = null, AppLocator $appLocator = null) { |
|
61 | + $this->appName = $appName; |
|
62 | + $this->connection = $connection; |
|
63 | + $this->output = $output; |
|
64 | + if (null === $this->output) { |
|
65 | + $this->output = new SimpleOutput(\OC::$server->getLogger(), $appName); |
|
66 | + } |
|
67 | + |
|
68 | + if ($appName === 'core') { |
|
69 | + $this->migrationsPath = \OC::$SERVERROOT . '/core/Migrations'; |
|
70 | + $this->migrationsNamespace = 'OC\\Core\\Migrations'; |
|
71 | + } else { |
|
72 | + if (null === $appLocator) { |
|
73 | + $appLocator = new AppLocator(); |
|
74 | + } |
|
75 | + $appPath = $appLocator->getAppPath($appName); |
|
76 | + $namespace = App::buildAppNamespace($appName); |
|
77 | + $this->migrationsPath = "$appPath/lib/Migration"; |
|
78 | + $this->migrationsNamespace = $namespace . '\\Migration'; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the name of the app for which this migration is executed |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function getApp() { |
|
88 | + return $this->appName; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return bool |
|
93 | + * @codeCoverageIgnore - this will implicitly tested on installation |
|
94 | + */ |
|
95 | + private function createMigrationTable() { |
|
96 | + if ($this->migrationTableCreated) { |
|
97 | + return false; |
|
98 | + } |
|
99 | + |
|
100 | + $schema = new SchemaWrapper($this->connection); |
|
101 | + |
|
102 | + /** |
|
103 | + * We drop the table when it has different columns or the definition does not |
|
104 | + * match. E.g. ownCloud uses a length of 177 for app and 14 for version. |
|
105 | + */ |
|
106 | + try { |
|
107 | + $table = $schema->getTable('migrations'); |
|
108 | + $columns = $table->getColumns(); |
|
109 | + |
|
110 | + if (count($columns) === 2) { |
|
111 | + try { |
|
112 | + $column = $table->getColumn('app'); |
|
113 | + $schemaMismatch = $column->getLength() !== 255; |
|
114 | + |
|
115 | + if (!$schemaMismatch) { |
|
116 | + $column = $table->getColumn('version'); |
|
117 | + $schemaMismatch = $column->getLength() !== 255; |
|
118 | + } |
|
119 | + } catch (SchemaException $e) { |
|
120 | + // One of the columns is missing |
|
121 | + $schemaMismatch = true; |
|
122 | + } |
|
123 | + |
|
124 | + if (!$schemaMismatch) { |
|
125 | + // Table exists and schema matches: return back! |
|
126 | + $this->migrationTableCreated = true; |
|
127 | + return false; |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + // Drop the table, when it didn't match our expectations. |
|
132 | + $this->connection->dropTable($this->connection->getPrefix() . 'migrations'); |
|
133 | + } catch (SchemaException $e) { |
|
134 | + // Table not found, no need to panic, we will create it. |
|
135 | + } |
|
136 | + |
|
137 | + $tableName = $this->connection->getPrefix() . 'migrations'; |
|
138 | + $tableName = $this->connection->getDatabasePlatform()->quoteIdentifier($tableName); |
|
139 | + |
|
140 | + $columns = [ |
|
141 | + 'app' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('app'), Type::getType('string'), ['length' => 255]), |
|
142 | + 'version' => new Column($this->connection->getDatabasePlatform()->quoteIdentifier('version'), Type::getType('string'), ['length' => 255]), |
|
143 | + ]; |
|
144 | + $table = new Table($tableName, $columns); |
|
145 | + $table->setPrimaryKey([ |
|
146 | + $this->connection->getDatabasePlatform()->quoteIdentifier('app'), |
|
147 | + $this->connection->getDatabasePlatform()->quoteIdentifier('version')]); |
|
148 | + $this->connection->getSchemaManager()->createTable($table); |
|
149 | + |
|
150 | + $this->migrationTableCreated = true; |
|
151 | + |
|
152 | + return true; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Returns all versions which have already been applied |
|
157 | + * |
|
158 | + * @return string[] |
|
159 | + * @codeCoverageIgnore - no need to test this |
|
160 | + */ |
|
161 | + public function getMigratedVersions() { |
|
162 | + $this->createMigrationTable(); |
|
163 | + $qb = $this->connection->getQueryBuilder(); |
|
164 | + |
|
165 | + $qb->select('version') |
|
166 | + ->from('migrations') |
|
167 | + ->where($qb->expr()->eq('app', $qb->createNamedParameter($this->getApp()))) |
|
168 | + ->orderBy('version'); |
|
169 | + |
|
170 | + $result = $qb->execute(); |
|
171 | + $rows = $result->fetchAll(\PDO::FETCH_COLUMN); |
|
172 | + $result->closeCursor(); |
|
173 | + |
|
174 | + return $rows; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns all versions which are available in the migration folder |
|
179 | + * |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public function getAvailableVersions() { |
|
183 | + $this->ensureMigrationsAreLoaded(); |
|
184 | + return array_map('strval', array_keys($this->migrations)); |
|
185 | + } |
|
186 | + |
|
187 | + protected function findMigrations() { |
|
188 | + $directory = realpath($this->migrationsPath); |
|
189 | + if ($directory === false || !file_exists($directory) || !is_dir($directory)) { |
|
190 | + return []; |
|
191 | + } |
|
192 | + |
|
193 | + $iterator = new \RegexIterator( |
|
194 | + new \RecursiveIteratorIterator( |
|
195 | + new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), |
|
196 | + \RecursiveIteratorIterator::LEAVES_ONLY |
|
197 | + ), |
|
198 | + '#^.+\\/Version[^\\/]{1,255}\\.php$#i', |
|
199 | + \RegexIterator::GET_MATCH); |
|
200 | + |
|
201 | + $files = array_keys(iterator_to_array($iterator)); |
|
202 | + uasort($files, function ($a, $b) { |
|
203 | + preg_match('/^Version(\d+)Date(\d+)\\.php$/', basename($a), $matchA); |
|
204 | + preg_match('/^Version(\d+)Date(\d+)\\.php$/', basename($b), $matchB); |
|
205 | + if (!empty($matchA) && !empty($matchB)) { |
|
206 | + if ($matchA[1] !== $matchB[1]) { |
|
207 | + return ($matchA[1] < $matchB[1]) ? -1 : 1; |
|
208 | + } |
|
209 | + return ($matchA[2] < $matchB[2]) ? -1 : 1; |
|
210 | + } |
|
211 | + return (basename($a) < basename($b)) ? -1 : 1; |
|
212 | + }); |
|
213 | + |
|
214 | + $migrations = []; |
|
215 | + |
|
216 | + foreach ($files as $file) { |
|
217 | + $className = basename($file, '.php'); |
|
218 | + $version = (string) substr($className, 7); |
|
219 | + if ($version === '0') { |
|
220 | + throw new \InvalidArgumentException( |
|
221 | + "Cannot load a migrations with the name '$version' because it is a reserved number" |
|
222 | + ); |
|
223 | + } |
|
224 | + $migrations[$version] = sprintf('%s\\%s', $this->migrationsNamespace, $className); |
|
225 | + } |
|
226 | + |
|
227 | + return $migrations; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param string $to |
|
232 | + * @return string[] |
|
233 | + */ |
|
234 | + private function getMigrationsToExecute($to) { |
|
235 | + $knownMigrations = $this->getMigratedVersions(); |
|
236 | + $availableMigrations = $this->getAvailableVersions(); |
|
237 | + |
|
238 | + $toBeExecuted = []; |
|
239 | + foreach ($availableMigrations as $v) { |
|
240 | + if ($to !== 'latest' && $v > $to) { |
|
241 | + continue; |
|
242 | + } |
|
243 | + if ($this->shallBeExecuted($v, $knownMigrations)) { |
|
244 | + $toBeExecuted[] = $v; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + return $toBeExecuted; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @param string $m |
|
253 | + * @param string[] $knownMigrations |
|
254 | + * @return bool |
|
255 | + */ |
|
256 | + private function shallBeExecuted($m, $knownMigrations) { |
|
257 | + if (in_array($m, $knownMigrations)) { |
|
258 | + return false; |
|
259 | + } |
|
260 | + |
|
261 | + return true; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $version |
|
266 | + */ |
|
267 | + private function markAsExecuted($version) { |
|
268 | + $this->connection->insertIfNotExist('*PREFIX*migrations', [ |
|
269 | + 'app' => $this->appName, |
|
270 | + 'version' => $version |
|
271 | + ]); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Returns the name of the table which holds the already applied versions |
|
276 | + * |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function getMigrationsTableName() { |
|
280 | + return $this->connection->getPrefix() . 'migrations'; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Returns the namespace of the version classes |
|
285 | + * |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function getMigrationsNamespace() { |
|
289 | + return $this->migrationsNamespace; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Returns the directory which holds the versions |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function getMigrationsDirectory() { |
|
298 | + return $this->migrationsPath; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Return the explicit version for the aliases; current, next, prev, latest |
|
303 | + * |
|
304 | + * @param string $alias |
|
305 | + * @return mixed|null|string |
|
306 | + */ |
|
307 | + public function getMigration($alias) { |
|
308 | + switch($alias) { |
|
309 | + case 'current': |
|
310 | + return $this->getCurrentVersion(); |
|
311 | + case 'next': |
|
312 | + return $this->getRelativeVersion($this->getCurrentVersion(), 1); |
|
313 | + case 'prev': |
|
314 | + return $this->getRelativeVersion($this->getCurrentVersion(), -1); |
|
315 | + case 'latest': |
|
316 | + $this->ensureMigrationsAreLoaded(); |
|
317 | + |
|
318 | + $migrations = $this->getAvailableVersions(); |
|
319 | + return @end($migrations); |
|
320 | + } |
|
321 | + return '0'; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $version |
|
326 | + * @param int $delta |
|
327 | + * @return null|string |
|
328 | + */ |
|
329 | + private function getRelativeVersion($version, $delta) { |
|
330 | + $this->ensureMigrationsAreLoaded(); |
|
331 | + |
|
332 | + $versions = $this->getAvailableVersions(); |
|
333 | + array_unshift($versions, 0); |
|
334 | + $offset = array_search($version, $versions, true); |
|
335 | + if ($offset === false || !isset($versions[$offset + $delta])) { |
|
336 | + // Unknown version or delta out of bounds. |
|
337 | + return null; |
|
338 | + } |
|
339 | + |
|
340 | + return (string) $versions[$offset + $delta]; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + private function getCurrentVersion() { |
|
347 | + $m = $this->getMigratedVersions(); |
|
348 | + if (count($m) === 0) { |
|
349 | + return '0'; |
|
350 | + } |
|
351 | + $migrations = array_values($m); |
|
352 | + return @end($migrations); |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * @param string $version |
|
357 | + * @return string |
|
358 | + * @throws \InvalidArgumentException |
|
359 | + */ |
|
360 | + private function getClass($version) { |
|
361 | + $this->ensureMigrationsAreLoaded(); |
|
362 | + |
|
363 | + if (isset($this->migrations[$version])) { |
|
364 | + return $this->migrations[$version]; |
|
365 | + } |
|
366 | + |
|
367 | + throw new \InvalidArgumentException("Version $version is unknown."); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Allows to set an IOutput implementation which is used for logging progress and messages |
|
372 | + * |
|
373 | + * @param IOutput $output |
|
374 | + */ |
|
375 | + public function setOutput(IOutput $output) { |
|
376 | + $this->output = $output; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Applies all not yet applied versions up to $to |
|
381 | + * |
|
382 | + * @param string $to |
|
383 | + * @throws \InvalidArgumentException |
|
384 | + */ |
|
385 | + public function migrate($to = 'latest') { |
|
386 | + // read known migrations |
|
387 | + $toBeExecuted = $this->getMigrationsToExecute($to); |
|
388 | + foreach ($toBeExecuted as $version) { |
|
389 | + $this->executeStep($version); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @param string $version |
|
395 | + * @return mixed |
|
396 | + * @throws \InvalidArgumentException |
|
397 | + */ |
|
398 | + protected function createInstance($version) { |
|
399 | + $class = $this->getClass($version); |
|
400 | + try { |
|
401 | + $s = \OC::$server->query($class); |
|
402 | + } catch (QueryException $e) { |
|
403 | + if (class_exists($class)) { |
|
404 | + $s = new $class(); |
|
405 | + } else { |
|
406 | + throw new \InvalidArgumentException("Migration step '$class' is unknown"); |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + return $s; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Executes one explicit version |
|
415 | + * |
|
416 | + * @param string $version |
|
417 | + * @throws \InvalidArgumentException |
|
418 | + */ |
|
419 | + public function executeStep($version) { |
|
420 | + $instance = $this->createInstance($version); |
|
421 | + if (!$instance instanceof IMigrationStep) { |
|
422 | + throw new \InvalidArgumentException('Not a valid migration'); |
|
423 | + } |
|
424 | + |
|
425 | + $instance->preSchemaChange($this->output, function() { |
|
426 | + return new SchemaWrapper($this->connection); |
|
427 | + }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
428 | + |
|
429 | + $toSchema = $instance->changeSchema($this->output, function() { |
|
430 | + return new SchemaWrapper($this->connection); |
|
431 | + }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
432 | + |
|
433 | + if ($toSchema instanceof SchemaWrapper) { |
|
434 | + $this->connection->migrateToSchema($toSchema->getWrappedSchema()); |
|
435 | + $toSchema->performDropTableCalls(); |
|
436 | + } |
|
437 | + |
|
438 | + $instance->postSchemaChange($this->output, function() { |
|
439 | + return new SchemaWrapper($this->connection); |
|
440 | + }, ['tablePrefix' => $this->connection->getPrefix()]); |
|
441 | + |
|
442 | + $this->markAsExecuted($version); |
|
443 | + } |
|
444 | + |
|
445 | + private function ensureMigrationsAreLoaded() { |
|
446 | + if (empty($this->migrations)) { |
|
447 | + $this->migrations = $this->findMigrations(); |
|
448 | + } |
|
449 | + } |
|
450 | 450 | } |
@@ -29,64 +29,64 @@ |
||
29 | 29 | */ |
30 | 30 | interface ISchemaWrapper { |
31 | 31 | |
32 | - /** |
|
33 | - * @param string $tableName |
|
34 | - * |
|
35 | - * @return \Doctrine\DBAL\Schema\Table |
|
36 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function getTable($tableName); |
|
32 | + /** |
|
33 | + * @param string $tableName |
|
34 | + * |
|
35 | + * @return \Doctrine\DBAL\Schema\Table |
|
36 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function getTable($tableName); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Does this schema have a table with the given name? |
|
43 | - * |
|
44 | - * @param string $tableName Prefix is automatically prepended |
|
45 | - * |
|
46 | - * @return boolean |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function hasTable($tableName); |
|
41 | + /** |
|
42 | + * Does this schema have a table with the given name? |
|
43 | + * |
|
44 | + * @param string $tableName Prefix is automatically prepended |
|
45 | + * |
|
46 | + * @return boolean |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function hasTable($tableName); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Creates a new table. |
|
53 | - * |
|
54 | - * @param string $tableName Prefix is automatically prepended |
|
55 | - * @return \Doctrine\DBAL\Schema\Table |
|
56 | - * @since 13.0.0 |
|
57 | - */ |
|
58 | - public function createTable($tableName); |
|
51 | + /** |
|
52 | + * Creates a new table. |
|
53 | + * |
|
54 | + * @param string $tableName Prefix is automatically prepended |
|
55 | + * @return \Doctrine\DBAL\Schema\Table |
|
56 | + * @since 13.0.0 |
|
57 | + */ |
|
58 | + public function createTable($tableName); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Drops a table from the schema. |
|
62 | - * |
|
63 | - * @param string $tableName Prefix is automatically prepended |
|
64 | - * @return \Doctrine\DBAL\Schema\Schema |
|
65 | - * @since 13.0.0 |
|
66 | - */ |
|
67 | - public function dropTable($tableName); |
|
60 | + /** |
|
61 | + * Drops a table from the schema. |
|
62 | + * |
|
63 | + * @param string $tableName Prefix is automatically prepended |
|
64 | + * @return \Doctrine\DBAL\Schema\Schema |
|
65 | + * @since 13.0.0 |
|
66 | + */ |
|
67 | + public function dropTable($tableName); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Gets all tables of this schema. |
|
71 | - * |
|
72 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
73 | - * @since 13.0.0 |
|
74 | - */ |
|
75 | - public function getTables(); |
|
69 | + /** |
|
70 | + * Gets all tables of this schema. |
|
71 | + * |
|
72 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
73 | + * @since 13.0.0 |
|
74 | + */ |
|
75 | + public function getTables(); |
|
76 | 76 | |
77 | - /** |
|
78 | - * Gets all table names, prefixed with table prefix |
|
79 | - * |
|
80 | - * @return array |
|
81 | - * @since 13.0.0 |
|
82 | - */ |
|
83 | - public function getTableNames(); |
|
77 | + /** |
|
78 | + * Gets all table names, prefixed with table prefix |
|
79 | + * |
|
80 | + * @return array |
|
81 | + * @since 13.0.0 |
|
82 | + */ |
|
83 | + public function getTableNames(); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Gets all table names |
|
87 | - * |
|
88 | - * @return array |
|
89 | - * @since 13.0.0 |
|
90 | - */ |
|
91 | - public function getTableNamesWithoutPrefix(); |
|
85 | + /** |
|
86 | + * Gets all table names |
|
87 | + * |
|
88 | + * @return array |
|
89 | + * @since 13.0.0 |
|
90 | + */ |
|
91 | + public function getTableNamesWithoutPrefix(); |
|
92 | 92 | } |
@@ -30,28 +30,28 @@ |
||
30 | 30 | */ |
31 | 31 | interface IMigrationStep { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IOutput $output |
|
35 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | - * @param array $options |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); |
|
33 | + /** |
|
34 | + * @param IOutput $output |
|
35 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | + * @param array $options |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IOutput $output |
|
43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | - * @param array $options |
|
45 | - * @return null|ISchemaWrapper |
|
46 | - * @since 13.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options); |
|
41 | + /** |
|
42 | + * @param IOutput $output |
|
43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | + * @param array $options |
|
45 | + * @return null|ISchemaWrapper |
|
46 | + * @since 13.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options); |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param IOutput $output |
|
52 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
53 | - * @param array $options |
|
54 | - * @since 13.0.0 |
|
55 | - */ |
|
56 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); |
|
50 | + /** |
|
51 | + * @param IOutput $output |
|
52 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
53 | + * @param array $options |
|
54 | + * @since 13.0.0 |
|
55 | + */ |
|
56 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); |
|
57 | 57 | } |
@@ -31,38 +31,38 @@ |
||
31 | 31 | */ |
32 | 32 | abstract class BigIntMigration extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** |
|
35 | - * @return array Returns an array with the following structure |
|
36 | - * ['table1' => ['column1', 'column2'], ...] |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - abstract protected function getColumnsByTable(); |
|
34 | + /** |
|
35 | + * @return array Returns an array with the following structure |
|
36 | + * ['table1' => ['column1', 'column2'], ...] |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + abstract protected function getColumnsByTable(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IOutput $output |
|
43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | - * @param array $options |
|
45 | - * @return null|ISchemaWrapper |
|
46 | - * @since 13.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | - /** @var ISchemaWrapper $schema */ |
|
50 | - $schema = $schemaClosure(); |
|
41 | + /** |
|
42 | + * @param IOutput $output |
|
43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | + * @param array $options |
|
45 | + * @return null|ISchemaWrapper |
|
46 | + * @since 13.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | + /** @var ISchemaWrapper $schema */ |
|
50 | + $schema = $schemaClosure(); |
|
51 | 51 | |
52 | - $tables = $this->getColumnsByTable(); |
|
52 | + $tables = $this->getColumnsByTable(); |
|
53 | 53 | |
54 | - foreach ($tables as $tableName => $columns) { |
|
55 | - $table = $schema->getTable($tableName); |
|
54 | + foreach ($tables as $tableName => $columns) { |
|
55 | + $table = $schema->getTable($tableName); |
|
56 | 56 | |
57 | - foreach ($columns as $columnName) { |
|
58 | - $column = $table->getColumn($columnName); |
|
59 | - if ($column->getType()->getName() !== Type::BIGINT) { |
|
60 | - $column->setType(Type::getType(Type::BIGINT)); |
|
61 | - $column->setOptions(['length' => 20]); |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
57 | + foreach ($columns as $columnName) { |
|
58 | + $column = $table->getColumn($columnName); |
|
59 | + if ($column->getType()->getName() !== Type::BIGINT) { |
|
60 | + $column->setType(Type::getType(Type::BIGINT)); |
|
61 | + $column->setOptions(['length' => 20]); |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - return $schema; |
|
67 | - } |
|
66 | + return $schema; |
|
67 | + } |
|
68 | 68 | } |
@@ -30,32 +30,32 @@ |
||
30 | 30 | */ |
31 | 31 | abstract class SimpleMigrationStep implements IMigrationStep { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IOutput $output |
|
35 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | - * @param array $options |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | - } |
|
33 | + /** |
|
34 | + * @param IOutput $output |
|
35 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | + * @param array $options |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IOutput $output |
|
44 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
45 | - * @param array $options |
|
46 | - * @return null|ISchemaWrapper |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
50 | - return null; |
|
51 | - } |
|
42 | + /** |
|
43 | + * @param IOutput $output |
|
44 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
45 | + * @param array $options |
|
46 | + * @return null|ISchemaWrapper |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
50 | + return null; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param IOutput $output |
|
55 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
56 | - * @param array $options |
|
57 | - * @since 13.0.0 |
|
58 | - */ |
|
59 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
60 | - } |
|
53 | + /** |
|
54 | + * @param IOutput $output |
|
55 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
56 | + * @param array $options |
|
57 | + * @since 13.0.0 |
|
58 | + */ |
|
59 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
60 | + } |
|
61 | 61 | } |