From 2847640f8126df73bea03d86c018961747aea5b7 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Sat, 15 Mar 2008 17:58:51 +0100 Subject: [PATCH] Fixes xnetevents aliases creation and update: * Proper initialization of '-participants' alias (previously, no member was ever added on alias creation). * Proper initialization of '-absents' alias (previously, only groupex members who had never participated to any events were added). * Adds an upgrade script to fix existing aliases. * Admin changes on participation list were improperly synchronized with aliases (Closes #730). --- modules/xnetevents.php | 7 ++-- modules/xnetevents/xnetevents.inc.php | 8 ++--- upgrade/0.9.16/connect.db.inc.php | 28 +++++++++++++++ upgrade/0.9.16/update.sh | 8 +++++ upgrade/0.9.16/xnetevents.list.php | 66 +++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 upgrade/0.9.16/connect.db.inc.php create mode 100755 upgrade/0.9.16/xnetevents.list.php diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 56fc766..3910dbc 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -244,7 +244,7 @@ class XnetEventsModule extends PLModule XDB::execute( "DELETE FROM groupex.evenements_participants WHERE eid = {?} AND uid = {?} AND item_id = {?}", - $eid, S::v("uid"), $j); + $eid, S::v("uid"), $j); $updated = $eid; } $total += $nb; @@ -356,7 +356,8 @@ class XnetEventsModule extends PLModule if (Post::v('intitule')) { require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php'; - $short_name = event_change_shortname($page, $infos['short_name'], + $short_name = event_change_shortname($page, $eid, + $infos['short_name'], Env::v('short_name', '')); if ($short_name != Env::v('short_name')) { $error = true; @@ -556,7 +557,7 @@ class XnetEventsModule extends PLModule GROUP BY uid", $member['uid'], $evt['eid']); $u = $res->fetchOneAssoc(); - $u = $u['cnt'] ? null : $u['nb']; + $u = $u['cnt'] ? $u['nb'] : null; subscribe_lists_event($u, $member['uid'], $evt); } diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index a9ca09c..b1822da 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -250,7 +250,7 @@ function subscribe_lists_event($participate, $uid, $evt) } // }}} -function event_change_shortname(&$page, $old, $new) +function event_change_shortname(&$page, $eid, $old, $new) { global $globals; @@ -307,7 +307,7 @@ function event_change_shortname(&$page, $old, $new) LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid) LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid) LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie') - WHERE ep.eid = {?} + WHERE ep.eid = {?} AND ep.nb > 0 GROUP BY ep.uid)", $lastid, '@'.$globals->mail->domain, $eid); @@ -318,12 +318,12 @@ function event_change_shortname(&$page, $old, $new) XDB::execute("INSERT INTO virtual_redirect ( SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect FROM groupex.membres AS m - LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid) + LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?}) LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid) LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie') WHERE m.asso_id = {?} AND ep.uid IS NULL GROUP BY m.uid)", - $lastid, "@".$globals->mail->domain, $globals->asso('id')); + $lastid, "@".$globals->mail->domain, $eid, $globals->asso('id')); return $new; } diff --git a/upgrade/0.9.16/connect.db.inc.php b/upgrade/0.9.16/connect.db.inc.php new file mode 100644 index 0000000..2e66895 --- /dev/null +++ b/upgrade/0.9.16/connect.db.inc.php @@ -0,0 +1,28 @@ + diff --git a/upgrade/0.9.16/update.sh b/upgrade/0.9.16/update.sh index 30823e5..b38d294 100755 --- a/upgrade/0.9.16/update.sh +++ b/upgrade/0.9.16/update.sh @@ -9,8 +9,16 @@ mailman_stop mailman_templates mailman_start +########################################################### + +echo "fixing the xnetevents aliases (this may be a long operation)" + +./xnetevents.list.php ########################################################### + +echo "upgrading the database" + for sql in *.sql do echo -n $sql diff --git a/upgrade/0.9.16/xnetevents.list.php b/upgrade/0.9.16/xnetevents.list.php new file mode 100755 index 0000000..60dab53 --- /dev/null +++ b/upgrade/0.9.16/xnetevents.list.php @@ -0,0 +1,66 @@ +#!/usr/bin/php5 +xnet->evts_domain, + '-participants@'.$globals->xnet->evts_domain); + +// Fixes the alias recipients for each list. +while (list($eid, $asso_id, $shortname, $absent_vid, $participant_vid) = $events->next()) { + $recipient_count = array(); + foreach (array($absent_vid, $participant_vid) as $vid) { + $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid); + $recipient_count[$vid] = $res->fetchOneCell(); + } + + // Updates the alias for participants. + XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $participant_vid); + XDB::execute( + "INSERT INTO virtual_redirect ( + SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect + FROM groupex.evenements_participants AS ep + LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid) + LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid) + LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie') + WHERE ep.eid = {?} AND ep.nb > 0 + GROUP BY ep.uid)", + $participant_vid, '@'.$globals->mail->domain, $eid); + + // Updates the alias for absents. + XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $absent_vid); + XDB::execute( + "INSERT INTO virtual_redirect ( + SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect + FROM groupex.membres AS m + LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?}) + LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid) + LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie') + WHERE m.asso_id = {?} AND ep.uid IS NULL + GROUP BY m.uid)", + $absent_vid, "@".$globals->mail->domain, $eid, $asso_id); + + // Lists alias recipient count changes. + $new_recipient_count = array(); + foreach (array($absent_vid, $participant_vid) as $vid) { + $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid); + $new_recipient_count[$vid] = $res->fetchOneCell(); + } + + if ($new_recipient_count[$absent_vid] != $recipient_count[$absent_vid] || + $new_recipient_count[$participant_vid] != $recipient_count[$participant_vid]) { + printf(" Fixed aliases for event %d (%s): absent list %d -> %d, participant list %d -> %d\n", + $eid, $shortname, + $recipient_count[$absent_vid], $new_recipient_count[$absent_vid], + $recipient_count[$participant_vid], $new_recipient_count[$participant_vid]); + } +} -- 2.1.4