From: Pascal Corpet Date: Tue, 15 Jun 2010 20:30:39 +0000 (+0200) Subject: Fixes switching an ext member of a group to an x user X-Git-Tag: xorg/1.0.0~132 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ab06182d73bdda0d35b4e70822be6e754523772e;p=platal.git Fixes switching an ext member of a group to an x user --- diff --git a/classes/user.php b/classes/user.php index 8761ee7..33b4de2 100644 --- a/classes/user.php +++ b/classes/user.php @@ -617,6 +617,67 @@ class User extends PlUser $mmlist->kill($alias, $clearAll); } + // Merge all infos in other user and then clean this one + public function mergeIn(User &$newuser) { + if ($this->profile() || !$newuser->id()) { + // don't disable user with profile in this way + return false; + } + // TODO check all tables to see if there is no other info to use + + $newemail = $newuser->forlifeEmail(); + if (!$newemail && $this->forlifeEmail()) { + XDB::execute("UPDATE accounts + SET email = {?} + WHERE uid = {?} AND email IS NULL", + $this->forlifeEmail(), $newuser->id()); + $newemail = $this->forlifeEmail(); + } + + // change email used in aliases and mailing lists + if ($this->forlifeEmail() != $newemail && $this->forlifeEmail()) { + // 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()); + + // require_once 'mmlist.php'; + + // 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(), $newmail); + } + // main domain lists + $mmlist = new MMList($this); + $mmlist->replace_email_in_all($this->forlifeEmail(), $newmail); + } + + // group_members (xnet group membership) + XDB::execute("DELETE g1 + FROM group_members AS g1, group_members AS g2 + WHERE g1.uid = {?} AND g2.uid = {?} AND g1.asso_id = g2.asso_id", + $this->id(), $newuser->id()); + XDB::execute("UPDATE group_members + SET uid = {?} + WHERE uid = {?}", + $this->id(), $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) { diff --git a/core b/core index f992b7a..5fe3a77 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit f992b7a5586a214d1704c9e74b7d1299e2c87a03 +Subproject commit 5fe3a77aecc4416235d5f017212a112e5929ee85 diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 35f589e..39c5da1 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -832,25 +832,8 @@ class XnetGrpModule extends PLModule return false; } - // Check if the user is in some groups as an X and as an ext - XDB::execute("DELETE g1 FROM group_members AS g1, group_members AS g2 - WHERE g1.uid = {?} AND g2.uid = {?} AND g1.asso_id = g2.asso_id", - $user->id(), $xuser->id()); - XDB::execute("UPDATE group_members - SET uid = {?} - WHERE uid = {?}", - $xuser->id(), $user->id()); - - // Update subscription to aliases - if ($sub && $user->forlifeEmail() != $xuser->forlifeEmail()) { - XDB::execute("UPDATE IGNORE virtual_redirect AS vr - SET vr.redirect = {?} - WHERE vr.redirect = {?}", - $xuser->forlifeEmail(), $user->forlifeEmail()); - foreach (Env::v('ml1', array()) as $ml => $state) { - $mmlist->replace_email($ml, $user->forlifeEmail(), $xuser->forlifeEmail()); - } - } + $user->mergeIn($xuser); + return $xuser->login(); } @@ -872,7 +855,6 @@ class XnetGrpModule extends PLModule // Convert user status to X if (!Post::blank('login_X')) { - // TODO: Rewrite changeLogin!!! $forlife = $this->changeLogin($page, $user, $mmlist, Post::t('login_X')); if ($forlife) { pl_redirect('member/' . $forlife); diff --git a/upgrade/account/30_xnet_groups.sql b/upgrade/account/30_xnet_groups.sql index 85ef767..1268b49 100644 --- a/upgrade/account/30_xnet_groups.sql +++ b/upgrade/account/30_xnet_groups.sql @@ -14,7 +14,7 @@ INSERT INTO accounts ( NULL as weak_password, NULL as registration_date, '' AS flags, - comm AS comment, + NULL AS comment, email, IF(prenom IS NULL, REPLACE(LEFT(email, POSITION('@' IN email)-1),'.',' '),