Passed
Push — master ( 2c1eac...4adb60 )
by John
28:02 queued 12:52
created

GroupMappingMigration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A copyGroupMappingData() 0 27 2
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
7
 *
8
 * @author Côme Chilliet <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\User_LDAP\Migration;
28
29
use OCP\IDBConnection;
30
use OCP\Migration\SimpleMigrationStep;
31
32
abstract class GroupMappingMigration extends SimpleMigrationStep {
33
34
	/** @var IDBConnection */
35
	private $dbc;
36
37
	public function __construct(IDBConnection $dbc) {
38
		$this->dbc = $dbc;
39
	}
40
41
	protected function copyGroupMappingData(string $sourceTable, string $destinationTable): void {
42
		$insert = $this->dbc->getQueryBuilder();
43
		$insert->insert($destinationTable)
44
			->values([
45
				'ldap_dn' => $insert->createParameter('ldap_dn'),
46
				'owncloud_name' => $insert->createParameter('owncloud_name'),
47
				'directory_uuid' => $insert->createParameter('directory_uuid'),
48
				'ldap_dn_hash' => $insert->createParameter('ldap_dn_hash'),
49
			]);
50
51
		$query = $this->dbc->getQueryBuilder();
52
		$query->select('*')
53
			->from($sourceTable);
54
55
56
		$result = $query->executeQuery();
57
		while ($row = $result->fetch()) {
58
			$insert
59
				->setParameter('ldap_dn', $row['ldap_dn'])
60
				->setParameter('owncloud_name', $row['owncloud_name'])
61
				->setParameter('directory_uuid', $row['directory_uuid'])
62
				->setParameter('ldap_dn_hash', $row['ldap_dn_hash'])
63
				;
64
65
			$insert->executeStatement();
66
		}
67
		$result->closeCursor();
68
	}
69
}
70