1
0

Version11300Date20201120141438.php 3.3 KB

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