Fixes xnetevents aliases creation and update:
authorVincent Zanotti <vincent.zanotti@polytechnique.org>
Sat, 15 Mar 2008 16:58:51 +0000 (17:58 +0100)
committerVincent Zanotti <vincent.zanotti@polytechnique.org>
Sat, 15 Mar 2008 16:59:08 +0000 (17:59 +0100)
 * 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
modules/xnetevents/xnetevents.inc.php
upgrade/0.9.16/connect.db.inc.php [new file with mode: 0644]
upgrade/0.9.16/update.sh
upgrade/0.9.16/xnetevents.list.php [new file with mode: 0755]

index 56fc766..3910dbc 100644 (file)
@@ -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);
             }
 
index a9ca09c..b1822da 100644 (file)
@@ -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 (file)
index 0000000..2e66895
--- /dev/null
@@ -0,0 +1,28 @@
+<?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:
+?>
index 30823e5..b38d294 100755 (executable)
@@ -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 (executable)
index 0000000..60dab53
--- /dev/null
@@ -0,0 +1,66 @@
+#!/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]);
+    }
+}