Commit 5e14d817 authored by David Surville's avatar David Surville
Browse files

[Evolution] Ajout des fonctions de renommage et de suppression d'une entité Ldap

parent 0aa94c78
Loading
Loading
Loading
Loading
+77 −5
Original line number Diff line number Diff line
@@ -186,6 +186,20 @@ abstract class Entity
        return $this->getNode()->getDnString();
    }

    /**
     * Retourne l'Organizational Unit (OU) de l'entité
     *
     * @return string
     */
    public function getOu()
    {
        if ($result = $this->getNode()->getDn()->get(1)) {
            return $result['ou'];
        }

        return null;
    }

    /**
     * Retourne le nom de la clé primaire correspondant à l'entité
     *
@@ -296,6 +310,9 @@ abstract class Entity
    /**
     * Affecte une nouvelle valeur à un attribut
     *
     * This is an offline method.
     * Node will be updated on calling update().
     *
     * @param string $attrName
     * @param mixed $value
     * @return self
@@ -339,6 +356,9 @@ abstract class Entity
     * Ajoute une valeur à un attribut
     * Si l'attribut est monovalué, la valeur actuelle est remplacée par la nouvelle valeur
     *
     * This is an offline method.
     * Node will be updated on calling update().
     *
     * @param string $attrName
     * @param mixed $value
     * @return self
@@ -368,6 +388,9 @@ abstract class Entity
    /**
     * Retire une valeur à un attribut
     *
     * This is an offline method.
     * Node will be updated on calling update().
     *
     * @param string $attrName
     * @param mixed|array $value
     * @return self
@@ -382,6 +405,9 @@ abstract class Entity
    /**
     * Ajoute ou affecte une valeur à un attribut Ldap
     *
     * This is an offline method.
     * Node will be updated on calling update().
     *
     * @param string $attrName
     * @param mixed $value
     * @param bool $append
@@ -441,21 +467,54 @@ abstract class Entity
    }

    /**
     * Mise à jour de l'entité
     * Déplacement de l'entité dans un autre OU (Organizational Unit)
     *
     * @return self
     * @throws LdapException
     * This is an offline method.
     * Node will be moved on calling update().
     *
     * @param string | Dn $newDn
     * @throws \Zend\Ldap\Exception\LdapException
     */
    public function update()
    public function move(string $newOu)
    {
        $this->getNode()->update();
        $arrayOu = $this->getService()->getOu();

        if(empty($arrayOu) || !in_array($newOu, $arrayOu)) {
            throw new Exception(sprintf("L'entité ne peut être déplacée dans l'OU '%s'.", $newOu));
        }

        if($newOu == $this->getOu()) {
            throw new Exception(sprintf("L'entité est déjà présente dans l'OU '%s'.", $newOu));
        }

        $newDn = sprintf('%s=%s,ou=%s,%s', $this->getKey(), $this->getId(), $newOu, $this->getNode()->getLdap()->getBaseDn());

        $this->getNode()->move($newDn);

        return $this;
    }

    /**
     * Renommage de l'entité
     *
     * This is an offline method. Node will be renamed on calling update().
     *
     * @param string | Dn $newDn
     * @throws \Zend\Ldap\Exception\LdapException
     */
    public function rename($newId)
    {
        $newDn = sprintf('%s=%s,ou=%s,%s', $this->getKey(), $newId, $this->getOu(), $this->getNode()->getLdap()->getBaseDn());

        $this->getNode()->move($newDn);
    }

    /**
     * Suppression de l'entité
     *
     * This is an offline method.
     * Node will be deleted on calling update().
     *
     * @return self
     */
    public function delete()
@@ -465,6 +524,19 @@ abstract class Entity
        return $this;
    }

    /**
     * Mise à jour de l'entité
     *
     * @return self
     * @throws LdapException
     */
    public function update()
    {
        $this->getNode()->update();

        return $this;
    }

    /**
     * Attache une connexion
     *
+0 −14
Original line number Diff line number Diff line
@@ -48,20 +48,6 @@ class People extends BasePeople
        return 'blocked' == $this->getOu();
    }

    /**
     * Retourne l'Organizational Unit (OU) de l'utilisateur
     *
     * @return string
     */
    public function getOu()
    {
        if ($result = $this->getNode()->getDn()->get(1)) {
            return $result['ou'];
        }

        return null;
    }

    /**
     * Retourne le nom complet.
     *