Commit 6a53d9b7 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #1922 Removing old code doing foreign key job

parent d14cc0b8
......@@ -327,22 +327,13 @@ class CopyPasteHandler
$dst_dn = $this->current['object']->dn;
$src_dn = $this->current['dn'];
$this->current->handleForeignKeys($src_dn, $dst_dn, ($this->current['method'] == 'cut'?'move':'copy'));
// Only copy references if required
if ($this->current['method'] != 'copy') {
return;
}
// Migrate objectgroups
$ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter(LDAP::fix($src_dn))."))",
"ogroup", array(get_ou("ogroupRDN")), $this->config->current['BASE'], array("dn"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
// Walk through all objectGroups
foreach ($ogroups as $ogroup) {
$o_ogroup = new ogroup($this->config, $ogroup['dn']);
$o_ogroup->member[$dst_dn] = $dst_dn;
$o_ogroup->save();
}
if (class_available('roleGeneric')) {
// Update roles
$roles = get_sub_list("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter(LDAP::fix($src_dn))."))",
......
......@@ -1014,14 +1014,6 @@ class plugin
{
/* Rename dn in possible object groups */
$ldap = $this->config->get_ldap_link();
$ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::prepare4filter($src_dn).'))',
array('cn'));
while ($attrs = $ldap->fetch()) {
$og = new ogroup($this->config, $ldap->getDN());
unset($og->member[$src_dn]);
$og->member[$dst_dn] = $dst_dn;
$og->save();
}
$ldap->cat($dst_dn);
$attrs = $ldap->fetch();
......@@ -1118,6 +1110,7 @@ class plugin
/* Get list of users,groups and roles within this tree,
maybe we have to update ACL references.
* TODO : replace this with a call to handleForeignKeys on sub objects
*/
$leaf_objs = get_list("(|(objectClass=posixGroup)(objectClass=gosaAccount)(objectClass=gosaRole))", array("all"), $dst_dn,
array("dn","objectClass"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
......@@ -1127,24 +1120,6 @@ class plugin
$this->update_acls($old_dn, $new_dn);
}
// Migrate objectgroups if needed
$ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter(LDAP::fix($src_dn))."))",
"ogroup", array(get_ou("ogroupRDN")), $this->config->current['BASE'],
array("dn"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
// Walk through all objectGroups
foreach ($ogroups as $ogroup) {
// Migrate old to new dn
$o_ogroup = new ogroup($this->config, $ogroup['dn']);
if (isset($o_ogroup->member[$src_dn])) {
unset($o_ogroup->member[$src_dn]);
}
$o_ogroup->member[$dst_dn] = $dst_dn;
// Save object group
$o_ogroup->save();
}
if (class_available('roleGeneric')) {
/* Update roles to use the new entry dn */
$roles = get_sub_list("(&(objectClass=organizationalRole)(roleOccupant=".LDAP::prepare4filter(LDAP::fix($src_dn))."))", "roles", array(get_ou("roleRDN")), $this->config->current['BASE'], array("dn"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
......@@ -1160,20 +1135,6 @@ class plugin
}
}
// Update 'manager' attributes from gosaDepartment and inetOrgPerson
$filter = '(&(objectClass=inetOrgPerson)(manager='.LDAP::prepare4filter(LDAP::fix($src_dn)).'))';
$filter = '(|'.$filter.'(&(objectClass=gosaDepartment)(manager='.LDAP::prepare4filter(LDAP::fix($src_dn)).')))';
$leaf_deps = get_list($filter, array('all'), $this->config->current['BASE'],
array('manager','dn','objectClass'), GL_SUBSEARCH | GL_NO_ACL_CHECK);
foreach ($leaf_deps as $entry) {
$update = array('manager' => $dst_dn);
$ldap->cd($entry['dn']);
$ldap->modify($update);
if (!$ldap->success()) {
trigger_error(sprintf("Failed to update manager for '%s', error was '%s'", $entry['dn'], $ldap->get_error()));
}
}
/* Check if there are gosa departments moved.
If there were deps moved, the force reload of config->deps.
*/
......
......@@ -211,8 +211,10 @@ class ACLsAssignmentAttribute extends DialogOrderedArrayAttribute
} elseif (($source['CLASS'] == 'user' || $source['CLASS'] == 'group') && (($member_key = array_search($oldvalue, $value['members'])) !== FALSE)) {
if ($newvalue === NULL) {
unset($value['members'][$member_key]);
} else {
} elseif ($source['MODE'] == 'move') {
$value['members'][$member_key] = $newvalue;
} elseif ($source['MODE'] == 'copy') {
$value['members'][] = $newvalue;
}
} elseif (!in_array($source['CLASS'], array('aclRole','user','group'))) {
trigger_error('unknown source '.$source['CLASS']);
......@@ -224,12 +226,12 @@ class ACLsAssignmentAttribute extends DialogOrderedArrayAttribute
function foreignKeyCheck($oldvalue, $source)
{
foreach ($this->value as $key => $value) {
if (($source[0] == 'aclRole') && ($value['role'] == $oldvalue)) {
if (($source['CLASS'] == 'aclRole') && ($value['role'] == $oldvalue)) {
return TRUE;
} elseif (($source[0] == 'user' || $source[0] == 'group') && (($member_key = array_search($oldvalue, $value['members'])) !== FALSE)) {
} elseif (($source['CLASS'] == 'user' || $source['CLASS'] == 'group') && in_array($oldvalue, $value['members'])) {
return TRUE;
} elseif (!in_array($source[0], array('aclRole','user','group'))) {
trigger_error('unknown source '.$source[0]);
} elseif (!in_array($source['CLASS'], array('aclRole','user','group'))) {
trigger_error('unknown source '.$source['CLASS']);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment