Commit 1a14e8f9 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #946 Merged move and rename methods, moved the result to simplePlugin

parent 21eddfc2
......@@ -31,78 +31,6 @@ class plugin
var $acl_base = "";
var $acl_category = "";
/*!
* \brief Rename/Move a given src_dn to the given dest_dn
*
* Move a given ldap object indentified by $src_dn to the
* given destination $dst_dn
*
* \param string $src_dn the source DN.
*
* \param string $dst_dn the destination DN.
*
* \return boolean TRUE on success else FALSE.
*/
private function rename($src_dn, $dst_dn)
{
global $config;
/* Try to move the source entry to the destination position */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
if (!$ldap->rename_dn($src_dn, $dst_dn)) {
logging::log('debug', 'Ldap Protocol v3 implementation error, ldap_rename failed.',
"FROM: $src_dn -- TO: $dst_dn", array(), $ldap->get_error());
@DEBUG(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, "Rename failed FROM: $src_dn -- TO: $dst_dn",
'Ldap Protocol v3 implementation error. Error:'.$ldap->get_error());
return FALSE;
}
return TRUE;
}
/*!
* \brief Move ldap entries from one place to another
*
* \param string $src_dn the source DN.
*
* \param string $dst_dn the destination DN.
*/
function move($src_dn, $dst_dn)
{
global $config, $ui;
/* Do not move if only case has changed */
if (strtolower($src_dn) == strtolower($dst_dn)) {
return TRUE;
}
/* Try to move with ldap routines */
if (!$this->rename($src_dn, $dst_dn)) {
return FALSE;
}
/* Update userinfo if necessary */
if (preg_match('/'.preg_quote($src_dn, '/').'$/i', $ui->dn)) {
$ui_dn = preg_replace('/'.preg_quote($src_dn, '/').'$/i', $dst_dn, $ui->dn);
logging::log('view', 'acl/'.get_class($this), $this->dn, array(), 'Updated userinfo dn from "'.$ui->dn.'" to "'.$ui_dn.'"');
$ui->dn = $ui_dn;
}
/* Check if departments were moved. If so, force the reload of config->departments */
$ldap = $config->get_ldap_link();
$ldap->cd($dst_dn);
$ldap->search('(objectClass=gosaDepartment)', array('dn'));
if ($ldap->count()) {
$config->get_departments();
$config->make_idepartments();
$ui->reset_acl_cache();
}
$this->handleForeignKeys($src_dn, $dst_dn);
return TRUE;
}
/*!
* \brief Set acl base
*
......
......@@ -538,6 +538,54 @@ class simplePlugin extends plugin
return $deps;
}
/*!
* \brief Move ldap entries from one place to another
*
* \param string $src_dn the source DN.
*
* \param string $dst_dn the destination DN.
*/
function move($src_dn, $dst_dn)
{
global $config, $ui;
/* Do not move if only case has changed */
if (strtolower($src_dn) == strtolower($dst_dn)) {
return TRUE;
}
/* Try to move with ldap routines */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
if (!$ldap->rename_dn($src_dn, $dst_dn)) {
logging::log('debug', 'Ldap Protocol v3 implementation error, ldap_rename failed.',
"FROM: $src_dn -- TO: $dst_dn", array(), $ldap->get_error());
@DEBUG(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, "Rename failed FROM: $src_dn -- TO: $dst_dn",
'Ldap Protocol v3 implementation error. Error:'.$ldap->get_error());
return FALSE;
}
/* Update userinfo if necessary */
if (preg_match('/'.preg_quote($src_dn, '/').'$/i', $ui->dn)) {
$ui_dn = preg_replace('/'.preg_quote($src_dn, '/').'$/i', $dst_dn, $ui->dn);
logging::log('view', 'acl/'.get_class($this), $this->dn, array(), 'Updated userinfo dn from "'.$ui->dn.'" to "'.$ui_dn.'"');
$ui->dn = $ui_dn;
}
/* Check if departments were moved. If so, force the reload of config->departments */
$ldap->cd($dst_dn);
$ldap->search('(objectClass=gosaDepartment)', array('dn'));
if ($ldap->count()) {
$config->get_departments();
$config->make_idepartments();
$ui->reset_acl_cache();
}
$this->handleForeignKeys($src_dn, $dst_dn);
return TRUE;
}
function getRequiredAttributes()
{
$tmp = array();
......
Markdown is supported
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