1
0

Version1011Date20201120125158.php 1.5 KB

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