|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[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
|
|
|
|
|
25
|
|
|
namespace OCA\RichDocuments\Command; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform; |
|
28
|
|
|
use Doctrine\DBAL\Types\Type; |
|
29
|
|
|
use OC\DB\Connection; |
|
30
|
|
|
use OCP\DB\Types; |
|
31
|
|
|
use OC\DB\SchemaWrapper; |
|
32
|
|
|
use OCP\IDBConnection; |
|
33
|
|
|
use Symfony\Component\Console\Command\Command; |
|
34
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
35
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
36
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
37
|
|
|
|
|
38
|
|
|
class ConvertToBigInt extends Command { |
|
39
|
|
|
|
|
40
|
|
|
/** @var IDBConnection */ |
|
41
|
|
|
private $connection; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param IDBConnection $connection |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(Connection $connection) { |
|
47
|
|
|
$this->connection = $connection; |
|
|
|
|
|
|
48
|
|
|
parent::__construct(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function configure() { |
|
52
|
|
|
$this |
|
53
|
|
|
->setName('richdocuments:convert-bigint') |
|
54
|
|
|
->setDescription('Convert the ID columns of the richdocuments tables to BigInt'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function getColumnsByTable() { |
|
58
|
|
|
return [ |
|
59
|
|
|
'richdocuments_wopi' => ['id', 'fileid', 'version', 'template_id', 'template_destination', 'expiry'], |
|
60
|
|
|
'richdocuments_direct' => ['id', 'fileid', 'template_id', 'template_destination', 'timestamp'], |
|
61
|
|
|
'richdocuments_assets' => ['id', 'fileid', 'timestamp'], |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
|
66
|
|
|
$schema = new SchemaWrapper($this->connection); |
|
67
|
|
|
$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform; |
|
|
|
|
|
|
68
|
|
|
$updates = []; |
|
69
|
|
|
|
|
70
|
|
|
$tables = $this->getColumnsByTable(); |
|
71
|
|
|
foreach ($tables as $tableName => $columns) { |
|
72
|
|
|
if (!$schema->hasTable($tableName)) { |
|
73
|
|
|
continue; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$table = $schema->getTable($tableName); |
|
77
|
|
|
|
|
78
|
|
|
foreach ($columns as $columnName) { |
|
79
|
|
|
$column = $table->getColumn($columnName); |
|
80
|
|
|
$isAutoIncrement = $column->getAutoincrement(); |
|
81
|
|
|
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; |
|
82
|
|
|
if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) { |
|
83
|
|
|
$column->setType(Type::getType(Types::BIGINT)); |
|
84
|
|
|
$column->setOptions(['length' => 20]); |
|
85
|
|
|
$column->setUnsigned(true); |
|
86
|
|
|
|
|
87
|
|
|
$updates[] = '* ' . $tableName . '.' . $columnName; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (empty($updates)) { |
|
93
|
|
|
$output->writeln('<info>All tables already up to date!</info>'); |
|
94
|
|
|
return 0; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$output->writeln('<comment>Following columns will be updated:</comment>'); |
|
98
|
|
|
$output->writeln(''); |
|
99
|
|
|
$output->writeln($updates); |
|
100
|
|
|
$output->writeln(''); |
|
101
|
|
|
$output->writeln('<comment>This can take up to hours, depending on the number of Collabora WOPI tokens in your instance!</comment>'); |
|
102
|
|
|
|
|
103
|
|
|
if ($input->isInteractive()) { |
|
104
|
|
|
$helper = $this->getHelper('question'); |
|
105
|
|
|
$question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
106
|
|
|
|
|
107
|
|
|
if (!$helper->ask($input, $output, $question)) { |
|
108
|
|
|
return 1; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
113
|
|
|
|
|
114
|
|
|
return 0; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..