-function switch_bestalias(PlUser &$user, $loginbis) {
- // check if loginbis was the bestalias
- $bestailas = XDB::fetchOneCell("SELECT alias
- FROM aliases
- WHERE uid = {?} AND FIND_IN_SET('bestalias', flags)",
- $user->id());
- if ($bestalias && $bestalias != $loginbis) {
- return false;
- }
-
- // select the shortest alias still alive
- $newbest = XDB::fetchOneCell("SELECT alias
- FROM aliases
- WHERE uid = {?} AND alias != {?} AND expire IS NULL
- ORDER BY LENGTH(alias)
- LIMIT 1", $user->id(), $loginbis);
- // change the bestalias flag
- XDB::execute("UPDATE aliases
- SET flags = (flags & (255 - 1)) | IF(alias = {?}, 1, 0)
- WHERE uid = {?}", $newbest, $user->id());
- return $newbest;
-}
-