+
+ 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_options', 'email_send_save', 'emails',
+ 'forum_innd', 'forum_profiles', 'forum_subs',
+ 'group_announces_read', 'group_members',
+ 'group_member_sub_requests', 'reminder', 'requests',
+ 'requests_hidden', 'aliases');
+ foreach ($tables as $t) {
+ XDB::execute('DELETE FROM ' . $t . '
+ WHERE uid = {?}',
+ $this->id());
+ }
+
+ foreach (array('gapps_accounts', 'gapps_nicknames') as $t) {
+ XDB::execute('DELETE FROM ' . $t . '
+ WHERE l_userid = {?}',
+ $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($this->id())) {
+ $account = new GoogleAppsAccount($this);
+ $account->suspend();
+ }
+ }
+ }
+
+ $mmlist = new MMList(S::user());
+ $mmlist->kill($this->hruid, $clearAll);
+ }
+
+ // Merge all infos in other user and then clean this one
+ public function mergeIn(User &$newuser) {
+ if ($this->profile()) {
+ // Don't disable user with profile in this way.
+ global $globals;
+ Platal::page()->trigError('Impossible de fusionner les comptes ' . $this->hruid . ' et ' . $newuser->hruid .
+ '. Contacte support@' . $globals->mail->domain . '.');
+ return false;
+ }
+
+ if ($this->forlifeEmail()) {
+ // If the new user is not registered and does not have already an email address,
+ // we need to give him the old user's email address if he has any.
+ if (!$newuser->perms) {
+ XDB::execute('UPDATE accounts
+ SET email = {?}
+ WHERE uid = {?} AND email IS NULL',
+ $this->forlifeEmail(), $newuser->id());
+ }
+ $newemail = XDB::fetchOneCell('SELECT email
+ FROM accounts
+ WHERE uid = {?}',
+ $newuser->id());
+
+ // Change email used in aliases and mailing lists.
+ if ($this->forlifeEmail() != $newemail) {
+ // virtual_redirect (email aliases)
+ XDB::execute('DELETE v1
+ FROM virtual_redirect AS v1, virtual_redirect AS v2
+ WHERE v1.vid = v2.vid AND v1.redirect = {?} AND v2.redirect = {?}',
+ $this->forlifeEmail(), $newemail);
+ XDB::execute('UPDATE virtual_redirect
+ SET redirect = {?}
+ WHERE redirect = {?}',
+ $newemail, $this->forlifeEmail());
+
+ // group mailing lists
+ $group_domains = XDB::fetchColumn('SELECT g.mail_domain
+ FROM groups AS g
+ INNER JOIN group_members AS gm ON(g.id = gm.asso_id)
+ WHERE g.mail_domain != \'\' AND gm.uid = {?}',
+ $this->id());
+ foreach ($group_domains as $mail_domain) {
+ $mmlist = new MMList($this, $mail_domain);
+ $mmlist->replace_email_in_all($this->forlifeEmail(), $newemail);
+ }
+ // main domain lists
+ $mmlist = new MMList($this);
+ $mmlist->replace_email_in_all($this->forlifeEmail(), $newemail);
+ }
+ }
+
+ // Updates user in following tables.
+ foreach (array('group_announces', 'payment_transactions', 'log_sessions', 'group_events') as $table) {
+ XDB::execute('UPDATE ' . $table . '
+ SET uid = {?}
+ WHERE uid = {?}',
+ $newuser->id(), $this->id());
+ }
+
+ // Merges user in following tables, ie updates when possible, then deletes remaining occurences of the old user.
+ foreach (array('group_announces_read', 'group_event_participants', 'group_member_sub_requests', 'group_members') as $table) {
+ XDB::execute('UPDATE IGNORE ' . $table . '
+ SET uid = {?}
+ WHERE uid = {?}',
+ $newuser->id(), $this->id());
+ XDB::execute('DELETE FROM ' . $table . '
+ WHERE uid = {?}',
+ $this->id());
+ }
+
+ // Eventually updates last session id and deletes old user's accounts entry.
+ $lastSession = XDB::fetchOneCell('SELECT id
+ FROM log_sessions
+ WHERE uid = {?}
+ ORDER BY start DESC
+ LIMIT 1',
+ $newuser->id());
+ XDB::execute('UPDATE log_last_sessions
+ SET id = {?}
+ WHERE uid = {?}',
+ $lastSession, $newuser->id());
+ XDB::execute('DELETE FROM accounts
+ WHERE uid = {?}',
+ $this->id());
+
+ return true;
+ }
+
+ // Return permission flags for a given permission level.
+ public static function makePerms($perms, $is_admin)
+ {
+ $flags = new PlFlagSet($perms);