1
0

GroupMappingMigration.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 OCP\IDBConnection;
  9. use OCP\Migration\SimpleMigrationStep;
  10. abstract class GroupMappingMigration extends SimpleMigrationStep {
  11. public function __construct(
  12. private IDBConnection $dbc,
  13. ) {
  14. }
  15. protected function copyGroupMappingData(string $sourceTable, string $destinationTable): void {
  16. $insert = $this->dbc->getQueryBuilder();
  17. $insert->insert($destinationTable)
  18. ->values([
  19. 'ldap_dn' => $insert->createParameter('ldap_dn'),
  20. 'owncloud_name' => $insert->createParameter('owncloud_name'),
  21. 'directory_uuid' => $insert->createParameter('directory_uuid'),
  22. 'ldap_dn_hash' => $insert->createParameter('ldap_dn_hash'),
  23. ]);
  24. $query = $this->dbc->getQueryBuilder();
  25. $query->select('*')
  26. ->from($sourceTable);
  27. $result = $query->executeQuery();
  28. while ($row = $result->fetch()) {
  29. $insert
  30. ->setParameter('ldap_dn', $row['ldap_dn'])
  31. ->setParameter('owncloud_name', $row['owncloud_name'])
  32. ->setParameter('directory_uuid', $row['directory_uuid'])
  33. ->setParameter('ldap_dn_hash', $row['ldap_dn_hash'])
  34. ;
  35. $insert->executeStatement();
  36. }
  37. $result->closeCursor();
  38. }
  39. }