1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[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 OC\Core\Command\Db; |
25
|
|
|
|
26
|
|
|
use Doctrine\DBAL\Types\Type; |
27
|
|
|
use OC\DB\SchemaWrapper; |
28
|
|
|
use OCP\IDBConnection; |
29
|
|
|
use Symfony\Component\Console\Command\Command; |
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
31
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
32
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
33
|
|
|
|
34
|
|
|
class ConvertFilecacheBigInt extends Command { |
35
|
|
|
|
36
|
|
|
/** @var IDBConnection */ |
37
|
|
|
private $connection; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param IDBConnection $connection |
41
|
|
|
*/ |
42
|
|
|
public function __construct(IDBConnection $connection) { |
43
|
|
|
$this->connection = $connection; |
44
|
|
|
parent::__construct(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function configure() { |
48
|
|
|
$this |
49
|
|
|
->setName('db:convert-filecache-bigint') |
50
|
|
|
->setDescription('Convert the ID columns of the filecache to BigInt'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function getColumnsByTable() { |
54
|
|
|
return [ |
55
|
|
|
'activity' => ['activity_id', 'object_id'], |
56
|
|
|
'activity_mq' => ['mail_id'], |
57
|
|
|
'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart'], |
58
|
|
|
'mimetypes' => ['id'], |
59
|
|
|
'storages' => ['numeric_id'], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
64
|
|
|
|
65
|
|
|
$schema = new SchemaWrapper($this->connection); |
66
|
|
|
$updates = []; |
67
|
|
|
|
68
|
|
|
$tables = $this->getColumnsByTable(); |
69
|
|
|
foreach ($tables as $tableName => $columns) { |
70
|
|
|
if (!$schema->hasTable($tableName)) { |
71
|
|
|
continue; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$table = $schema->getTable($tableName); |
75
|
|
|
|
76
|
|
|
foreach ($columns as $columnName) { |
77
|
|
|
$column = $table->getColumn($columnName); |
78
|
|
|
if ($column->getType()->getName() !== Type::BIGINT) { |
79
|
|
|
$column->setType(Type::getType(Type::BIGINT)); |
80
|
|
|
$column->setOptions(['length' => 20]); |
81
|
|
|
|
82
|
|
|
$updates[] = $tableName . '.' . $columnName; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (empty($updates)) { |
88
|
|
|
$output->writeln('<info>All tables already up to date!</info>'); |
89
|
|
|
return 0; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>'); |
93
|
|
|
|
94
|
|
View Code Duplication |
if ($input->isInteractive()) { |
95
|
|
|
$helper = $this->getHelper('question'); |
96
|
|
|
$question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
97
|
|
|
|
98
|
|
|
if (!$helper->ask($input, $output, $question)) { |
99
|
|
|
return 1; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
104
|
|
|
|
105
|
|
|
return 0; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|