From 680a61540cce191d2af42a356591632bf1e1f482 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Wed, 17 Nov 2004 10:12:44 +0000 Subject: [PATCH] epouse is now a flag, not a type anymore --- htdocs/admin/utilisateurs.php | 4 ++-- htdocs/auth-groupex.php | 14 +++++++++++--- htdocs/carnet/mescontacts_pdf.php | 6 +++--- htdocs/fiche.php | 6 +++--- htdocs/routage-mail.php | 7 +++++-- include/insert.password.inc.php | 7 +++++-- include/valid_epouses.inc.php | 9 +++++---- include/xorg.session.inc.php | 8 ++++---- scripts/migration/0.9.3/10_aliases.sql | 5 +++++ scripts/migration/0.9.3/update.sh | 18 ++++++++++++++++++ 10 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 scripts/migration/0.9.3/10_aliases.sql create mode 100755 scripts/migration/0.9.3/update.sh diff --git a/htdocs/admin/utilisateurs.php b/htdocs/admin/utilisateurs.php index 9c93383..c90c9a5 100644 --- a/htdocs/admin/utilisateurs.php +++ b/htdocs/admin/utilisateurs.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: utilisateurs.php,v 1.28 2004-11-16 21:13:31 x2000habouzit Exp $ + $Id: utilisateurs.php,v 1.29 2004-11-17 10:12:44 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -159,7 +159,7 @@ if(isset($mr)) { $globals->db->query("delete from photo where uid=$user_id"); $globals->db->query("delete from perte_pass where uid=$user_id"); $globals->db->query("delete from user_changes where user_id=$user_id"); - $globals->db->query("delete from aliases where id=$user_id and type in ('a_vie','epouse','alias')"); + $globals->db->query("delete from aliases where id=$user_id and type in ('a_vie','alias')"); $globals->db->query("delete from listes_ins where idu=$user_id"); $globals->db->query("delete from listes_mod where idu=$user_id"); $globals->db->query("delete from applis_ins where uid=$user_id"); diff --git a/htdocs/auth-groupex.php b/htdocs/auth-groupex.php index f89edfb..0d1bbb9 100644 --- a/htdocs/auth-groupex.php +++ b/htdocs/auth-groupex.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: auth-groupex.php,v 1.7 2004-10-08 20:07:18 web Exp $ + $Id: auth-groupex.php,v 1.8 2004-11-17 10:12:44 x2000habouzit Exp $ ***************************************************************************/ $gpex_pass = $_GET["pass"]; @@ -53,7 +53,11 @@ function gpex_make_auth($chlg, $privkey, $datafields) { if (isset($_SESSION[$val])) { $tohash .= stripslashes($_SESSION[$val]); } else if ($val == 'username') { - $sql = "SELECT alias FROM aliases AS al INNER JOIN auth_user_md5 AS a ON (a.user_id = al.id AND (al.type = 'a_vie' OR al.type = 'alias' OR al.type = 'epouse')) WHERE a.user_id = ".$_SESSION["uid"]." AND alias LIKE '%.%' ORDER BY LENGTH(alias)"; + $sql = "SELECT alias + FROM aliases AS al + INNER JOIN auth_user_md5 AS a ON (a.user_id = al.id AND al.type IN('a_vie','alias')) + WHERE a.user_id = ".$_SESSION["uid"]." AND alias LIKE '%.%' + ORDER BY LENGTH(alias)"; $res = mysql_query($sql); list($min_username) = mysql_fetch_array($res); $tohash .= stripslashes($min_username); @@ -71,7 +75,11 @@ function gpex_make_params($chlg, $privkey, $datafields) { if (isset($_SESSION[$val])) { $params .= "&$val=".$_SESSION[$val]; } else if ($val == 'username') { - $sql = "SELECT alias FROM aliases AS al INNER JOIN auth_user_md5 AS a ON (a.user_id = al.id AND (al.type = 'a_vie' OR al.type = 'alias' OR al.type = 'epouse')) WHERE a.user_id = ".$_SESSION["uid"]." AND alias LIKE '%.%' ORDER BY LENGTH(alias)"; + $sql = "SELECT alias + FROM aliases AS al + INNER JOIN auth_user_md5 AS a ON (a.user_id = al.id AND al.type IN('a_vie','alias')) + WHERE a.user_id = ".$_SESSION["uid"]." AND alias LIKE '%.%' + ORDER BY LENGTH(alias)"; $res = mysql_query($sql); list($min_username) = mysql_fetch_array($res); $params .= "&$val=".$min_username; diff --git a/htdocs/carnet/mescontacts_pdf.php b/htdocs/carnet/mescontacts_pdf.php index 7261592..83698e6 100644 --- a/htdocs/carnet/mescontacts_pdf.php +++ b/htdocs/carnet/mescontacts_pdf.php @@ -18,11 +18,11 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: mescontacts_pdf.php,v 1.1 2004-11-04 15:33:27 x2000habouzit Exp $ + $Id: mescontacts_pdf.php,v 1.2 2004-11-17 10:12:45 x2000habouzit Exp $ ***************************************************************************/ # -# $Id: mescontacts_pdf.php,v 1.1 2004-11-04 15:33:27 x2000habouzit Exp $ +# $Id: mescontacts_pdf.php,v 1.2 2004-11-17 10:12:45 x2000habouzit Exp $ # require("auto.prepend.inc.php"); @@ -33,7 +33,7 @@ require("applis.func.inc.php"); $sql = "SELECT a.*,c.*,e.alias as epouse FROM auth_user_md5 AS a INNER JOIN contacts AS c ON ( a.user_id = c.contact ) - LEFT JOIN aliases AS e ON ( a.user_id = e.id and type='epouse' ) + LEFT JOIN aliases AS e ON ( a.user_id = e.id and FIND_IN_SET('epouse',e.flags) ) WHERE c.uid = {$_SESSION['uid']}"; // choix de l'ordre des réponses (par promo ou par noms) if(isset($_GET['order']) && $_GET['order']=="promo") { diff --git a/htdocs/fiche.php b/htdocs/fiche.php index 659d841..b084968 100644 --- a/htdocs/fiche.php +++ b/htdocs/fiche.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: fiche.php,v 1.20 2004-11-13 14:16:15 x2000habouzit Exp $ + $Id: fiche.php,v 1.21 2004-11-17 10:12:44 x2000habouzit Exp $ ***************************************************************************/ @@ -49,12 +49,12 @@ $reqsql = "SELECT u.prenom, u.nom, u.epouse, IF(gp.nat='',gp.pays,gp.nat) AS te u.libre, u.promo, c.uid IS NOT NULL, p.x, p.y FROM auth_user_md5 AS u INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') - INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND (a2.type='alias' OR a2.type='epouse') AND a2.alias LIKE '%.%') + INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND a2.type='alias' AND a2.alias LIKE '%.%') LEFT JOIN contacts AS c ON (c.uid = {$_SESSION['uid']} and c.contact = u.user_id) LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) INNER JOIN sections ON(sections.id = u.section) LEFT JOIN photo as p ON(p.uid = u.user_id)".$where_clause." - ORDER BY a2.type != 'epouse', LENGTH(a2.alias) LIMIT 1"; + ORDER BY !FIND_IN_SET('epouse',a2.flags), LENGTH(a2.alias) LIMIT 1"; $result = $globals->db->query($reqsql); diff --git a/htdocs/routage-mail.php b/htdocs/routage-mail.php index 9372f21..147b492 100644 --- a/htdocs/routage-mail.php +++ b/htdocs/routage-mail.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: routage-mail.php,v 1.10 2004-11-07 20:17:22 x2000habouzit Exp $ + $Id: routage-mail.php,v 1.11 2004-11-17 10:12:44 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -52,7 +52,10 @@ list($grx) = mysql_fetch_row($res); $page->assign('grx',$grx); $page->assign('domaine',substr($grx,0,-3)); -$page->mysql_assign("SELECT alias,expire FROM aliases WHERE id='{$_SESSION['uid']}' AND (type='a_vie' OR type='alias' OR type='epouse') ORDER BY type!='epouse', LENGTH(alias)", 'alias'); +$page->mysql_assign("SELECT alias,expire + FROM aliases + WHERE id='{$_SESSION['uid']}' AND (type='a_vie' OR type='alias') + ORDER BY !FIND_IN_SET('epouse',flags), LENGTH(alias)", 'alias'); $page->assign('emails',$redirect->emails); $page->run(); diff --git a/include/insert.password.inc.php b/include/insert.password.inc.php index 1960be1..2d53ac0 100644 --- a/include/insert.password.inc.php +++ b/include/insert.password.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: insert.password.inc.php,v 1.5 2004-10-10 09:09:34 x2000chevalier Exp $ + $Id: insert.password.inc.php,v 1.6 2004-11-17 10:12:45 x2000habouzit Exp $ ***************************************************************************/ function smarty_insert_getName() { @@ -37,7 +37,10 @@ function smarty_insert_getUsername() { if(isset($_COOKIE['ORGuid'])) $id = $_COOKIE['ORGuid']; if(isset($_SESSION['uid'])) $id = $_SESSION['uid']; if(empty($id)) return ""; - $res = $globals->db->query("SELECT alias FROM aliases WHERE id='$id' AND (type='a_vie' OR type='alias' OR type='epouse') ORDER BY type!='epouse', LENGTH(alias) LIMIT 1"); + $res = $globals->db->query("SELECT alias + FROM aliases + WHERE id='$id' AND (type='a_vie' OR type='alias') + ORDER BY !FIND_IN_SET('epouse',flags), LENGTH(alias) LIMIT 1"); if(list($uname) = mysql_fetch_row($res)) { mysql_free_result($res); return $uname; diff --git a/include/valid_epouses.inc.php b/include/valid_epouses.inc.php index e567dd9..10a8daa 100644 --- a/include/valid_epouses.inc.php +++ b/include/valid_epouses.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: valid_epouses.inc.php,v 1.17 2004-10-19 22:05:09 x2000habouzit Exp $ + $Id: valid_epouses.inc.php,v 1.18 2004-11-17 10:12:45 x2000habouzit Exp $ ***************************************************************************/ @@ -47,7 +47,7 @@ class EpouseReq extends Validate { $sql = $globals->db->query(" SELECT e.alias, u.epouse, u.prenom, u.nom, a.id FROM auth_user_md5 as u - LEFT JOIN aliases as e ON(e.type='epouse' AND e.id = u.user_id) + LEFT JOIN aliases as e ON(e.type='alias' AND FIND_IN_SET('epouse',e.flags) AND e.id = u.user_id) LEFT JOIN aliases as a ON(a.alias = '{$this->alias}' AND a.id != u.user_id) WHERE u.user_id = ".$this->uid); list($this->oldalias, $this->oldepouse, $this->prenom, $this->nom, $this->homonyme) = mysql_fetch_row($sql); @@ -91,8 +91,9 @@ class EpouseReq extends Validate { global $globals; $globals->db->query("UPDATE auth_user_md5 set epouse='".$this->epouse."' WHERE user_id=".$this->uid); - $globals->db->query("DELETE FROM aliases WHERE type='epouse' AND id=".$this->uid); - $globals->db->query("INSERT INTO aliases VALUES('".$this->alias."', 'epouse', ".$this->uid.")"); + $globals->db->query("DELETE FROM aliases WHERE FIND_IN_SET('epouse',flags) AND id=".$this->uid); + $globals->db->query("UPDATE aliases SET flags='' WHERE flags='bestalias' AND id=".$this->uid); + $globals->db->query("INSERT INTO aliases VALUES('".$this->alias."', 'alias', 'epouse,bestalias', ".$this->uid.", null)"); $f = fopen("/tmp/flag_recherche","w"); fputs($f,"1"); fclose($f); diff --git a/include/xorg.session.inc.php b/include/xorg.session.inc.php index c8ad395..3d35fee 100644 --- a/include/xorg.session.inc.php +++ b/include/xorg.session.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: xorg.session.inc.php,v 1.37 2004-11-06 18:18:44 x2000habouzit Exp $ + $Id: xorg.session.inc.php,v 1.38 2004-11-17 10:12:45 x2000habouzit Exp $ ***************************************************************************/ require("diogenes.core.session.inc.php"); @@ -222,14 +222,14 @@ function start_connexion ($uid, $identified) { $result=$globals->db->query(" SELECT prenom, nom, perms, promo, matricule, UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, a.alias, UNIX_TIMESTAMP(q.lastnewslogin), q.watch_last, - a2.alias, password, FIND_IN_SET('femme', flags) + a2.alias, password, FIND_IN_SET('femme', u.flags) FROM auth_user_md5 AS u INNER JOIN auth_user_quick AS q USING(user_id) INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') - INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND (a2.type='a_vie' OR a2.type='alias' OR a2.type='epouse') AND a2.alias LIKE '%.%') + INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND (a2.type='a_vie' OR a2.type='alias') AND a2.alias LIKE '%.%') LEFT JOIN logger.sessions AS s ON (s.uid=u.user_id AND s.suid=0) WHERE u.user_id=$uid - ORDER BY s.start DESC, a2.type != 'epouse', length(a2.alias) + ORDER BY s.start DESC, !FIND_IN_SET('epouse', a2.flags), length(a2.alias) LIMIT 1"); list($prenom, $nom, $perms, $promo, $matricule, $lastlogin, $host, $forlife, $lastnewslogin, $watch_last, diff --git a/scripts/migration/0.9.3/10_aliases.sql b/scripts/migration/0.9.3/10_aliases.sql new file mode 100644 index 0000000..197936f --- /dev/null +++ b/scripts/migration/0.9.3/10_aliases.sql @@ -0,0 +1,5 @@ +alter table aliases add column flags set('epouse','bestalias') not null after type; +update aliases set flags='epouse' where type='epouse'; +update aliases set type='epouse' where type='epouse'; +alter table aliases change column type type enum('a_vie','alias','homonyme','liste') not null; +alter table aliases add index (flags); diff --git a/scripts/migration/0.9.3/update.sh b/scripts/migration/0.9.3/update.sh new file mode 100755 index 0000000..d198a30 --- /dev/null +++ b/scripts/migration/0.9.3/update.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +. ../inc/pervasive.sh + +mailman_stop +mailman_templates +mailman_start + + +########################################################### +for sql in *.sql +do + echo -n $sql + $MYSQL x4dat < $sql &>/dev/null || echo -n " ERROR" + echo . +done + +########################################################### -- 2.1.4