| Total Complexity | 42 |
| Total Lines | 997 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Version13000Date20170718121200 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Version13000Date20170718121200, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | class Version13000Date20170718121200 extends SimpleMigrationStep { |
||
| 39 | |||
| 40 | /** @var IDBConnection */ |
||
| 41 | private $connection; |
||
| 42 | |||
| 43 | public function __construct(IDBConnection $connection) { |
||
| 44 | $this->connection = $connection; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
||
| 48 | /** @var ISchemaWrapper $schema */ |
||
| 49 | $schema = $schemaClosure(); |
||
| 50 | |||
| 51 | if (!$schema->hasTable('properties')) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | // in case we have a properties table from oc we drop it since we will only migrate |
||
| 55 | // the dav_properties values in the postSchemaChange step |
||
| 56 | $table = $schema->getTable('properties'); |
||
| 57 | if ($table->hasColumn('fileid')) { |
||
| 58 | $qb = $this->connection->getQueryBuilder(); |
||
| 59 | $qb->delete('properties'); |
||
| 60 | $qb->execute(); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * @param IOutput $output |
||
| 67 | * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
||
| 68 | * @param array $options |
||
| 69 | * @return null|ISchemaWrapper |
||
| 70 | * @since 13.0.0 |
||
| 71 | */ |
||
| 72 | public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
||
| 73 | /** @var ISchemaWrapper $schema */ |
||
| 74 | $schema = $schemaClosure(); |
||
| 75 | |||
| 76 | if (!$schema->hasTable('appconfig')) { |
||
| 77 | $table = $schema->createTable('appconfig'); |
||
| 78 | $table->addColumn('appid', 'string', [ |
||
| 79 | 'notnull' => true, |
||
| 80 | 'length' => 32, |
||
| 81 | 'default' => '', |
||
| 82 | ]); |
||
| 83 | $table->addColumn('configkey', 'string', [ |
||
| 84 | 'notnull' => true, |
||
| 85 | 'length' => 64, |
||
| 86 | 'default' => '', |
||
| 87 | ]); |
||
| 88 | $table->addColumn('configvalue', 'text', [ |
||
| 89 | 'notnull' => false, |
||
| 90 | ]); |
||
| 91 | $table->setPrimaryKey(['appid', 'configkey']); |
||
| 92 | $table->addIndex(['configkey'], 'appconfig_config_key_index'); |
||
| 93 | $table->addIndex(['appid'], 'appconfig_appid_key'); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (!$schema->hasTable('storages')) { |
||
| 97 | $table = $schema->createTable('storages'); |
||
| 98 | $table->addColumn('id', 'string', [ |
||
| 99 | 'notnull' => false, |
||
| 100 | 'length' => 64, |
||
| 101 | ]); |
||
| 102 | $table->addColumn('numeric_id', Types::BIGINT, [ |
||
| 103 | 'autoincrement' => true, |
||
| 104 | 'notnull' => true, |
||
| 105 | 'length' => 20, |
||
| 106 | ]); |
||
| 107 | $table->addColumn('available', 'integer', [ |
||
| 108 | 'notnull' => true, |
||
| 109 | 'default' => 1, |
||
| 110 | ]); |
||
| 111 | $table->addColumn('last_checked', 'integer', [ |
||
| 112 | 'notnull' => false, |
||
| 113 | ]); |
||
| 114 | $table->setPrimaryKey(['numeric_id']); |
||
| 115 | $table->addUniqueIndex(['id'], 'storages_id_index'); |
||
| 116 | } |
||
| 117 | |||
| 118 | if (!$schema->hasTable('mounts')) { |
||
| 119 | $table = $schema->createTable('mounts'); |
||
| 120 | $table->addColumn('id', 'integer', [ |
||
| 121 | 'autoincrement' => true, |
||
| 122 | 'notnull' => true, |
||
| 123 | 'length' => 4, |
||
| 124 | ]); |
||
| 125 | $table->addColumn('storage_id', Types::BIGINT, [ |
||
| 126 | 'notnull' => true, |
||
| 127 | 'length' => 20, |
||
| 128 | ]); |
||
| 129 | $table->addColumn('root_id', Types::BIGINT, [ |
||
| 130 | 'notnull' => true, |
||
| 131 | 'length' => 20, |
||
| 132 | ]); |
||
| 133 | $table->addColumn('user_id', 'string', [ |
||
| 134 | 'notnull' => true, |
||
| 135 | 'length' => 64, |
||
| 136 | ]); |
||
| 137 | $table->addColumn('mount_point', 'string', [ |
||
| 138 | 'notnull' => true, |
||
| 139 | 'length' => 4000, |
||
| 140 | ]); |
||
| 141 | $table->addColumn('mount_id', Types::BIGINT, [ |
||
| 142 | 'notnull' => false, |
||
| 143 | 'length' => 20, |
||
| 144 | ]); |
||
| 145 | $table->setPrimaryKey(['id']); |
||
| 146 | $table->addIndex(['user_id'], 'mounts_user_index'); |
||
| 147 | $table->addIndex(['storage_id'], 'mounts_storage_index'); |
||
| 148 | $table->addIndex(['root_id'], 'mounts_root_index'); |
||
| 149 | $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
||
| 150 | $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index'); |
||
| 151 | } else { |
||
| 152 | $table = $schema->getTable('mounts'); |
||
| 153 | $table->addColumn('mount_id', Types::BIGINT, [ |
||
| 154 | 'notnull' => false, |
||
| 155 | 'length' => 20, |
||
| 156 | ]); |
||
| 157 | if (!$table->hasIndex('mounts_mount_id_index')) { |
||
| 158 | $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | if (!$schema->hasTable('mimetypes')) { |
||
| 163 | $table = $schema->createTable('mimetypes'); |
||
| 164 | $table->addColumn('id', Types::BIGINT, [ |
||
| 165 | 'autoincrement' => true, |
||
| 166 | 'notnull' => true, |
||
| 167 | 'length' => 20, |
||
| 168 | ]); |
||
| 169 | $table->addColumn('mimetype', 'string', [ |
||
| 170 | 'notnull' => true, |
||
| 171 | 'length' => 255, |
||
| 172 | 'default' => '', |
||
| 173 | ]); |
||
| 174 | $table->setPrimaryKey(['id']); |
||
| 175 | $table->addUniqueIndex(['mimetype'], 'mimetype_id_index'); |
||
| 176 | } |
||
| 177 | |||
| 178 | if (!$schema->hasTable('filecache')) { |
||
| 179 | $table = $schema->createTable('filecache'); |
||
| 180 | $table->addColumn('fileid', Types::BIGINT, [ |
||
| 181 | 'autoincrement' => true, |
||
| 182 | 'notnull' => true, |
||
| 183 | 'length' => 20, |
||
| 184 | ]); |
||
| 185 | $table->addColumn('storage', Types::BIGINT, [ |
||
| 186 | 'notnull' => true, |
||
| 187 | 'length' => 20, |
||
| 188 | 'default' => 0, |
||
| 189 | ]); |
||
| 190 | $table->addColumn('path', 'string', [ |
||
| 191 | 'notnull' => false, |
||
| 192 | 'length' => 4000, |
||
| 193 | ]); |
||
| 194 | $table->addColumn('path_hash', 'string', [ |
||
| 195 | 'notnull' => true, |
||
| 196 | 'length' => 32, |
||
| 197 | 'default' => '', |
||
| 198 | ]); |
||
| 199 | $table->addColumn('parent', Types::BIGINT, [ |
||
| 200 | 'notnull' => true, |
||
| 201 | 'length' => 20, |
||
| 202 | 'default' => 0, |
||
| 203 | ]); |
||
| 204 | $table->addColumn('name', 'string', [ |
||
| 205 | 'notnull' => false, |
||
| 206 | 'length' => 250, |
||
| 207 | ]); |
||
| 208 | $table->addColumn('mimetype', Types::BIGINT, [ |
||
| 209 | 'notnull' => true, |
||
| 210 | 'length' => 20, |
||
| 211 | 'default' => 0, |
||
| 212 | ]); |
||
| 213 | $table->addColumn('mimepart', Types::BIGINT, [ |
||
| 214 | 'notnull' => true, |
||
| 215 | 'length' => 20, |
||
| 216 | 'default' => 0, |
||
| 217 | ]); |
||
| 218 | $table->addColumn('size', 'bigint', [ |
||
| 219 | 'notnull' => true, |
||
| 220 | 'length' => 8, |
||
| 221 | 'default' => 0, |
||
| 222 | ]); |
||
| 223 | $table->addColumn('mtime', Types::BIGINT, [ |
||
| 224 | 'notnull' => true, |
||
| 225 | 'length' => 20, |
||
| 226 | 'default' => 0, |
||
| 227 | ]); |
||
| 228 | $table->addColumn('storage_mtime', Types::BIGINT, [ |
||
| 229 | 'notnull' => true, |
||
| 230 | 'length' => 20, |
||
| 231 | 'default' => 0, |
||
| 232 | ]); |
||
| 233 | $table->addColumn('encrypted', 'integer', [ |
||
| 234 | 'notnull' => true, |
||
| 235 | 'length' => 4, |
||
| 236 | 'default' => 0, |
||
| 237 | ]); |
||
| 238 | $table->addColumn('unencrypted_size', 'bigint', [ |
||
| 239 | 'notnull' => true, |
||
| 240 | 'length' => 8, |
||
| 241 | 'default' => 0, |
||
| 242 | ]); |
||
| 243 | $table->addColumn('etag', 'string', [ |
||
| 244 | 'notnull' => false, |
||
| 245 | 'length' => 40, |
||
| 246 | ]); |
||
| 247 | $table->addColumn('permissions', 'integer', [ |
||
| 248 | 'notnull' => false, |
||
| 249 | 'length' => 4, |
||
| 250 | 'default' => 0, |
||
| 251 | ]); |
||
| 252 | $table->addColumn('checksum', 'string', [ |
||
| 253 | 'notnull' => false, |
||
| 254 | 'length' => 255, |
||
| 255 | ]); |
||
| 256 | $table->setPrimaryKey(['fileid']); |
||
| 257 | $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash'); |
||
| 258 | $table->addIndex(['parent', 'name'], 'fs_parent_name_hash'); |
||
| 259 | $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype'); |
||
| 260 | $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart'); |
||
| 261 | $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size'); |
||
| 262 | $table->addIndex(['mtime'], 'fs_mtime'); |
||
| 263 | $table->addIndex(['size'], 'fs_size'); |
||
| 264 | } |
||
| 265 | |||
| 266 | if (!$schema->hasTable('group_user')) { |
||
| 267 | $table = $schema->createTable('group_user'); |
||
| 268 | $table->addColumn('gid', 'string', [ |
||
| 269 | 'notnull' => true, |
||
| 270 | 'length' => 64, |
||
| 271 | 'default' => '', |
||
| 272 | ]); |
||
| 273 | $table->addColumn('uid', 'string', [ |
||
| 274 | 'notnull' => true, |
||
| 275 | 'length' => 64, |
||
| 276 | 'default' => '', |
||
| 277 | ]); |
||
| 278 | $table->setPrimaryKey(['gid', 'uid']); |
||
| 279 | $table->addIndex(['uid'], 'gu_uid_index'); |
||
| 280 | } |
||
| 281 | |||
| 282 | if (!$schema->hasTable('group_admin')) { |
||
| 283 | $table = $schema->createTable('group_admin'); |
||
| 284 | $table->addColumn('gid', 'string', [ |
||
| 285 | 'notnull' => true, |
||
| 286 | 'length' => 64, |
||
| 287 | 'default' => '', |
||
| 288 | ]); |
||
| 289 | $table->addColumn('uid', 'string', [ |
||
| 290 | 'notnull' => true, |
||
| 291 | 'length' => 64, |
||
| 292 | 'default' => '', |
||
| 293 | ]); |
||
| 294 | $table->setPrimaryKey(['gid', 'uid']); |
||
| 295 | $table->addIndex(['uid'], 'group_admin_uid'); |
||
| 296 | } |
||
| 297 | |||
| 298 | if (!$schema->hasTable('groups')) { |
||
| 299 | $table = $schema->createTable('groups'); |
||
| 300 | $table->addColumn('gid', 'string', [ |
||
| 301 | 'notnull' => true, |
||
| 302 | 'length' => 64, |
||
| 303 | 'default' => '', |
||
| 304 | ]); |
||
| 305 | $table->setPrimaryKey(['gid']); |
||
| 306 | } |
||
| 307 | |||
| 308 | if (!$schema->hasTable('preferences')) { |
||
| 309 | $table = $schema->createTable('preferences'); |
||
| 310 | $table->addColumn('userid', 'string', [ |
||
| 311 | 'notnull' => true, |
||
| 312 | 'length' => 64, |
||
| 313 | 'default' => '', |
||
| 314 | ]); |
||
| 315 | $table->addColumn('appid', 'string', [ |
||
| 316 | 'notnull' => true, |
||
| 317 | 'length' => 32, |
||
| 318 | 'default' => '', |
||
| 319 | ]); |
||
| 320 | $table->addColumn('configkey', 'string', [ |
||
| 321 | 'notnull' => true, |
||
| 322 | 'length' => 64, |
||
| 323 | 'default' => '', |
||
| 324 | ]); |
||
| 325 | $table->addColumn('configvalue', 'text', [ |
||
| 326 | 'notnull' => false, |
||
| 327 | ]); |
||
| 328 | $table->setPrimaryKey(['userid', 'appid', 'configkey']); |
||
| 329 | } |
||
| 330 | |||
| 331 | if (!$schema->hasTable('properties')) { |
||
| 332 | $table = $schema->createTable('properties'); |
||
| 333 | $table->addColumn('id', 'integer', [ |
||
| 334 | 'autoincrement' => true, |
||
| 335 | 'notnull' => true, |
||
| 336 | 'length' => 4, |
||
| 337 | ]); |
||
| 338 | $table->addColumn('userid', 'string', [ |
||
| 339 | 'notnull' => true, |
||
| 340 | 'length' => 64, |
||
| 341 | 'default' => '', |
||
| 342 | ]); |
||
| 343 | $table->addColumn('propertypath', 'string', [ |
||
| 344 | 'notnull' => true, |
||
| 345 | 'length' => 255, |
||
| 346 | 'default' => '', |
||
| 347 | ]); |
||
| 348 | $table->addColumn('propertyname', 'string', [ |
||
| 349 | 'notnull' => true, |
||
| 350 | 'length' => 255, |
||
| 351 | 'default' => '', |
||
| 352 | ]); |
||
| 353 | $table->addColumn('propertyvalue', 'text', [ |
||
| 354 | 'notnull' => true, |
||
| 355 | ]); |
||
| 356 | $table->setPrimaryKey(['id']); |
||
| 357 | $table->addIndex(['userid'], 'property_index'); |
||
| 358 | $table->addIndex(['userid', 'propertypath'], 'properties_path_index'); |
||
| 359 | } else { |
||
| 360 | $table = $schema->getTable('properties'); |
||
| 361 | if ($table->hasColumn('propertytype')) { |
||
| 362 | $table->dropColumn('propertytype'); |
||
| 363 | } |
||
| 364 | if ($table->hasColumn('fileid')) { |
||
| 365 | $table->dropColumn('fileid'); |
||
| 366 | } |
||
| 367 | if (!$table->hasColumn('propertypath')) { |
||
| 368 | $table->addColumn('propertypath', 'string', [ |
||
| 369 | 'notnull' => true, |
||
| 370 | 'length' => 255, |
||
| 371 | ]); |
||
| 372 | } |
||
| 373 | if (!$table->hasColumn('userid')) { |
||
| 374 | $table->addColumn('userid', 'string', [ |
||
| 375 | 'notnull' => false, |
||
| 376 | 'length' => 64, |
||
| 377 | 'default' => '', |
||
| 378 | ]); |
||
| 379 | } |
||
| 380 | } |
||
| 381 | |||
| 382 | if (!$schema->hasTable('share')) { |
||
| 383 | $table = $schema->createTable('share'); |
||
| 384 | $table->addColumn('id', 'integer', [ |
||
| 385 | 'autoincrement' => true, |
||
| 386 | 'notnull' => true, |
||
| 387 | 'length' => 4, |
||
| 388 | ]); |
||
| 389 | $table->addColumn('share_type', 'smallint', [ |
||
| 390 | 'notnull' => true, |
||
| 391 | 'length' => 1, |
||
| 392 | 'default' => 0, |
||
| 393 | ]); |
||
| 394 | $table->addColumn('share_with', 'string', [ |
||
| 395 | 'notnull' => false, |
||
| 396 | 'length' => 255, |
||
| 397 | ]); |
||
| 398 | $table->addColumn('password', 'string', [ |
||
| 399 | 'notnull' => false, |
||
| 400 | 'length' => 255, |
||
| 401 | ]); |
||
| 402 | $table->addColumn('uid_owner', 'string', [ |
||
| 403 | 'notnull' => true, |
||
| 404 | 'length' => 64, |
||
| 405 | 'default' => '', |
||
| 406 | ]); |
||
| 407 | $table->addColumn('uid_initiator', 'string', [ |
||
| 408 | 'notnull' => false, |
||
| 409 | 'length' => 64, |
||
| 410 | ]); |
||
| 411 | $table->addColumn('parent', 'integer', [ |
||
| 412 | 'notnull' => false, |
||
| 413 | 'length' => 4, |
||
| 414 | ]); |
||
| 415 | $table->addColumn('item_type', 'string', [ |
||
| 416 | 'notnull' => true, |
||
| 417 | 'length' => 64, |
||
| 418 | 'default' => '', |
||
| 419 | ]); |
||
| 420 | $table->addColumn('item_source', 'string', [ |
||
| 421 | 'notnull' => false, |
||
| 422 | 'length' => 255, |
||
| 423 | ]); |
||
| 424 | $table->addColumn('item_target', 'string', [ |
||
| 425 | 'notnull' => false, |
||
| 426 | 'length' => 255, |
||
| 427 | ]); |
||
| 428 | $table->addColumn('file_source', 'integer', [ |
||
| 429 | 'notnull' => false, |
||
| 430 | 'length' => 4, |
||
| 431 | ]); |
||
| 432 | $table->addColumn('file_target', 'string', [ |
||
| 433 | 'notnull' => false, |
||
| 434 | 'length' => 512, |
||
| 435 | ]); |
||
| 436 | $table->addColumn('permissions', 'smallint', [ |
||
| 437 | 'notnull' => true, |
||
| 438 | 'length' => 1, |
||
| 439 | 'default' => 0, |
||
| 440 | ]); |
||
| 441 | $table->addColumn('stime', 'bigint', [ |
||
| 442 | 'notnull' => true, |
||
| 443 | 'length' => 8, |
||
| 444 | 'default' => 0, |
||
| 445 | ]); |
||
| 446 | $table->addColumn('accepted', 'smallint', [ |
||
| 447 | 'notnull' => true, |
||
| 448 | 'length' => 1, |
||
| 449 | 'default' => 0, |
||
| 450 | ]); |
||
| 451 | $table->addColumn('expiration', 'datetime', [ |
||
| 452 | 'notnull' => false, |
||
| 453 | ]); |
||
| 454 | $table->addColumn('token', 'string', [ |
||
| 455 | 'notnull' => false, |
||
| 456 | 'length' => 32, |
||
| 457 | ]); |
||
| 458 | $table->addColumn('mail_send', 'smallint', [ |
||
| 459 | 'notnull' => true, |
||
| 460 | 'length' => 1, |
||
| 461 | 'default' => 0, |
||
| 462 | ]); |
||
| 463 | $table->addColumn('share_name', 'string', [ |
||
| 464 | 'notnull' => false, |
||
| 465 | 'length' => 64, |
||
| 466 | ]); |
||
| 467 | $table->setPrimaryKey(['id']); |
||
| 468 | $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); |
||
| 469 | $table->addIndex(['file_source'], 'file_source_index'); |
||
| 470 | $table->addIndex(['token'], 'token_index'); |
||
| 471 | $table->addIndex(['share_with'], 'share_with_index'); |
||
| 472 | $table->addIndex(['parent'], 'parent_index'); |
||
| 473 | $table->addIndex(['uid_owner'], 'owner_index'); |
||
| 474 | $table->addIndex(['uid_initiator'], 'initiator_index'); |
||
| 475 | } else { |
||
| 476 | $table = $schema->getTable('share'); |
||
| 477 | if (!$table->hasColumn('password')) { |
||
| 478 | $table->addColumn('password', 'string', [ |
||
| 479 | 'notnull' => false, |
||
| 480 | 'length' => 255, |
||
| 481 | ]); |
||
| 482 | } |
||
| 483 | } |
||
| 484 | |||
| 485 | if (!$schema->hasTable('jobs')) { |
||
| 486 | $table = $schema->createTable('jobs'); |
||
| 487 | $table->addColumn('id', 'integer', [ |
||
| 488 | 'autoincrement' => true, |
||
| 489 | 'notnull' => true, |
||
| 490 | 'length' => 4, |
||
| 491 | 'unsigned' => true, |
||
| 492 | ]); |
||
| 493 | $table->addColumn('class', 'string', [ |
||
| 494 | 'notnull' => true, |
||
| 495 | 'length' => 255, |
||
| 496 | 'default' => '', |
||
| 497 | ]); |
||
| 498 | $table->addColumn('argument', 'string', [ |
||
| 499 | 'notnull' => true, |
||
| 500 | 'length' => 4000, |
||
| 501 | 'default' => '', |
||
| 502 | ]); |
||
| 503 | $table->addColumn('last_run', 'integer', [ |
||
| 504 | 'notnull' => false, |
||
| 505 | 'default' => 0, |
||
| 506 | ]); |
||
| 507 | $table->addColumn('last_checked', 'integer', [ |
||
| 508 | 'notnull' => false, |
||
| 509 | 'default' => 0, |
||
| 510 | ]); |
||
| 511 | $table->addColumn('reserved_at', 'integer', [ |
||
| 512 | 'notnull' => false, |
||
| 513 | 'default' => 0, |
||
| 514 | ]); |
||
| 515 | $table->addColumn('execution_duration', 'integer', [ |
||
| 516 | 'notnull' => true, |
||
| 517 | 'default' => 0, |
||
| 518 | ]); |
||
| 519 | $table->setPrimaryKey(['id']); |
||
| 520 | $table->addIndex(['class'], 'job_class_index'); |
||
| 521 | } |
||
| 522 | |||
| 523 | if (!$schema->hasTable('users')) { |
||
| 524 | $table = $schema->createTable('users'); |
||
| 525 | $table->addColumn('uid', 'string', [ |
||
| 526 | 'notnull' => true, |
||
| 527 | 'length' => 64, |
||
| 528 | 'default' => '', |
||
| 529 | ]); |
||
| 530 | $table->addColumn('displayname', 'string', [ |
||
| 531 | 'notnull' => false, |
||
| 532 | 'length' => 64, |
||
| 533 | ]); |
||
| 534 | $table->addColumn('password', 'string', [ |
||
| 535 | 'notnull' => true, |
||
| 536 | 'length' => 255, |
||
| 537 | 'default' => '', |
||
| 538 | ]); |
||
| 539 | $table->setPrimaryKey(['uid']); |
||
| 540 | } |
||
| 541 | |||
| 542 | if (!$schema->hasTable('authtoken')) { |
||
| 543 | $table = $schema->createTable('authtoken'); |
||
| 544 | $table->addColumn('id', 'integer', [ |
||
| 545 | 'autoincrement' => true, |
||
| 546 | 'notnull' => true, |
||
| 547 | 'length' => 4, |
||
| 548 | 'unsigned' => true, |
||
| 549 | ]); |
||
| 550 | $table->addColumn('uid', 'string', [ |
||
| 551 | 'notnull' => true, |
||
| 552 | 'length' => 64, |
||
| 553 | 'default' => '', |
||
| 554 | ]); |
||
| 555 | $table->addColumn('login_name', 'string', [ |
||
| 556 | 'notnull' => true, |
||
| 557 | 'length' => 64, |
||
| 558 | 'default' => '', |
||
| 559 | ]); |
||
| 560 | $table->addColumn('password', 'text', [ |
||
| 561 | 'notnull' => false, |
||
| 562 | ]); |
||
| 563 | $table->addColumn('name', 'text', [ |
||
| 564 | 'notnull' => true, |
||
| 565 | 'default' => '', |
||
| 566 | ]); |
||
| 567 | $table->addColumn('token', 'string', [ |
||
| 568 | 'notnull' => true, |
||
| 569 | 'length' => 200, |
||
| 570 | 'default' => '', |
||
| 571 | ]); |
||
| 572 | $table->addColumn('type', 'smallint', [ |
||
| 573 | 'notnull' => false, |
||
| 574 | 'length' => 2, |
||
| 575 | 'default' => 0, |
||
| 576 | 'unsigned' => true, |
||
| 577 | ]); |
||
| 578 | $table->addColumn('remember', 'smallint', [ |
||
| 579 | 'notnull' => false, |
||
| 580 | 'length' => 1, |
||
| 581 | 'default' => 0, |
||
| 582 | 'unsigned' => true, |
||
| 583 | ]); |
||
| 584 | $table->addColumn('last_activity', 'integer', [ |
||
| 585 | 'notnull' => false, |
||
| 586 | 'length' => 4, |
||
| 587 | 'default' => 0, |
||
| 588 | 'unsigned' => true, |
||
| 589 | ]); |
||
| 590 | $table->addColumn('last_check', 'integer', [ |
||
| 591 | 'notnull' => false, |
||
| 592 | 'length' => 4, |
||
| 593 | 'default' => 0, |
||
| 594 | 'unsigned' => true, |
||
| 595 | ]); |
||
| 596 | $table->addColumn('scope', 'text', [ |
||
| 597 | 'notnull' => false, |
||
| 598 | ]); |
||
| 599 | $table->setPrimaryKey(['id']); |
||
| 600 | $table->addUniqueIndex(['token'], 'authtoken_token_index'); |
||
| 601 | $table->addIndex(['last_activity'], 'authtoken_last_activity_idx'); |
||
| 602 | } else { |
||
| 603 | $table = $schema->getTable('authtoken'); |
||
| 604 | $table->addColumn('scope', 'text', [ |
||
| 605 | 'notnull' => false, |
||
| 606 | ]); |
||
| 607 | } |
||
| 608 | |||
| 609 | if (!$schema->hasTable('bruteforce_attempts')) { |
||
| 610 | $table = $schema->createTable('bruteforce_attempts'); |
||
| 611 | $table->addColumn('id', 'integer', [ |
||
| 612 | 'autoincrement' => true, |
||
| 613 | 'notnull' => true, |
||
| 614 | 'length' => 4, |
||
| 615 | 'unsigned' => true, |
||
| 616 | ]); |
||
| 617 | $table->addColumn('action', 'string', [ |
||
| 618 | 'notnull' => true, |
||
| 619 | 'length' => 64, |
||
| 620 | 'default' => '', |
||
| 621 | ]); |
||
| 622 | $table->addColumn('occurred', 'integer', [ |
||
| 623 | 'notnull' => true, |
||
| 624 | 'length' => 4, |
||
| 625 | 'default' => 0, |
||
| 626 | 'unsigned' => true, |
||
| 627 | ]); |
||
| 628 | $table->addColumn('ip', 'string', [ |
||
| 629 | 'notnull' => true, |
||
| 630 | 'length' => 255, |
||
| 631 | 'default' => '', |
||
| 632 | ]); |
||
| 633 | $table->addColumn('subnet', 'string', [ |
||
| 634 | 'notnull' => true, |
||
| 635 | 'length' => 255, |
||
| 636 | 'default' => '', |
||
| 637 | ]); |
||
| 638 | $table->addColumn('metadata', 'string', [ |
||
| 639 | 'notnull' => true, |
||
| 640 | 'length' => 255, |
||
| 641 | 'default' => '', |
||
| 642 | ]); |
||
| 643 | $table->setPrimaryKey(['id']); |
||
| 644 | $table->addIndex(['ip'], 'bruteforce_attempts_ip'); |
||
| 645 | $table->addIndex(['subnet'], 'bruteforce_attempts_subnet'); |
||
| 646 | } |
||
| 647 | |||
| 648 | if (!$schema->hasTable('vcategory')) { |
||
| 649 | $table = $schema->createTable('vcategory'); |
||
| 650 | $table->addColumn('id', 'integer', [ |
||
| 651 | 'autoincrement' => true, |
||
| 652 | 'notnull' => true, |
||
| 653 | 'length' => 4, |
||
| 654 | 'unsigned' => true, |
||
| 655 | ]); |
||
| 656 | $table->addColumn('uid', 'string', [ |
||
| 657 | 'notnull' => true, |
||
| 658 | 'length' => 64, |
||
| 659 | 'default' => '', |
||
| 660 | ]); |
||
| 661 | $table->addColumn('type', 'string', [ |
||
| 662 | 'notnull' => true, |
||
| 663 | 'length' => 64, |
||
| 664 | 'default' => '', |
||
| 665 | ]); |
||
| 666 | $table->addColumn('category', 'string', [ |
||
| 667 | 'notnull' => true, |
||
| 668 | 'length' => 255, |
||
| 669 | 'default' => '', |
||
| 670 | ]); |
||
| 671 | $table->setPrimaryKey(['id']); |
||
| 672 | $table->addIndex(['uid'], 'uid_index'); |
||
| 673 | $table->addIndex(['type'], 'type_index'); |
||
| 674 | $table->addIndex(['category'], 'category_index'); |
||
| 675 | } |
||
| 676 | |||
| 677 | if (!$schema->hasTable('vcategory_to_object')) { |
||
| 678 | $table = $schema->createTable('vcategory_to_object'); |
||
| 679 | $table->addColumn('objid', 'integer', [ |
||
| 680 | 'notnull' => true, |
||
| 681 | 'length' => 4, |
||
| 682 | 'default' => 0, |
||
| 683 | 'unsigned' => true, |
||
| 684 | ]); |
||
| 685 | $table->addColumn('categoryid', 'integer', [ |
||
| 686 | 'notnull' => true, |
||
| 687 | 'length' => 4, |
||
| 688 | 'default' => 0, |
||
| 689 | 'unsigned' => true, |
||
| 690 | ]); |
||
| 691 | $table->addColumn('type', 'string', [ |
||
| 692 | 'notnull' => true, |
||
| 693 | 'length' => 64, |
||
| 694 | 'default' => '', |
||
| 695 | ]); |
||
| 696 | $table->setPrimaryKey(['categoryid', 'objid', 'type']); |
||
| 697 | $table->addIndex(['objid', 'type'], 'vcategory_objectd_index'); |
||
| 698 | } |
||
| 699 | |||
| 700 | if (!$schema->hasTable('systemtag')) { |
||
| 701 | $table = $schema->createTable('systemtag'); |
||
| 702 | $table->addColumn('id', 'integer', [ |
||
| 703 | 'autoincrement' => true, |
||
| 704 | 'notnull' => true, |
||
| 705 | 'length' => 4, |
||
| 706 | 'unsigned' => true, |
||
| 707 | ]); |
||
| 708 | $table->addColumn('name', 'string', [ |
||
| 709 | 'notnull' => true, |
||
| 710 | 'length' => 64, |
||
| 711 | 'default' => '', |
||
| 712 | ]); |
||
| 713 | $table->addColumn('visibility', 'smallint', [ |
||
| 714 | 'notnull' => true, |
||
| 715 | 'length' => 1, |
||
| 716 | 'default' => 1, |
||
| 717 | ]); |
||
| 718 | $table->addColumn('editable', 'smallint', [ |
||
| 719 | 'notnull' => true, |
||
| 720 | 'length' => 1, |
||
| 721 | 'default' => 1, |
||
| 722 | ]); |
||
| 723 | $table->setPrimaryKey(['id']); |
||
| 724 | $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident'); |
||
| 725 | } |
||
| 726 | |||
| 727 | if (!$schema->hasTable('systemtag_object_mapping')) { |
||
| 728 | $table = $schema->createTable('systemtag_object_mapping'); |
||
| 729 | $table->addColumn('objectid', 'string', [ |
||
| 730 | 'notnull' => true, |
||
| 731 | 'length' => 64, |
||
| 732 | 'default' => '', |
||
| 733 | ]); |
||
| 734 | $table->addColumn('objecttype', 'string', [ |
||
| 735 | 'notnull' => true, |
||
| 736 | 'length' => 64, |
||
| 737 | 'default' => '', |
||
| 738 | ]); |
||
| 739 | $table->addColumn('systemtagid', 'integer', [ |
||
| 740 | 'notnull' => true, |
||
| 741 | 'length' => 4, |
||
| 742 | 'default' => 0, |
||
| 743 | 'unsigned' => true, |
||
| 744 | ]); |
||
| 745 | $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk'); |
||
| 746 | // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping'); |
||
| 747 | } |
||
| 748 | |||
| 749 | if (!$schema->hasTable('systemtag_group')) { |
||
| 750 | $table = $schema->createTable('systemtag_group'); |
||
| 751 | $table->addColumn('systemtagid', 'integer', [ |
||
| 752 | 'notnull' => true, |
||
| 753 | 'length' => 4, |
||
| 754 | 'default' => 0, |
||
| 755 | 'unsigned' => true, |
||
| 756 | ]); |
||
| 757 | $table->addColumn('gid', 'string', [ |
||
| 758 | 'notnull' => true, |
||
| 759 | ]); |
||
| 760 | $table->setPrimaryKey(['gid', 'systemtagid']); |
||
| 761 | } |
||
| 762 | |||
| 763 | if (!$schema->hasTable('file_locks')) { |
||
| 764 | $table = $schema->createTable('file_locks'); |
||
| 765 | $table->addColumn('id', 'integer', [ |
||
| 766 | 'autoincrement' => true, |
||
| 767 | 'notnull' => true, |
||
| 768 | 'length' => 4, |
||
| 769 | 'unsigned' => true, |
||
| 770 | ]); |
||
| 771 | $table->addColumn('lock', 'integer', [ |
||
| 772 | 'notnull' => true, |
||
| 773 | 'length' => 4, |
||
| 774 | 'default' => 0, |
||
| 775 | ]); |
||
| 776 | $table->addColumn('key', 'string', [ |
||
| 777 | 'notnull' => true, |
||
| 778 | 'length' => 64, |
||
| 779 | ]); |
||
| 780 | $table->addColumn('ttl', 'integer', [ |
||
| 781 | 'notnull' => true, |
||
| 782 | 'length' => 4, |
||
| 783 | 'default' => -1, |
||
| 784 | ]); |
||
| 785 | $table->setPrimaryKey(['id']); |
||
| 786 | $table->addUniqueIndex(['key'], 'lock_key_index'); |
||
| 787 | $table->addIndex(['ttl'], 'lock_ttl_index'); |
||
| 788 | } |
||
| 789 | |||
| 790 | if (!$schema->hasTable('comments')) { |
||
| 791 | $table = $schema->createTable('comments'); |
||
| 792 | $table->addColumn('id', 'integer', [ |
||
| 793 | 'autoincrement' => true, |
||
| 794 | 'notnull' => true, |
||
| 795 | 'length' => 4, |
||
| 796 | 'unsigned' => true, |
||
| 797 | ]); |
||
| 798 | $table->addColumn('parent_id', 'integer', [ |
||
| 799 | 'notnull' => true, |
||
| 800 | 'length' => 4, |
||
| 801 | 'default' => 0, |
||
| 802 | 'unsigned' => true, |
||
| 803 | ]); |
||
| 804 | $table->addColumn('topmost_parent_id', 'integer', [ |
||
| 805 | 'notnull' => true, |
||
| 806 | 'length' => 4, |
||
| 807 | 'default' => 0, |
||
| 808 | 'unsigned' => true, |
||
| 809 | ]); |
||
| 810 | $table->addColumn('children_count', 'integer', [ |
||
| 811 | 'notnull' => true, |
||
| 812 | 'length' => 4, |
||
| 813 | 'default' => 0, |
||
| 814 | 'unsigned' => true, |
||
| 815 | ]); |
||
| 816 | $table->addColumn('actor_type', 'string', [ |
||
| 817 | 'notnull' => true, |
||
| 818 | 'length' => 64, |
||
| 819 | 'default' => '', |
||
| 820 | ]); |
||
| 821 | $table->addColumn('actor_id', 'string', [ |
||
| 822 | 'notnull' => true, |
||
| 823 | 'length' => 64, |
||
| 824 | 'default' => '', |
||
| 825 | ]); |
||
| 826 | $table->addColumn('message', 'text', [ |
||
| 827 | 'notnull' => false, |
||
| 828 | ]); |
||
| 829 | $table->addColumn('verb', 'string', [ |
||
| 830 | 'notnull' => false, |
||
| 831 | 'length' => 64, |
||
| 832 | ]); |
||
| 833 | $table->addColumn('creation_timestamp', 'datetime', [ |
||
| 834 | 'notnull' => false, |
||
| 835 | ]); |
||
| 836 | $table->addColumn('latest_child_timestamp', 'datetime', [ |
||
| 837 | 'notnull' => false, |
||
| 838 | ]); |
||
| 839 | $table->addColumn('object_type', 'string', [ |
||
| 840 | 'notnull' => true, |
||
| 841 | 'length' => 64, |
||
| 842 | 'default' => '', |
||
| 843 | ]); |
||
| 844 | $table->addColumn('object_id', 'string', [ |
||
| 845 | 'notnull' => true, |
||
| 846 | 'length' => 64, |
||
| 847 | 'default' => '', |
||
| 848 | ]); |
||
| 849 | $table->addColumn('reference_id', 'string', [ |
||
| 850 | 'notnull' => false, |
||
| 851 | 'length' => 64, |
||
| 852 | ]); |
||
| 853 | $table->setPrimaryKey(['id']); |
||
| 854 | $table->addIndex(['parent_id'], 'comments_parent_id_index'); |
||
| 855 | $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx'); |
||
| 856 | $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index'); |
||
| 857 | $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index'); |
||
| 858 | } |
||
| 859 | |||
| 860 | if (!$schema->hasTable('comments_read_markers')) { |
||
| 861 | $table = $schema->createTable('comments_read_markers'); |
||
| 862 | $table->addColumn('user_id', 'string', [ |
||
| 863 | 'notnull' => true, |
||
| 864 | 'length' => 64, |
||
| 865 | 'default' => '', |
||
| 866 | ]); |
||
| 867 | $table->addColumn('marker_datetime', 'datetime', [ |
||
| 868 | 'notnull' => false, |
||
| 869 | ]); |
||
| 870 | $table->addColumn('object_type', 'string', [ |
||
| 871 | 'notnull' => true, |
||
| 872 | 'length' => 64, |
||
| 873 | 'default' => '', |
||
| 874 | ]); |
||
| 875 | $table->addColumn('object_id', 'string', [ |
||
| 876 | 'notnull' => true, |
||
| 877 | 'length' => 64, |
||
| 878 | 'default' => '', |
||
| 879 | ]); |
||
| 880 | $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); |
||
| 881 | $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk'); |
||
| 882 | // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index'); |
||
| 883 | } |
||
| 884 | |||
| 885 | // if (!$schema->hasTable('credentials')) { |
||
| 886 | // $table = $schema->createTable('credentials'); |
||
| 887 | // $table->addColumn('user', 'string', [ |
||
| 888 | // 'notnull' => false, |
||
| 889 | // 'length' => 64, |
||
| 890 | // ]); |
||
| 891 | // $table->addColumn('identifier', 'string', [ |
||
| 892 | // 'notnull' => true, |
||
| 893 | // 'length' => 64, |
||
| 894 | // ]); |
||
| 895 | // $table->addColumn('credentials', 'text', [ |
||
| 896 | // 'notnull' => false, |
||
| 897 | // ]); |
||
| 898 | // $table->setPrimaryKey(['user', 'identifier']); |
||
| 899 | // $table->addIndex(['user'], 'credentials_user'); |
||
| 900 | // } |
||
| 901 | |||
| 902 | if (!$schema->hasTable('admin_sections')) { |
||
| 903 | $table = $schema->createTable('admin_sections'); |
||
| 904 | $table->addColumn('id', 'string', [ |
||
| 905 | 'notnull' => true, |
||
| 906 | 'length' => 64, |
||
| 907 | ]); |
||
| 908 | $table->addColumn('class', 'string', [ |
||
| 909 | 'notnull' => true, |
||
| 910 | 'length' => 255, |
||
| 911 | 'default' => '', |
||
| 912 | ]); |
||
| 913 | $table->addColumn('priority', 'smallint', [ |
||
| 914 | 'notnull' => true, |
||
| 915 | 'length' => 1, |
||
| 916 | 'default' => 0, |
||
| 917 | ]); |
||
| 918 | $table->setPrimaryKey(['id']); |
||
| 919 | $table->addUniqueIndex(['class'], 'admin_sections_class'); |
||
| 920 | } |
||
| 921 | |||
| 922 | if (!$schema->hasTable('admin_settings')) { |
||
| 923 | $table = $schema->createTable('admin_settings'); |
||
| 924 | $table->addColumn('id', 'integer', [ |
||
| 925 | 'autoincrement' => true, |
||
| 926 | 'notnull' => true, |
||
| 927 | 'length' => 4, |
||
| 928 | ]); |
||
| 929 | $table->addColumn('class', 'string', [ |
||
| 930 | 'notnull' => true, |
||
| 931 | 'length' => 255, |
||
| 932 | 'default' => '', |
||
| 933 | ]); |
||
| 934 | $table->addColumn('section', 'string', [ |
||
| 935 | 'notnull' => false, |
||
| 936 | 'length' => 64, |
||
| 937 | ]); |
||
| 938 | $table->addColumn('priority', 'smallint', [ |
||
| 939 | 'notnull' => true, |
||
| 940 | 'length' => 1, |
||
| 941 | 'default' => 0, |
||
| 942 | ]); |
||
| 943 | $table->setPrimaryKey(['id']); |
||
| 944 | $table->addUniqueIndex(['class'], 'admin_settings_class'); |
||
| 945 | $table->addIndex(['section'], 'admin_settings_section'); |
||
| 946 | } |
||
| 947 | |||
| 948 | if (!$schema->hasTable('personal_sections')) { |
||
| 949 | $table = $schema->createTable('personal_sections'); |
||
| 950 | $table->addColumn('id', 'string', [ |
||
| 951 | 'notnull' => true, |
||
| 952 | 'length' => 64, |
||
| 953 | ]); |
||
| 954 | $table->addColumn('class', 'string', [ |
||
| 955 | 'notnull' => true, |
||
| 956 | 'length' => 255, |
||
| 957 | 'default' => '', |
||
| 958 | ]); |
||
| 959 | $table->addColumn('priority', 'smallint', [ |
||
| 960 | 'notnull' => true, |
||
| 961 | 'length' => 1, |
||
| 962 | 'default' => 0, |
||
| 963 | ]); |
||
| 964 | $table->setPrimaryKey(['id']); |
||
| 965 | $table->addUniqueIndex(['class'], 'personal_sections_class'); |
||
| 966 | } |
||
| 967 | |||
| 968 | if (!$schema->hasTable('personal_settings')) { |
||
| 969 | $table = $schema->createTable('personal_settings'); |
||
| 970 | $table->addColumn('id', 'integer', [ |
||
| 971 | 'autoincrement' => true, |
||
| 972 | 'notnull' => true, |
||
| 973 | 'length' => 4, |
||
| 974 | ]); |
||
| 975 | $table->addColumn('class', 'string', [ |
||
| 976 | 'notnull' => true, |
||
| 977 | 'length' => 255, |
||
| 978 | 'default' => '', |
||
| 979 | ]); |
||
| 980 | $table->addColumn('section', 'string', [ |
||
| 981 | 'notnull' => false, |
||
| 982 | 'length' => 64, |
||
| 983 | ]); |
||
| 984 | $table->addColumn('priority', 'smallint', [ |
||
| 985 | 'notnull' => true, |
||
| 986 | 'length' => 1, |
||
| 987 | 'default' => 0, |
||
| 988 | ]); |
||
| 989 | $table->setPrimaryKey(['id']); |
||
| 990 | $table->addUniqueIndex(['class'], 'personal_settings_class'); |
||
| 991 | $table->addIndex(['section'], 'personal_settings_section'); |
||
| 992 | } |
||
| 993 | |||
| 994 | if (!$schema->hasTable('accounts')) { |
||
| 995 | $table = $schema->createTable('accounts'); |
||
| 996 | $table->addColumn('uid', 'string', [ |
||
| 997 | 'notnull' => true, |
||
| 998 | 'length' => 64, |
||
| 999 | 'default' => '', |
||
| 1000 | ]); |
||
| 1001 | $table->addColumn('data', 'text', [ |
||
| 1002 | 'notnull' => true, |
||
| 1003 | 'default' => '', |
||
| 1004 | ]); |
||
| 1005 | $table->setPrimaryKey(['uid']); |
||
| 1006 | } |
||
| 1007 | return $schema; |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
||
| 1035 | } |
||
| 1036 | } |
||
| 1037 | } |
||
| 1038 |