From: x2000habouzit Date: Fri, 5 Nov 2004 13:30:12 +0000 (+0000) Subject: more notification script X-Git-Tag: xorg/old~1055 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=2fc2b16e51e19c65b641e9007170e04e4abcc032;p=platal.git more notification script --- diff --git a/scripts/cron/watch.notifs.php b/scripts/cron/watch.notifs.php index 17c8918..08966ec 100755 --- a/scripts/cron/watch.notifs.php +++ b/scripts/cron/watch.notifs.php @@ -19,12 +19,12 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: watch.notifs.php,v 1.1 2004-11-04 20:27:31 x2000habouzit Exp $ + $Id: watch.notifs.php,v 1.2 2004-11-05 13:30:12 x2000habouzit Exp $ ***************************************************************************/ /* * verifie qu'il n'y a pas d'incoherences dans les tables de jointures * - * $Id: watch.notifs.php,v 1.1 2004-11-04 20:27:31 x2000habouzit Exp $ + * $Id: watch.notifs.php,v 1.2 2004-11-05 13:30:12 x2000habouzit Exp $ */ require('./connect.db.inc.php'); @@ -33,9 +33,120 @@ mysql_query("LOCK TABLE watch_ops"); // be smart here -mysql_query("DELETE FROM watch_ops"); + +function search_notifs($sql, &$array, &$ops) { + $res = mysql_query($sql); + while(list($uid,$prenom,$nom,$forlife,$nuid,$nprenom,$nnom,$npromo,$nforlife,$nop,$ndate) = mysql_fetch_row($res)) { + $array[$uid]['prenom'] = $prenom; + $array[$uid]['nom'] = $nom; + $array[$uid]['forlife']= $forlife; + $array[$uid][$nop][$nuid] = $npromo.strtolower($nnom); + $ops[$nop][$nuid] = Array('prenom'=>$nprenom,'nom'=>$nnom,'forlife'=>$nforlife,'promo'=>$npromo,'date'=>$ndate); + } + mysql_free_result($res); +} + +function print_notif($uid,$op) { + global $ops; + echo " - ({$ops[$op][$uid]['promo']}) {$ops[$op][$uid]['prenom']} {$ops[$op][$uid]['nom']}, le {$ops[$op][$uid]['date']}\n"; +} + +function do_notif(&$not) { + echo "Notifications pour {$not['prenom']} {$not['nom']} <{$not['forlife']}@polytechnique.org>\n"; + if(isset($not['ins'])) { + asort($not['ins']); + echo " Ces camarades viennent de s'inscrire :\n"; + foreach($not['ins'] as $uid=>$foo) print_notif($uid,'ins'); + } + if(isset($not['fiche'])) { + asort($not['fiche']); + echo " Ces camarades ont mis leur fiche à jour :\n"; + foreach($not['fiche'] as $uid=>$foo) print_notif($uid,'fiche'); + } + if(isset($not['death'])) { + asort($not['death']); + echo " Ces camarades sont décédés :\n"; + foreach($not['death'] as $uid=>$foo) print_notif($uid,'death'); + } + echo "\n"; +} + +$notifs = Array(); +$ops = Array(); + +$sql = "SELECT u.user_id, u.prenom, IF(u.epouse='',u.nom,u.epouse), a.alias, + v.user_id, v.prenom, IF(v.epouse='',v.nom,v.epouse) AS nom, v.promo, b.alias, + o.op, IF(o.op='death',v.deces,IF(o.op='fiche',v.date,DATE_FORMAT(v.date_ins,'%Y-%m-%d'))) + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') + INNER JOIN contacts AS c ON (u.user_id = c.uid) + INNER JOIN watch_ops AS o ON (c.contact = o.user_id) + INNER JOIN auth_user_md5 AS v ON (o.user_id = v.user_id) + INNER JOIN aliases AS b ON (o.user_id = b.id AND b.type='a_vie') + WHERE FIND_IN_SET('contacts',u.watch) AND u.user_id!=v.user_id +"; +search_notifs($sql,$notifs,$ops); + +$sql = "SELECT u.user_id, u.prenom, IF(u.epouse='',u.nom,u.epouse), a.alias, + v.user_id, v.prenom, IF(v.epouse='',v.nom,v.epouse) AS nom, v.promo, b.alias, + o.op, IF(o.op='death',v.deces,IF(o.op='fiche',v.date,DATE_FORMAT(v.date_ins,'%Y-%m-%d'))) + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') + INNER JOIN watch AS w ON (u.user_id = w.user_id AND w.type='promo') + INNER JOIN auth_user_md5 AS v ON (v.promo = w.arg) + INNER JOIN watch_ops AS o ON (v.user_id = o.user_id AND o.op != 'fiche') + LEFT JOIN aliases AS b ON (o.user_id = b.id AND b.type='a_vie') + WHERE u.user_id!=v.user_id +"; +search_notifs($sql,$notifs,$ops); + +$sql = "SELECT u.user_id, u.prenom, IF(u.epouse='',u.nom,u.epouse), a.alias, + v.user_id, v.prenom, IF(v.epouse='',v.nom,v.epouse) AS nom, v.promo, b.alias, + o.op, IF(o.op='death',v.deces,IF(o.op='fiche',v.date,DATE_FORMAT(v.date_ins,'%Y-%m-%d'))) + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') + INNER JOIN watch AS w ON (u.user_id = w.user_id AND w.type='non-inscrit') + INNER JOIN auth_user_md5 AS v ON (v.user_id = w.arg) + INNER JOIN watch_ops AS o ON (v.user_id = o.user_id) + LEFT JOIN aliases AS b ON (o.user_id = b.id AND b.type='a_vie') + WHERE u.user_id!=v.user_id +"; +search_notifs($sql,$notifs,$ops); + + +/******************************************************************************* + * DELETE dead pple from contacts for those who wants it, and from the watch + */ +mysql_query("DELETE FROM contacts + USING contacts AS c + INNER JOIN auth_user_md5 AS u ON (u.user_id = c.uid AND FIND_IN_SET('deaths',u.watch)) + INNER JOIN auth_user_md5 AS v ON (c.contact = v.user_id AND v.deces!='0000-00-00')"); + +mysql_query("DELETE FROM watch + USING watch AS w + INNER JOIN auth_user_md5 AS u ON (u.user_id = w.arg AND w.type='non-inscrit' AND u.deces!='0000-00-00')"); + + +/******************************************************************************* + * INSERT watched nonins into contacts + */ + +mysql_query("INSERT INTO contacts (uid,contact) + SELECT w.user_id,w.arg + FROM watch AS w + INNER JOIN auth_user_md5 AS u ON (u.user_id = w.arg AND w.type='non-inscrit' AND u.perms!='non-inscrit')"); + +mysql_query("DELETE FROM watch + USING watch AS w + INNER JOIN auth_user_md5 AS u ON (u.user_id = w.arg AND w.type='non-inscrit' AND u.perms!='non-inscrit')"); + +//mysql_query("DELETE FROM watch_ops"); mysql_query("UNLOCK TABLE watch_ops"); -// send 10238 mails here +/******************************************************************************* + * DO notifications HERE ONLY (slow) + */ + +foreach($notifs as $user=>$notiflist) do_notif($notiflist); ?> diff --git a/scripts/migration/0.9.2/notifs.sql b/scripts/migration/0.9.2/notifs.sql index 8a0e731..db09356 100644 --- a/scripts/migration/0.9.2/notifs.sql +++ b/scripts/migration/0.9.2/notifs.sql @@ -1,4 +1,5 @@ alter table auth_user_md5 add column watch set('contacts', 'deaths') default 'contacts' not null; +alter table aliases add index (type); create table watch ( user_id smallint not null,