purge user forme LDAP

purge user forme LDAP

by stephane ngov -
Number of replies: 2

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: -
In reply to stephane ngov

Re: purge user forme LDAP

by stephane ngov -

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
            FROM INFORMATION_SCHEMA.COLUMNS
            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;
                $this->bdd->exec($kill_fantom);
            }
        }
    }

 

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

In reply to stephane ngov

Re: purge user forme LDAP

by Céline Perves -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

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