Esempio n. 1
0
 /**
  * Rename or move an entry
  *
  * This method will instantly carry out an update() after the move,
  * so the entry is moved instantly.
  * You can pass an optional Net_LDAP2 object. In this case, a cross directory
  * move will be performed which deletes the entry in the source (THIS) directory
  * and adds it in the directory $target_ldap.
  * A cross directory move will switch the Entrys internal LDAP reference so
  * updates to the entry will go to the new directory.
  *
  * Note that if you want to do a cross directory move, you need to
  * pass an Net_LDAP2_Entry object, otherwise the attributes will be empty.
  *
  * @param string|Net_LDAP2_Entry $entry       Entry DN or Entry object
  * @param string                 $newdn       New location
  * @param Net_LDAP2              $target_ldap (optional) Target directory for cross server move; should be passed via reference
  *
  * @return Net_LDAP2_Error|true
  */
 public function move($entry, $newdn, $target_ldap = null)
 {
     if (is_string($entry)) {
         $entry_o = $this->getEntry($entry);
     } else {
         $entry_o =& $entry;
     }
     if (!$entry_o instanceof Net_LDAP2_Entry) {
         return PEAR::raiseError('Parameter $entry is expected to be a Net_LDAP2_Entry object! (If DN was passed, conversion failed)');
     }
     if (null !== $target_ldap && !$target_ldap instanceof Net_LDAP2) {
         return PEAR::raiseError('Parameter $target_ldap is expected to be a Net_LDAP2 object!');
     }
     if ($target_ldap && $target_ldap !== $this) {
         // cross directory move
         if (is_string($entry)) {
             return PEAR::raiseError('Unable to perform cross directory move: operation requires a Net_LDAP2_Entry object');
         }
         if ($target_ldap->dnExists($newdn)) {
             return PEAR::raiseError('Unable to perform cross directory move: entry does exist in target directory');
         }
         $entry_o->dn($newdn);
         $res = $target_ldap->add($entry_o);
         if (self::isError($res)) {
             return PEAR::raiseError('Unable to perform cross directory move: ' . $res->getMessage() . ' in target directory');
         }
         $res = $this->delete($entry_o->currentDN());
         if (self::isError($res)) {
             $res2 = $target_ldap->delete($entry_o);
             // undo add
             if (self::isError($res2)) {
                 $add_error_string = 'Additionally, the deletion (undo add) of $entry in target directory failed.';
             }
             return PEAR::raiseError('Unable to perform cross directory move: ' . $res->getMessage() . ' in source directory. ' . $add_error_string);
         }
         $entry_o->setLDAP($target_ldap);
         return true;
     } else {
         // local move
         $entry_o->dn($newdn);
         $entry_o->setLDAP($this);
         return $entry_o->update();
     }
 }