1
0

Version1011Date20201120125158.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\FederatedFileSharing\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 Version1011Date20201120125158 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) {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. if ($schema->hasTable('federated_reshares')) {
  25. $table = $schema->getTable('federated_reshares');
  26. $remoteIdColumn = $table->getColumn('remote_id');
  27. if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) {
  28. $remoteIdColumn->setNotnull(false);
  29. $remoteIdColumn->setType(Type::getType(Types::STRING));
  30. $remoteIdColumn->setOptions(['length' => 255]);
  31. $remoteIdColumn->setDefault('');
  32. return $schema;
  33. }
  34. }
  35. return null;
  36. }
  37. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  38. $qb = $this->connection->getQueryBuilder();
  39. $qb->update('federated_reshares')
  40. ->set('remote_id', $qb->createNamedParameter(''))
  41. ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1')));
  42. $qb->execute();
  43. }
  44. }