* 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).
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;
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;
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);
}
}
// }}}
-function event_change_shortname(&$page, $old, $new)
+function event_change_shortname(&$page, $eid, $old, $new)
{
global $globals;
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);
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;
}
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2008 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+ini_set('include_path', dirname(__FILE__).'/../../include:' . dirname(__FILE__).'/../../classes:/usr/share/php');
+
+require_once 'xorg.inc.php';
+require_once 'xdb.php';
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
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
--- /dev/null
+#!/usr/bin/php5
+<?php
+
+global $globals;
+require_once 'connect.db.inc.php';
+
+// Fetches the list of existing xnetevents aliases.
+$events = XDB::iterRow(
+ "SELECT e.eid, e.asso_id, e.short_name, al.vid, pl.vid
+ FROM groupex.evenements AS e
+ LEFT JOIN virtual AS al ON (al.type = 'evt' AND al.alias = CONCAT(short_name, {?}))
+ LEFT JOIN virtual AS pl ON (pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?}))
+ WHERE al.vid IS NOT NULL AND pl.vid IS NOT NULL
+ ORDER BY e.eid",
+ '-absents@'.$globals->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]);
+ }
+}