GroupMappingMigration.php 1.3 KB

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