Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ConvertFilecacheBigInt.php 3.1KB

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