From: Raphaël Barrois Date: Fri, 25 Jun 2010 08:46:46 +0000 (+0200) Subject: Fix user/profile deletion X-Git-Tag: xorg/1.0.0~31 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=405d70cc9d8870ec910b05b35d0c694ef2f4731f;p=platal.git Fix user/profile deletion Signed-off-by: Raphaël Barrois --- diff --git a/classes/profile.php b/classes/profile.php index 9924eb4..56e1f5a 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -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 diff --git a/classes/user.php b/classes/user.php index 9b1d41e..b2a75f0 100644 --- a/classes/user.php +++ b/classes/user.php @@ -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