|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> |
| 6 | + * |
| 7 | + * @author Joas Schilling <coding@schilljs.com> |
| 8 | + * |
| 9 | + * @license GNU AGPL version 3 or any later version |
| 10 | + * |
| 11 | + * This program is free software: you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU Affero General Public License as |
| 13 | + * published by the Free Software Foundation, either version 3 of the |
| 14 | + * License, or (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace OC\Core\Migrations; |
| 27 | + |
| 28 | +use Closure; |
| 29 | +use OCP\DB\ISchemaWrapper; |
| 30 | +use OCP\Migration\IOutput; |
| 31 | +use OCP\Migration\SimpleMigrationStep; |
| 32 | + |
| 33 | +class Version20000Date20201109081920 extends SimpleMigrationStep { |
| 34 | + |
| 35 | + /** |
| 36 | + * @param IOutput $output |
| 37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 38 | + * @param array $options |
| 39 | + * @return null|ISchemaWrapper |
| 40 | + */ |
| 41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
| 42 | + /** @var ISchemaWrapper $schema */ |
| 43 | + $schema = $schemaClosure(); |
| 44 | + $updated = false; |
| 45 | + |
| 46 | + if ($schema->hasTable('systemtag_object_mapping')) { |
| 47 | + $table = $schema->getTable('systemtag_object_mapping'); |
| 48 | + if (!$table->hasPrimaryKey()) { |
| 49 | + $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk'); |
| 50 | + if ($table->hasIndex('mapping')) { |
| 51 | + $table->dropIndex('mapping'); |
| 52 | + } |
| 53 | + $updated = true; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + if ($schema->hasTable('comments_read_markers')) { |
| 58 | + $table = $schema->getTable('comments_read_markers'); |
| 59 | + if (!$table->hasPrimaryKey()) { |
| 60 | + $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk'); |
| 61 | + if ($table->hasIndex('comments_marker_index')) { |
| 62 | + $table->dropIndex('comments_marker_index'); |
| 63 | + } |
| 64 | + $updated = true; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + if ($schema->hasTable('collres_resources')) { |
| 69 | + $table = $schema->getTable('collres_resources'); |
| 70 | + if (!$table->hasPrimaryKey()) { |
| 71 | + $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk'); |
| 72 | + if ($table->hasIndex('collres_unique_res')) { |
| 73 | + $table->dropIndex('collres_unique_res'); |
| 74 | + } |
| 75 | + $updated = true; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + if ($schema->hasTable('collres_accesscache')) { |
| 80 | + $table = $schema->getTable('collres_accesscache'); |
| 81 | + if (!$table->hasPrimaryKey()) { |
| 82 | + $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk'); |
| 83 | + if ($table->hasIndex('collres_unique_user')) { |
| 84 | + $table->dropIndex('collres_unique_user'); |
| 85 | + } |
| 86 | + $updated = true; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if ($schema->hasTable('filecache_extended')) { |
| 91 | + $table = $schema->getTable('filecache_extended'); |
| 92 | + if (!$table->hasPrimaryKey()) { |
| 93 | + $table->setPrimaryKey(['fileid'], 'fce_pk'); |
| 94 | + if ($table->hasIndex('fce_fileid_idx')) { |
| 95 | + $table->dropIndex('fce_fileid_idx'); |
| 96 | + } |
| 97 | + $updated = true; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + return $updated ? $schema : null; |
| 102 | + } |
| 103 | +} |
0 commit comments