Version20000Date20201109081915.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 OC\Core\Migrations;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. class Version20000Date20201109081915 extends SimpleMigrationStep {
  13. /**
  14. * @param IOutput $output
  15. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  16. * @param array $options
  17. * @return null|ISchemaWrapper
  18. */
  19. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  20. /** @var ISchemaWrapper $schema */
  21. $schema = $schemaClosure();
  22. $result = $this->ensureColumnIsNullable($schema, 'share', 'password_by_talk');
  23. $result = $this->ensureColumnIsNullable($schema, 'share', 'hide_download') || $result;
  24. // $result = $this->ensureColumnIsNullable($schema, 'credentials', 'user') || $result;
  25. $result = $this->ensureColumnIsNullable($schema, 'authtoken', 'password_invalid') || $result;
  26. $result = $this->ensureColumnIsNullable($schema, 'collres_accesscache', 'access') || $result;
  27. return $result ? $schema : null;
  28. }
  29. protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
  30. $table = $schema->getTable($tableName);
  31. $column = $table->getColumn($columnName);
  32. if ($column->getNotnull()) {
  33. $column->setNotnull(false);
  34. return true;
  35. }
  36. return false;
  37. }
  38. }