Version1000Date20201111130204.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\UserStatus\Migration;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. class Version1000Date20201111130204 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, 'user_status', 'is_user_defined');
  23. return $result ? $schema : null;
  24. }
  25. protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
  26. $table = $schema->getTable($tableName);
  27. $column = $table->getColumn($columnName);
  28. if ($column->getNotnull()) {
  29. $column->setNotnull(false);
  30. return true;
  31. }
  32. return false;
  33. }
  34. }