1
0

Version18000Date20190920085628.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 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\DB\Types;
  11. use OCP\IDBConnection;
  12. use OCP\Migration\IOutput;
  13. use OCP\Migration\SimpleMigrationStep;
  14. class Version18000Date20190920085628 extends SimpleMigrationStep {
  15. public function __construct(
  16. protected IDBConnection $connection,
  17. ) {
  18. }
  19. /**
  20. * @param IOutput $output
  21. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  22. * @param array $options
  23. * @return null|ISchemaWrapper
  24. */
  25. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  26. /** @var ISchemaWrapper $schema */
  27. $schema = $schemaClosure();
  28. if ($schema->hasTable('groups')) {
  29. $table = $schema->getTable('groups');
  30. $table->addColumn('displayname', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 255,
  33. // Will be overwritten in postSchemaChange, but Oracle can not save
  34. // empty strings in notnull columns
  35. 'default' => 'name',
  36. ]);
  37. }
  38. return $schema;
  39. }
  40. /**
  41. * @param IOutput $output
  42. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  43. * @param array $options
  44. */
  45. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
  46. $query = $this->connection->getQueryBuilder();
  47. $query->update('groups')
  48. ->set('displayname', 'gid');
  49. $query->execute();
  50. }
  51. }