1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2021 René Gieling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author René Gieling <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Polls\Migration; |
25
|
|
|
|
26
|
|
|
use OC\DB\Connection; |
|
|
|
|
27
|
|
|
use OC\DB\SchemaWrapper; |
|
|
|
|
28
|
|
|
use OCP\Migration\IRepairStep; |
29
|
|
|
use OCP\Migration\IOutput; |
30
|
|
|
|
31
|
|
|
class RemoveIndices implements IRepairStep { |
32
|
|
|
/** @var Connection */ |
33
|
|
|
private $connection; |
34
|
|
|
|
35
|
|
|
public function __construct(Connection $connection) { |
36
|
|
|
$this->connection = $connection; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getName() { |
40
|
|
|
return 'Remove polls table indices'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function run(IOutput $output) { |
44
|
|
|
$this->removeUniqueIndices('polls_options'); |
45
|
|
|
$this->removeUniqueIndices('polls_log'); |
46
|
|
|
$this->removeUniqueIndices('polls_notif'); |
47
|
|
|
$this->removeUniqueIndices('polls_share'); |
48
|
|
|
$this->removeUniqueIndices('polls_votes'); |
49
|
|
|
$this->removeUniqueIndices('polls_preferences'); |
50
|
|
|
$this->removeUniqueIndices('polls_preferences'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* remove an index with $indexName from $table |
55
|
|
|
*/ |
56
|
|
|
private function removeIndex(string $tableName, string $indexName) { |
57
|
|
|
$schema = new SchemaWrapper($this->connection); |
58
|
|
|
if ($schema->hasTable($tableName)) { |
59
|
|
|
$table = $schema->getTable($tableName); |
60
|
|
|
if ($table->hasIndex($indexName)) { |
61
|
|
|
$table->dropIndex($indexName); |
62
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* remove all UNIQUE indices from $table |
69
|
|
|
*/ |
70
|
|
|
private function removeUniqueIndices(string $tableName) { |
71
|
|
|
$schema = new SchemaWrapper($this->connection); |
72
|
|
|
if ($schema->hasTable($tableName)) { |
73
|
|
|
$table = $schema->getTable($tableName); |
74
|
|
|
foreach ($table->getIndexes() as $index) { |
75
|
|
|
if (strpos($index->getName(), 'UNIQ_') === 0) { |
76
|
|
|
$this->removeIndex($tableName, $index->getName()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths