Exemple #1
0
 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());
             // Reftech new user so its forlifeEmail will be correct.
             $newuser = self::getSilentWithUID($newuser->id());
         }
         // Change email used in mailing lists.
         if ($this->forlifeEmail() != $newuser->forlifeEmail()) {
             // The super user is the user who has the right to do the modification.
             $super_user = S::user();
             // 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($super_user, $mail_domain);
                 $mmlist->replace_email_in_all($this->forlifeEmail(), $newuser->forlifeEmail());
             }
             // main domain lists
             $mmlist = new MMList($super_user);
             $mmlist->replace_email_in_all($this->forlifeEmail(), $newuser->forlifeEmail());
         }
     }
     // 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', 'email_redirect_account') 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;
 }