Version11300Date20201120141438.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Files_Sharing\Migration;
  27. use Closure;
  28. use Doctrine\DBAL\Types\Type;
  29. use OCP\DB\Types;
  30. use OCP\DB\ISchemaWrapper;
  31. use OCP\IDBConnection;
  32. use OCP\Migration\IOutput;
  33. use OCP\Migration\SimpleMigrationStep;
  34. class Version11300Date20201120141438 extends SimpleMigrationStep {
  35. /** @var IDBConnection */
  36. private $connection;
  37. public function __construct(IDBConnection $connection) {
  38. $this->connection = $connection;
  39. }
  40. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  41. /** @var ISchemaWrapper $schema */
  42. $schema = $schemaClosure();
  43. if (!$schema->hasTable('share_external')) {
  44. $table = $schema->createTable('share_external');
  45. $table->addColumn('id', Types::BIGINT, [
  46. 'autoincrement' => true,
  47. 'notnull' => true,
  48. ]);
  49. $table->addColumn('parent', Types::BIGINT, [
  50. 'notnull' => false,
  51. 'default' => -1,
  52. ]);
  53. $table->addColumn('share_type', Types::INTEGER, [
  54. 'notnull' => false,
  55. 'length' => 4,
  56. ]);
  57. $table->addColumn('remote', Types::STRING, [
  58. 'notnull' => true,
  59. 'length' => 512,
  60. ]);
  61. $table->addColumn('remote_id', Types::STRING, [
  62. 'notnull' => false,
  63. 'length' => 255,
  64. 'default' => '',
  65. ]);
  66. $table->addColumn('share_token', Types::STRING, [
  67. 'notnull' => true,
  68. 'length' => 64,
  69. ]);
  70. $table->addColumn('password', Types::STRING, [
  71. 'notnull' => false,
  72. 'length' => 64,
  73. ]);
  74. $table->addColumn('name', Types::STRING, [
  75. 'notnull' => true,
  76. 'length' => 64,
  77. ]);
  78. $table->addColumn('owner', Types::STRING, [
  79. 'notnull' => true,
  80. 'length' => 64,
  81. ]);
  82. $table->addColumn('user', Types::STRING, [
  83. 'notnull' => true,
  84. 'length' => 64,
  85. ]);
  86. $table->addColumn('mountpoint', Types::STRING, [
  87. 'notnull' => true,
  88. 'length' => 4000,
  89. ]);
  90. $table->addColumn('mountpoint_hash', Types::STRING, [
  91. 'notnull' => true,
  92. 'length' => 32,
  93. ]);
  94. $table->addColumn('accepted', Types::INTEGER, [
  95. 'notnull' => true,
  96. 'length' => 4,
  97. 'default' => 0,
  98. ]);
  99. $table->setPrimaryKey(['id']);
  100. $table->addUniqueIndex(['user', 'mountpoint_hash'], 'sh_external_mp');
  101. } else {
  102. $table = $schema->getTable('share_external');
  103. $remoteIdColumn = $table->getColumn('remote_id');
  104. if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) {
  105. $remoteIdColumn->setNotnull(false);
  106. $remoteIdColumn->setType(Type::getType(Types::STRING));
  107. $remoteIdColumn->setOptions(['length' => 255]);
  108. $remoteIdColumn->setDefault('');
  109. }
  110. if (!$table->hasColumn('parent')) {
  111. $table->addColumn('parent', Types::BIGINT, [
  112. 'notnull' => false,
  113. 'default' => -1,
  114. ]);
  115. }
  116. if (!$table->hasColumn('share_type')) {
  117. $table->addColumn('share_type', Types::INTEGER, [
  118. 'notnull' => false,
  119. 'length' => 4,
  120. ]);
  121. }
  122. if ($table->hasColumn('lastscan')) {
  123. $table->dropColumn('lastscan');
  124. }
  125. }
  126. return $schema;
  127. }
  128. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  129. $qb = $this->connection->getQueryBuilder();
  130. $qb->update('share_external')
  131. ->set('remote_id', $qb->createNamedParameter(''))
  132. ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1')));
  133. $qb->execute();
  134. }
  135. }