1
0

Version1130Date20220110154717.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Migration\IOutput;
  11. class Version1130Date20220110154717 extends GroupMappingMigration {
  12. public function getName() {
  13. return 'Copy ldap_group_mapping data to backup table if needed';
  14. }
  15. /**
  16. * @param IOutput $output
  17. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  18. * @param array $options
  19. * @since 13.0.0
  20. */
  21. public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. if (!$schema->hasTable('ldap_group_mapping_backup')) {
  25. // Backup table does not exist
  26. return;
  27. }
  28. $output->startProgress();
  29. $this->copyGroupMappingData('ldap_group_mapping', 'ldap_group_mapping_backup');
  30. $output->finishProgress();
  31. }
  32. /**
  33. * @param IOutput $output
  34. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  35. * @param array $options
  36. * @return null|ISchemaWrapper
  37. */
  38. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  39. /** @var ISchemaWrapper $schema */
  40. $schema = $schemaClosure();
  41. if (!$schema->hasTable('ldap_group_mapping_backup')) {
  42. // Backup table does not exist
  43. return null;
  44. }
  45. $schema->dropTable('ldap_group_mapping');
  46. return $schema;
  47. }
  48. }