General developer forum

purge user forme LDAP

purge user forme LDAP

Hi all,

we want find how we can delete user when user is deleted in LDAP.

we test delete LDAP and when throw synchro user LDAP, the user who is deleted

is not deleted in prod_user moodle, we observe user is here in this table but in fiedl "deleted"

is "1".

how i can delete user out in LDAP ? have it a script for erase this user ghost ?

i whant throw automaticaly in cron.


thanks for hellp me smile

Average of ratings: -
Re: purge user forme LDAP

I try this


   public function testUser() {

        echo "<h1>recherche des user fantômes </h1>";
        $sql_fantom = "SELECT id FROM mdl_user WHERE deleted = 1 and auth='ldap'  ";
        $qb_query = $this->bdd->query($sql_fantom);

        while ($donnee = $qb_query->fetch(PDO::FETCH_OBJ)) {
            $this->id_fantome[] = $donnee->id;
        echo "===============<br/>";

        echo "suppression des utilisateurs retirer du LDAP<br/>";
        $sql_champ = "SELECT TABLE_NAME
            WHERE  table_schema = 'moodle' AND column_name ='userid' ";
        $qb_champ = $this->bdd->query($sql_champ);

        while ($result_champ = $qb_champ->fetch(PDO::FETCH_OBJ)) {
            $champ = $result_champ->TABLE_NAME; //nom des table qui contient le champ userid

            foreach ($this->id_fantome as $F) {
                echo "<h1>id fantom = $F  || champ  = $champ</h1>";
                $kill_fantom = "DELETE FROM $champ WHERE userid =$F";
                echo $kill_fantom;


I think my script all user who LDAP is deleted prod_user is deleted too

Average of ratings: -
Picture of Céline Perves
Re: purge user forme LDAP

But while simply deleting from user datatable you make orhans in other datable e.g user_enrolments an so on


Average of ratings: -