index 10f4636d6ac62089839260ca8be6662ccd0f0c24..15180d73cbd1719b2805435b63ce8ae03a597d83 100644 (file)
--- a/include/class_plugin.inc
+++ b/include/class_plugin.inc
*/
var $attrs= array();
+ /* Save unit tags */
+ var $gosaUnitTag= "";
/*!
\brief Used standard values
/* Copy needed attributes */
foreach ($this->attributes as $val){
- #if (isset($this->attrs["$val"][0])){
$found= array_key_ics($val, $this->attrs);
if ($found != ""){
$this->$val= $this->attrs["$found"][0];
}
}
+ /* gosaUnitTag loading... */
+ if (isset($this->attrs['gosaUnitTag'][0])){
+ $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0];
+ }
+
/* Set the template flag according to the existence of objectClass
gosaUserTemplate */
if (isset($this->attrs['objectClass'])){
/* Try to use plain entry first */
$dn= "$attribute=".$this->$attribute.",$base";
- $ldap->cat ($dn);
+ $ldap->cat ($dn, array('dn'));
if (!$ldap->fetch()){
return ($dn);
}
}
$dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
- $ldap->cat ($dn);
+ $ldap->cat ($dn, array('dn'));
if (!$ldap->fetch()){
return ($dn);
}
}
$ldap->cat($src_dn);
- $attrs= array();
$attrs= $ldap->fetch();
if (!count($attrs)){
trigger_error("Trying to move $src_dn, which does not seem to exist.",
/* Save copy */
$ldap->connect();
$ldap->cd($this->config->current['BASE']);
+
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
+
+ /* FAIvariable=.../..., cn=..
+ could not be saved, because the attribute FAIvariable was different to
+ the dn FAIvariable=..., cn=... */
+ if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){
+ $new['FAIvariable'] = $ldap->fix($new['FAIvariable']);
+ }
$ldap->cd($dst_dn);
$ldap->add($new);
$ldap= $this->config->get_ldap_link();
/* Check if destination exists - abort */
- $ldap->cat($dst_dn);
+ $ldap->cat($dst_dn, array('dn'));
if ($ldap->fetch()){
trigger_error("recursive_move $dst_dn already exists.",
E_USER_WARNING);
}
- function handle_object_tagging($dn= "", $tag= "")
+ function handle_object_tagging($dn= "", $tag= "", $show= false)
{
+ //FIXME: How to optimize this? We have at least two
+ // LDAP accesses per object. It would be a good
+ // idea to have it integrated.
+
/* No dn? Self-operation... */
if ($dn == ""){
$dn= $this->dn;
- }
- /* No tag? Find it yourself... */
- #....
+ /* No tag? Find it yourself... */
+ if ($tag == ""){
+ $len= strlen($dn);
+
+ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
+ $relevant= array();
+ foreach ($this->config->adepartments as $key => $ntag){
+
+ /* This one is bigger than our dn, its not relevant... */
+ if ($len <= strlen($key)){
+ continue;
+ }
+
+ /* This one matches with the latter part. Break and don't fix this entry */
+ if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
+ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
+ $relevant[strlen($key)]= $ntag;
+ continue;
+ }
+
+ }
+
+ /* If we've some relevant tags to set, just get the longest one */
+ if (count($relevant)){
+ ksort($relevant);
+ $tmp= array_keys($relevant);
+ $idx= end($tmp);
+ $tag= $relevant[$idx];
+ $this->gosaUnitTag= $tag;
+ }
+ }
+ }
+
/* Set tag? */
if ($tag != ""){
- #echo "Add tagging ($tag) to $dn.<br>";
-
/* Set objectclass and attribute */
$ldap= $this->config->get_ldap_link();
- $ldap->cat($dn);
+ $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
$attrs= $ldap->fetch();
- $nattrs= array("gosaUnitTag" => $this->gosaUnitTag);
- $nattrs['objectClass']= array();
- for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
- $oc= $attrs['objectClass'][$i];
- if ($oc != "gosaAdministrativeUnitTag"){
- $nattrs['objectClass'][]= $oc;
+ if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
+ if ($show) {
+ echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
+ flush();
}
+ return;
}
- $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
- $ldap->cd($dn);
- $ldap->modify($nattrs);
- if ($ldap->error != "Success"){
- print_red($ldap->get_error());
+ if (count($attrs)){
+ if ($show){
+ echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
+ flush();
+ }
+ $nattrs= array("gosaUnitTag" => $this->gosaUnitTag);
+ $nattrs['objectClass']= array();
+ for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
+ $oc= $attrs['objectClass'][$i];
+ if ($oc != "gosaAdministrativeUnitTag"){
+ $nattrs['objectClass'][]= $oc;
+ }
+ }
+ $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
+ $ldap->cd($dn);
+ $ldap->modify($nattrs);
+ show_ldap_error($ldap->get_error(), _("Handle object tagging failed"));
+ } else {
+ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
}
+
} else {
- #echo "Remove tagging from $dn.<br>";
-
/* Remove objectclass and attribute */
$ldap= $this->config->get_ldap_link();
- $ldap->cat($dn);
+ $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
$attrs= $ldap->fetch();
- $nattrs= array("gosaUnitTag" => array());
- $nattrs['objectClass']= array();
- for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
- $oc= $attrs['objectClass'][$i];
- if ($oc != "gosaAdministrativeUnitTag"){
- $nattrs['objectClass'][]= $oc;
+ if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
+ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
+ return;
+ }
+ if (count($attrs)){
+ if ($show){
+ echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
+ flush();
}
- }
- $ldap->cd($dn);
- $ldap->modify($nattrs);
- if ($ldap->error != "Success"){
- print_red($ldap->get_error());
+ $nattrs= array("gosaUnitTag" => array());
+ $nattrs['objectClass']= array();
+ for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
+ $oc= $attrs['objectClass'][$i];
+ if ($oc != "gosaAdministrativeUnitTag"){
+ $nattrs['objectClass'][]= $oc;
+ }
+ }
+ $ldap->cd($dn);
+ $ldap->modify($nattrs);
+ show_ldap_error($ldap->get_error(), _("Handle object tagging failed"));
+ } else {
+ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
}
}