From 6150f591dcf55caba1bfe532bf8cbf919dc883c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Mon, 1 Mar 2010 22:44:51 +0100 Subject: [PATCH] Moves user_clear_all_subs to both User and Profile classes. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/profile.php | 27 ++++++++++++++ classes/user.php | 65 ++++++++++++++++++++++++++++++++++ include/user.func.inc.php | 90 ----------------------------------------------- modules/admin.php | 6 ++-- 4 files changed, 95 insertions(+), 93 deletions(-) delete mode 100644 include/user.func.inc.php diff --git a/classes/profile.php b/classes/profile.php index 9fe5d39..6da9eff 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -473,6 +473,33 @@ class Profile return ($isOk && ($maxlen > 2 || $maxlen == strlen($_lastname))); } + /** + * 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() + { + XDB::execute('DELETE FROM profile_job, profile_langskills, profile_mentor, + profile_networking, profile_skills, watch_profile + WHERE pid = {?}', + $this->id()); + XDB::execute('DELETE FROM profile_addresses, profile_binets, + profile_phones + 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()); + } + private static function fetchProfileData(array $pids, $respect_order = true) { if (count($pids) == 0) { diff --git a/classes/user.php b/classes/user.php index 9936c94..3254b73 100644 --- a/classes/user.php +++ b/classes/user.php @@ -506,6 +506,71 @@ class User extends PlUser return $this->groups; } + /** + * Clears a user. + * *always deletes in: account_lost_passwords, register_marketing, + * register_pending, register_subs, watch_nonins, watch, watch_promo + * *always keeps in: account_types, accounts, aliases, axletter_ins, carvas, + * group_members, homonyms, newsletter_ins, register_mstats, + * *deletes if $clearAll: 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_member_sub_requests, reminder, requests, requests_hidden, + * virtual, virtual_redirect, ML + * *modifies if $clearAll: accounts + * + * Use cases: + * *$clearAll == false: when a user dies, her family still needs to keep in + * touch with the community. + * *$clearAll == true: in every other case we want the account to be fully + * deleted so that it can not be used anymore. + */ + 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()); + + if ($clearAll) { + 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_member_sub_requests, reminder, requests, + requests_hidden + WHERE uid = {?}', + $this->id()); + XDB::execute("UPDATE accounts + SET registration_date = 0, state = 'pending', password = NULL, + weak_password = NULL, token = NULL, is_admin = 0 + WHERE uid = {?}", + $this->id()); + + XDB::execute('DELETE v.* + FROM virtual AS v + INNER JOIN virtual_redirect AS r ON (v.vid = r.vid) + WHERE redirect = {?} OR redirect = {?}', + $this->forlifeEmail(), $this->m4xForlifeEmail()); + XDB::execute('DELETE FROM virtual_redirect + WHERE redirect = {?} OR redirect = {?}', + $this->forlifeEmail(), $this->m4xForlifeEmail()); + + if ($globals->mailstorage->googleapps_domain) { + require_once 'googleapps.inc.php'; + + if (GoogleAppsAccount::account_status($uid)) { + $account = new GoogleAppsAccount($user); + $account->suspend(); + } + } + } + + $mmlist = new MMList($this); + $mmlist->kill($alias, $clearAll); + } + // Return permission flags for a given permission level. public static function makePerms($perms, $is_admin) { diff --git a/include/user.func.inc.php b/include/user.func.inc.php deleted file mode 100644 index 20cabe2..0000000 --- a/include/user.func.inc.php +++ /dev/null @@ -1,90 +0,0 @@ -forlifeEmail()); - - // TODO: clear profile. - $tables_to_clear = array('uid' => array('profile_skills', 'profile_job', 'profile_langskills', 'profile_mentor_country', - 'profile_mentor_sector', 'profile_mentor', 'perte_pass', 'watch_sub'), - 'user_id' => array('requests', 'user_changes')); - - if ($really_del) { - array_push($tables_to_clear['uid'], 'emails', 'group_members', 'contacts', 'adresses', 'profile_phones', - 'photo', 'perte_pass', 'profile_langskills', 'forum_subs', 'forum_profiles'); - array_push($tables_to_clear['user_id'], 'newsletter_ins', 'profile_binets'); - $tables_to_clear['id'] = array('aliases'); - $tables_to_clear['contact'] = array('contacts'); - XDB::execute("UPDATE accounts - SET registration_date = 0, state = 'pending', password = NULL, weak_password = NULL, token = NULL, is_admin = 0 - WHERE uid = {?}", $uid); - XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", - $alias.'@'.$globals->mail->domain); - XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}", - $alias.'@'.$globals->mail->domain2); - } else { - XDB::execute("UPDATE accounts - SET password = NULL, weak_password = NULL, token = NULL - WHERE uid = {?}", $uid); - } - - XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain); - XDB::execute("DELETE FROM virtual_redirect WHERE redirect = {?}", $alias.'@'.$globals->mail->domain2); - - /* TODO: handle both account and profile - foreach ($tables_to_clear as $key=>&$tables) { - foreach ($tables as $table) { - XDB::execute("DELETE FROM $table WHERE $key={?}", $uid); - } - }*/ - - $mmlist = new MMList($user); - $mmlist->kill($alias, $really_del); - - // Deactivates, when available, the Google Apps account of the user. - if ($globals->mailstorage->googleapps_domain) { - require_once 'googleapps.inc.php'; - if (GoogleAppsAccount::account_status($uid)) { - $account = new GoogleAppsAccount($user); - $account->suspend(); - } - } -} - -// }}} - - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: -?> diff --git a/modules/admin.php b/modules/admin.php index 4dff7a8..341d21c 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -900,9 +900,9 @@ class AdminModule extends PLModule WHERE hrpid = {?}', $val, $pid); $page->trigSuccess('Ajout du décès de ' . $name . ' le ' . $val . '.'); if($death == '0000-00-00' || empty($death)) { - // TODO: FIX THIS DEPRECATED CALL - require_once('user.func.inc.php'); - user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email + $profile = Profile::get($pid); + $profile->clear(); + $profile->owner()->clear(false); } } } -- 2.1.4