1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2017 Bjoern Schiessle <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
namespace OC\Core\Command\Db; |
25
|
|
|
|
26
|
|
|
use OC\DB\SchemaWrapper; |
27
|
|
|
use OCP\IDBConnection; |
28
|
|
|
use Symfony\Component\Console\Command\Command; |
29
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
30
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
31
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
32
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class AddMissingIndices |
36
|
|
|
* |
37
|
|
|
* if you added any new indices to the database, this is the right place to add |
38
|
|
|
* it your update routine for existing instances |
39
|
|
|
* |
40
|
|
|
* @package OC\Core\Command\Db |
41
|
|
|
*/ |
42
|
|
|
class AddMissingIndices extends Command { |
43
|
|
|
|
44
|
|
|
/** @var IDBConnection */ |
45
|
|
|
private $connection; |
46
|
|
|
|
47
|
|
|
/** @var EventDispatcherInterface */ |
48
|
|
|
private $dispatcher; |
49
|
|
|
|
50
|
|
|
public function __construct(IDBConnection $connection, EventDispatcherInterface $dispatcher) { |
51
|
|
|
parent::__construct(); |
52
|
|
|
|
53
|
|
|
$this->connection = $connection; |
54
|
|
|
$this->dispatcher = $dispatcher; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function configure() { |
58
|
|
|
$this |
59
|
|
|
->setName('db:add-missing-indices') |
60
|
|
|
->setDescription('Add missing indices to the database tables'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
64
|
|
|
$this->addCoreIndexes($output); |
65
|
|
|
|
66
|
|
|
// Dispatch event so apps can also update indexes if needed |
67
|
|
|
$event = new GenericEvent($output); |
68
|
|
|
$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* add missing indices to the share table |
73
|
|
|
* |
74
|
|
|
* @param OutputInterface $output |
75
|
|
|
* @throws \Doctrine\DBAL\Schema\SchemaException |
76
|
|
|
*/ |
77
|
|
|
private function addCoreIndexes(OutputInterface $output) { |
78
|
|
|
|
79
|
|
|
$output->writeln('<info>Check indices of the share table.</info>'); |
80
|
|
|
|
81
|
|
|
$schema = new SchemaWrapper($this->connection); |
82
|
|
|
$updated = false; |
83
|
|
|
|
84
|
|
|
if ($schema->hasTable('share')) { |
85
|
|
|
$table = $schema->getTable('share'); |
86
|
|
|
if (!$table->hasIndex('share_with_index')) { |
87
|
|
|
$output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>'); |
88
|
|
|
$table->addIndex(['share_with'], 'share_with_index'); |
89
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
90
|
|
|
$updated = true; |
91
|
|
|
$output->writeln('<info>Share table updated successfully.</info>'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (!$table->hasIndex('parent_index')) { |
95
|
|
|
$output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>'); |
96
|
|
|
$table->addIndex(['parent'], 'parent_index'); |
97
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
98
|
|
|
$updated = true; |
99
|
|
|
$output->writeln('<info>Share table updated successfully.</info>'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (!$table->hasIndex('owner_index')) { |
103
|
|
|
$output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>'); |
104
|
|
|
$table->addIndex(['uid_owner'], 'owner_index'); |
105
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
106
|
|
|
$updated = true; |
107
|
|
|
$output->writeln('<info>Share table updated successfully.</info>'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (!$table->hasIndex('initiator_index')) { |
111
|
|
|
$output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>'); |
112
|
|
|
$table->addIndex(['uid_initiator'], 'initiator_index'); |
113
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
114
|
|
|
$updated = true; |
115
|
|
|
$output->writeln('<info>Share table updated successfully.</info>'); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$output->writeln('<info>Check indices of the filecache table.</info>'); |
120
|
|
|
if ($schema->hasTable('filecache')) { |
121
|
|
|
$table = $schema->getTable('filecache'); |
122
|
|
|
if (!$table->hasIndex('fs_mtime')) { |
123
|
|
|
$output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>'); |
124
|
|
|
$table->addIndex(['mtime'], 'fs_mtime'); |
125
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
126
|
|
|
$updated = true; |
127
|
|
|
$output->writeln('<info>Filecache table updated successfully.</info>'); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$output->writeln('<info>Check indices of the twofactor_providers table.</info>'); |
132
|
|
|
if ($schema->hasTable('twofactor_providers')) { |
133
|
|
|
$table = $schema->getTable('twofactor_providers'); |
134
|
|
|
if (!$table->hasIndex('twofactor_providers_uid')) { |
135
|
|
|
$output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>'); |
136
|
|
|
$table->addIndex(['uid'], 'twofactor_providers_uid'); |
137
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
138
|
|
|
$updated = true; |
139
|
|
|
$output->writeln('<info>Twofactor_providers table updated successfully.</info>'); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
if (!$updated) { |
144
|
|
|
$output->writeln('<info>Done.</info>'); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|