Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ConvertFilecacheBigInt.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Alecks Gates <alecks.g@gmail.com>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author timm2k <timm2k@gmx.de>
  13. *
  14. * @license GNU AGPL version 3 or any later version
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as
  18. * published by the Free Software Foundation, either version 3 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. */
  30. namespace OC\Core\Command\Db;
  31. use Doctrine\DBAL\Platforms\SqlitePlatform;
  32. use Doctrine\DBAL\Types\Type;
  33. use Doctrine\DBAL\Types\Types;
  34. use OC\DB\SchemaWrapper;
  35. use OCP\IDBConnection;
  36. use Symfony\Component\Console\Command\Command;
  37. use Symfony\Component\Console\Input\InputInterface;
  38. use Symfony\Component\Console\Output\OutputInterface;
  39. use Symfony\Component\Console\Question\ConfirmationQuestion;
  40. class ConvertFilecacheBigInt extends Command {
  41. /** @var IDBConnection */
  42. private $connection;
  43. /**
  44. * @param IDBConnection $connection
  45. */
  46. public function __construct(IDBConnection $connection) {
  47. $this->connection = $connection;
  48. parent::__construct();
  49. }
  50. protected function configure() {
  51. $this
  52. ->setName('db:convert-filecache-bigint')
  53. ->setDescription('Convert the ID columns of the filecache to BigInt');
  54. }
  55. protected function getColumnsByTable() {
  56. // also update in CheckSetupController::hasBigIntConversionPendingColumns()
  57. return [
  58. 'activity' => ['activity_id', 'object_id'],
  59. 'activity_mq' => ['mail_id'],
  60. 'authtoken' => ['id'],
  61. 'bruteforce_attempts' => ['id'],
  62. 'federated_reshares' => ['share_id'],
  63. 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
  64. 'filecache_extended' => ['fileid'],
  65. 'files_trash' => ['auto_id'],
  66. 'file_locks' => ['id'],
  67. 'jobs' => ['id'],
  68. 'mimetypes' => ['id'],
  69. 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
  70. 'share_external' => ['id', 'parent'],
  71. 'storages' => ['numeric_id'],
  72. ];
  73. }
  74. protected function execute(InputInterface $input, OutputInterface $output): int {
  75. $schema = new SchemaWrapper($this->connection);
  76. $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
  77. $updates = [];
  78. $tables = $this->getColumnsByTable();
  79. foreach ($tables as $tableName => $columns) {
  80. if (!$schema->hasTable($tableName)) {
  81. continue;
  82. }
  83. $table = $schema->getTable($tableName);
  84. foreach ($columns as $columnName) {
  85. $column = $table->getColumn($columnName);
  86. $isAutoIncrement = $column->getAutoincrement();
  87. $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
  88. if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
  89. $column->setType(Type::getType(Types::BIGINT));
  90. $column->setOptions(['length' => 20]);
  91. $updates[] = '* ' . $tableName . '.' . $columnName;
  92. }
  93. }
  94. }
  95. if (empty($updates)) {
  96. $output->writeln('<info>All tables already up to date!</info>');
  97. return 0;
  98. }
  99. $output->writeln('<comment>Following columns will be updated:</comment>');
  100. $output->writeln('');
  101. $output->writeln($updates);
  102. $output->writeln('');
  103. $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>');
  104. if ($input->isInteractive()) {
  105. $helper = $this->getHelper('question');
  106. $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
  107. if (!$helper->ask($input, $output, $question)) {
  108. return 1;
  109. }
  110. }
  111. $this->connection->migrateToSchema($schema->getWrappedSchema());
  112. return 0;
  113. }
  114. }