Version11300Date20201120141438.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Sharing\Migration;
  8. use Closure;
  9. use Doctrine\DBAL\Types\Type;
  10. use OCP\DB\ISchemaWrapper;
  11. use OCP\DB\Types;
  12. use OCP\IDBConnection;
  13. use OCP\Migration\IOutput;
  14. use OCP\Migration\SimpleMigrationStep;
  15. class Version11300Date20201120141438 extends SimpleMigrationStep {
  16. /** @var IDBConnection */
  17. private $connection;
  18. public function __construct(IDBConnection $connection) {
  19. $this->connection = $connection;
  20. }
  21. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. if (!$schema->hasTable('share_external')) {
  25. $table = $schema->createTable('share_external');
  26. $table->addColumn('id', Types::BIGINT, [
  27. 'autoincrement' => true,
  28. 'notnull' => true,
  29. ]);
  30. $table->addColumn('parent', Types::BIGINT, [
  31. 'notnull' => false,
  32. 'default' => -1,
  33. ]);
  34. $table->addColumn('share_type', Types::INTEGER, [
  35. 'notnull' => false,
  36. 'length' => 4,
  37. ]);
  38. $table->addColumn('remote', Types::STRING, [
  39. 'notnull' => true,
  40. 'length' => 512,
  41. ]);
  42. $table->addColumn('remote_id', Types::STRING, [
  43. 'notnull' => false,
  44. 'length' => 255,
  45. 'default' => '',
  46. ]);
  47. $table->addColumn('share_token', Types::STRING, [
  48. 'notnull' => true,
  49. 'length' => 64,
  50. ]);
  51. $table->addColumn('password', Types::STRING, [
  52. 'notnull' => false,
  53. 'length' => 64,
  54. ]);
  55. $table->addColumn('name', Types::STRING, [
  56. 'notnull' => true,
  57. 'length' => 64,
  58. ]);
  59. $table->addColumn('owner', Types::STRING, [
  60. 'notnull' => true,
  61. 'length' => 64,
  62. ]);
  63. $table->addColumn('user', Types::STRING, [
  64. 'notnull' => true,
  65. 'length' => 64,
  66. ]);
  67. $table->addColumn('mountpoint', Types::STRING, [
  68. 'notnull' => true,
  69. 'length' => 4000,
  70. ]);
  71. $table->addColumn('mountpoint_hash', Types::STRING, [
  72. 'notnull' => true,
  73. 'length' => 32,
  74. ]);
  75. $table->addColumn('accepted', Types::INTEGER, [
  76. 'notnull' => true,
  77. 'length' => 4,
  78. 'default' => 0,
  79. ]);
  80. $table->setPrimaryKey(['id']);
  81. $table->addUniqueIndex(['user', 'mountpoint_hash'], 'sh_external_mp');
  82. } else {
  83. $table = $schema->getTable('share_external');
  84. $remoteIdColumn = $table->getColumn('remote_id');
  85. if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) {
  86. $remoteIdColumn->setNotnull(false);
  87. $remoteIdColumn->setType(Type::getType(Types::STRING));
  88. $remoteIdColumn->setOptions(['length' => 255]);
  89. $remoteIdColumn->setDefault('');
  90. }
  91. if (!$table->hasColumn('parent')) {
  92. $table->addColumn('parent', Types::BIGINT, [
  93. 'notnull' => false,
  94. 'default' => -1,
  95. ]);
  96. }
  97. if (!$table->hasColumn('share_type')) {
  98. $table->addColumn('share_type', Types::INTEGER, [
  99. 'notnull' => false,
  100. 'length' => 4,
  101. ]);
  102. }
  103. if ($table->hasColumn('lastscan')) {
  104. $table->dropColumn('lastscan');
  105. }
  106. }
  107. return $schema;
  108. }
  109. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  110. $qb = $this->connection->getQueryBuilder();
  111. $qb->update('share_external')
  112. ->set('remote_id', $qb->createNamedParameter(''))
  113. ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1')));
  114. $qb->execute();
  115. }
  116. }