Exemple #1
0
 /**
  * Clears a user.
  *  *always deletes in: account_lost_passwords, register_marketing,
  *      register_pending, register_subs, watch_nonins, watch, watch_promo, watch_group,
  *  *always keeps in: account_types, accounts, email_virtual, carvas,
  *      group_members, homonyms_list, newsletter_ins, register_mstats, email_source_account
  *  *deletes if $clearAll: account_auth_openid, announce_read, contacts,
  *      email_redirect_account, email_redirect_account, email_send_save, forum_innd, forum_profiles,
  *      forum_subs, gapps_accounts, gapps_nicknames, group_announces_read,
  *      group_member_sub_requests, reminder, requests, requests_hidden,
  *      email_virtual, 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)
 {
     $tables = array('account_lost_passwords', 'register_marketing', 'register_pending', 'register_subs', 'watch_nonins', 'watch', 'watch_promo', 'watch_group');
     foreach ($tables as $t) {
         XDB::execute('DELETE FROM  ' . $t . '
                             WHERE  uid = {?}', $this->id());
     }
     if ($clearAll) {
         global $globals;
         $groupIds = XDB::iterator('SELECT  asso_id
                                      FROM  group_members
                                     WHERE  uid = {?}', $this->id());
         while ($groupId = $groupIds->next()) {
             $group = Group::get($groupId);
             if (!empty($group) && $group->notif_unsub) {
                 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
                 $admins = $group->iterAdmins();
                 while ($admin = $admins->next()) {
                     $mailer->addTo($admin);
                 }
                 $mailer->assign('group', $group->shortname);
                 $mailer->assign('user', $this);
                 $mailer->assign('selfdone', false);
                 $mailer->send();
             }
         }
         $tables = array('account_auth_openid', 'announce_read', 'contacts', 'email_send_save', 'forum_innd', 'forum_profiles', 'forum_subs', 'group_announces_read', 'group_members', 'group_member_sub_requests', 'reminder', 'requests', 'requests_hidden');
         foreach ($tables as $t) {
             XDB::execute('DELETE FROM  ' . $t . '
                                 WHERE  uid = {?}', $this->id());
         }
         XDB::execute('DELETE FROM  email_redirect_account
                             WHERE  uid = {?} AND type != \'homonym\'', $this->id());
         XDB::execute('DELETE FROM  email_virtual
                             WHERE  redirect = {?}', $this->forlifeEmail());
         foreach (array('gapps_accounts', 'gapps_nicknames') as $t) {
             XDB::execute('DELETE FROM  ' . $t . '
                                 WHERE  l_userid = {?}', $this->id());
         }
         XDB::execute("UPDATE  accounts\n                             SET  registration_date = 0, state = 'pending', password = NULL,\n                                  weak_password = NULL, token = NULL, is_admin = 0\n                           WHERE  uid = {?}", $this->id());
         if ($globals->mailstorage->googleapps_domain) {
             require_once 'googleapps.inc.php';
             if (GoogleAppsAccount::account_status($this->id())) {
                 $account = new GoogleAppsAccount($this);
                 $account->suspend();
             }
         }
     }
     $mmlist = new MMList(S::user());
     $mmlist->kill($this->forlife, $this->promo(), $clearAll);
 }