Version1130Date20220110154718.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\User_LDAP\Migration;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\IOutput;
  12. class Version1130Date20220110154718 extends GroupMappingMigration {
  13. public function getName() {
  14. return 'Copy ldap_group_mapping data from backup table and if needed';
  15. }
  16. /**
  17. * @param IOutput $output
  18. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  19. * @param array $options
  20. * @return null|ISchemaWrapper
  21. */
  22. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  23. /** @var ISchemaWrapper $schema */
  24. $schema = $schemaClosure();
  25. if (!$schema->hasTable('ldap_group_mapping_backup')) {
  26. // Backup table does not exist
  27. return null;
  28. }
  29. $table = $schema->createTable('ldap_group_mapping');
  30. $table->addColumn('ldap_dn', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 4000,
  33. 'default' => '',
  34. ]);
  35. $table->addColumn('owncloud_name', Types::STRING, [
  36. 'notnull' => true,
  37. 'length' => 64,
  38. 'default' => '',
  39. ]);
  40. $table->addColumn('directory_uuid', Types::STRING, [
  41. 'notnull' => true,
  42. 'length' => 255,
  43. 'default' => '',
  44. ]);
  45. $table->addColumn('ldap_dn_hash', Types::STRING, [
  46. 'notnull' => false,
  47. 'length' => 64,
  48. ]);
  49. $table->setPrimaryKey(['owncloud_name']);
  50. $table->addUniqueIndex(['ldap_dn_hash'], 'ldap_group_dn_hashes');
  51. $table->addUniqueIndex(['directory_uuid'], 'ldap_group_directory_uuid');
  52. return $schema;
  53. }
  54. /**
  55. * @param IOutput $output
  56. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  57. * @param array $options
  58. */
  59. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
  60. /** @var ISchemaWrapper $schema */
  61. $schema = $schemaClosure();
  62. if (!$schema->hasTable('ldap_group_mapping_backup')) {
  63. // Backup table does not exist
  64. return;
  65. }
  66. $output->startProgress();
  67. $this->copyGroupMappingData('ldap_group_mapping_backup', 'ldap_group_mapping');
  68. $output->finishProgress();
  69. }
  70. }