Fix user/profile deletion
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 25 Jun 2010 08:46:46 +0000 (10:46 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 25 Jun 2010 09:28:14 +0000 (11:28 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
classes/user.php

index 9924eb4..56e1f5a 100644 (file)
@@ -411,6 +411,36 @@ class Profile
     }
 
 
+    /**
+     * Clears a profile.
+     *  *always deletes in: profile_addresses, profile_binets, profile_job,
+     *      profile_langskills, profile_mentor, profile_networking,
+     *      profile_phones, profile_skills, watch_profile
+     *  *always keeps in: profile_corps, profile_display, profile_education,
+     *      profile_medals, profile_name, profile_photos, search_name
+     *  *modifies: profiles
+     */
+    public function clear()
+    {
+        $tables = array(
+            'profile_job', 'profile_langskills', 'profile_mentor',
+            'profile_networking', 'profile_skills', 'watch_profile',
+            'profile_phones', 'profile_addresses', 'profile_binets');
+
+        foreach ($tables as $t) {
+            XDB::execute('DELETE FROM  ' . $t . '
+                                WHERE  pid = {?}',
+                                $this->id());
+        }
+
+        XDB::execute("UPDATE  profiles
+                         SET  cv = NULL, freetext = NULL, freetext_pub = 'private',
+                              medals_pub = 'private', alias_pub = 'private',
+                              email_directory = NULL
+                       WHERE  pid = {?}",
+                     $this->id());
+    }
+
     /** Sets the level of visibility of the profile
      * Sets $this->visibility to a list of valid visibilities.
      * @param one of the self::VIS_* values
index 9b1d41e..b2a75f0 100644 (file)
@@ -569,11 +569,15 @@ class User extends PlUser
      */
     public function clear($clearAll = true)
     {
-        XDB::execute('DELETE FROM  account_lost_passwords, register_marketing,
-                                   register_pending, register_subs, watch_nonins,
-                                   watch, watch_promo
-                            WHERE  uid = {?}',
-                     $this->id());
+        $tables = array('account_lost_passwords', 'register_marketing',
+                        'register_pending', 'register_subs', 'watch_nonins',
+                        'watch', 'watch_promo');
+
+        foreach ($tables as $t) {
+            XDB::execute('DELETE FROM  ' . $t . '
+                                WHERE  uid = {?}',
+                                $this->id());
+        }
 
         if ($clearAll) {
             $groupIds = XDB::iterator('SELECT  asso_id
@@ -595,14 +599,19 @@ class User extends PlUser
                 }
             }
 
-            XDB::execute('DELETE FROM  account_auth_openid, announce_read, contacts,
-                                       email_options, email_send_save, emails,
-                                       forum_innd, forum_profiles, forum_subs,
-                                       gapps_accounts, gapps_nicknames, group_announces_read,
-                                       group_members, group_member_sub_requests, reminder, requests,
-                                       requests_hidden
-                                WHERE  uid = {?}',
-                         $this->id());
+            $tables = array('account_auth_openid', 'gannounce_read', 'contacts',
+                            'email_options', 'gemail_send_save', 'emails',
+                            'forum_innd', 'gforum_profiles', 'forum_subs',
+                            'gapps_accounts', 'ggapps_nicknames', 'group_announces_read',
+                            'group_members', 'ggroup_member_sub_requests', 'reminder', 'requests',
+                            'requests_hidden');
+
+            foreach ($tables as $t) {
+                XDB::execute('DELETE FROM  ' . $t . '
+                                    WHERE  uid = {?}',
+                    $this->id());
+            }
+
             XDB::execute("UPDATE  accounts
                              SET  registration_date = 0, state = 'pending', password = NULL,
                                   weak_password = NULL, token = NULL, is_admin = 0