aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/appinfo/update.php
blob: da36211b665db17b8f362b0c996b99ed4a196b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

//from version 0.1 to 0.2

//ATTENTION
//Upgrade from ownCloud 3 (LDAP backend 0.1) to ownCloud 4.5 (LDAP backend 0.3) is not supported!!
//You must do upgrade to ownCloud 4.0 first!
//The upgrade stuff in the section from 0.1 to 0.2 is just to minimize the bad efffects.

//settings
$pw = OCP\Config::getAppValue('user_ldap', 'ldap_password');
if(!is_null($pw)) {
	$pwEnc = base64_encode($pw);
	OCP\Config::setAppValue('user_ldap', 'ldap_agent_password', $pwEnc);
	OC_Appconfig::deleteKey('user_ldap', 'ldap_password');
}

//detect if we can switch on naming guidelines. We won't do it on conflicts.
//it's a bit spaghetti, but hey.
$state = OCP\Config::getSystemValue('ldapIgnoreNamingRules', 'unset');
if($state == 'unset'){
	OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
}

// ### SUPPORTED upgrade path starts here ###

//from version 0.2 to 0.3 (0.2.0.x dev version)
$objects = array('user', 'group');

$connector = new \OCA\user_ldap\lib\Connection('user_ldap');
$userBE = new \OCA\user_ldap\USER_LDAP();
$userBE->setConnector($connector);
$groupBE = new \OCA\user_ldap\GROUP_LDAP();
$groupBE->setConnector($connector);

foreach($objects as $object) {
	$fetchDNSql = 'SELECT `ldap_dn`, `owncloud_name` FROM `*PREFIX*ldap_'.$object.'_mapping` WHERE `directory_uuid` = ""';
	$updateSql = 'UPDATE `*PREFIX*ldap_'.$object.'_mapping` SET `ldap_DN` = ?, `directory_uuid` = ? WHERE `ldap_dn` = ?';

	$query = OCP\DB::prepare($fetchDNSql);
	$res = $query->execute();
	$DNs = $res->fetchAll();
	$updateQuery = OCP\DB::prepare($updateSql);
	foreach($DNs as $dn) {
		$newDN = mb_strtolower($dn['ldap_dn'], 'UTF-8');
		if($object == 'user') {
			$uuid = $userBE->getUUID($newDN);
			//fix home folder to avoid new ones depending on the configuration
			$userBE->getHome($dn['owncloud_name']);
		} else {
			$uuid = $groupBE->getUUID($newDN);
		}
		$updateQuery->execute(array($newDN, $uuid, $dn['ldap_dn']));
	}
}