summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/appinfo/update.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2012-08-23 18:29:43 +0200
committerArthur Schiwon <blizzz@owncloud.com>2012-08-23 18:29:43 +0200
commitd5c111a984278a097025d267f3461c01983ca0c2 (patch)
tree95d9f8f5cbdb92b4cf731bb60d114da18f592408 /apps/user_ldap/appinfo/update.php
parentc90c358f0d315c8cf755ec670b7d7738ab15148a (diff)
downloadnextcloud-server-d5c111a984278a097025d267f3461c01983ca0c2.tar.gz
nextcloud-server-d5c111a984278a097025d267f3461c01983ca0c2.zip
LDAP: identify (map) users with their directory UUID. Fixes the issue, that usernames for owncloud will change, when the DN changes (which happens rarely, but it happens).
Diffstat (limited to 'apps/user_ldap/appinfo/update.php')
-rw-r--r--apps/user_ldap/appinfo/update.php42
1 files changed, 22 insertions, 20 deletions
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php
index badceb378d1..9cf1814cf6f 100644
--- a/apps/user_ldap/appinfo/update.php
+++ b/apps/user_ldap/appinfo/update.php
@@ -2,6 +2,11 @@
//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)) {
@@ -12,33 +17,25 @@ if(!is_null($pw)) {
//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', 'doCheck');
-if($state == 'doCheck'){
- $sqlCleanMap = 'DELETE FROM *PREFIX*ldap_user_mapping';
-
- OCP\Config::setSystemValue('ldapIgnoreNamingRules', true);
- $LDAP_USER = new OC_USER_LDAP();
- $users_old = $LDAP_USER->getUsers();
- $query = OCP\DB::prepare($sqlCleanMap);
- $query->execute();
+$state = OCP\Config::getSystemValue('ldapIgnoreNamingRules', 'unset');
+if($state == 'unset'){
OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
- OC_LDAP::init(true);
- $users_new = $LDAP_USER->getUsers();
- $query = OCP\DB::prepare($sqlCleanMap);
- $query->execute();
- if($users_old !== $users_new) {
- //we don't need to check Groups, because they were not supported in 3'
- OCP\Config::setSystemValue('ldapIgnoreNamingRules', true);
- }
}
+// ### SUPPORTED upgrade path starts here ###
-//from version 0.2 to 0.2.1
+//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 from *PREFIX*ldap_'.$object.'_mapping';
- $updateSql = 'UPDATE *PREFIX*ldap_'.$object.'_mapping SET ldap_DN = ? WHERE ldap_dn = ?';
+ $updateSql = 'UPDATE *PREFIX*ldap_'.$object.'_mapping SET ldap_DN = ?, directory_uuid = ? WHERE ldap_dn = ?';
$query = OCP\DB::prepare($fetchDNSql);
$res = $query->execute();
@@ -46,6 +43,11 @@ foreach($objects as $object) {
$updateQuery = OCP\DB::prepare($updateSql);
foreach($DNs as $dn) {
$newDN = mb_strtolower($dn['ldap_dn'], 'UTF-8');
- $updateQuery->execute(array($newDN, $dn['ldap_dn']));
+ if($object == 'user') {
+ $uuid = $userBE->getUUID($newDN);
+ } else {
+ $uuid = $groupBE->getUUID($newDN);
+ }
+ $updateQuery->execute(array($newDN, $uuid, $dn['ldap_dn']));
}
}