Moving to GitHub.
[platal.git] / upgrade / 0.9.16 / xnetevents.list.php
CommitLineData
2847640f
VZ
1#!/usr/bin/php5
2<?php
3
4global $globals;
5require_once 'connect.db.inc.php';
6
7// Fetches the list of existing xnetevents aliases.
8$events = XDB::iterRow(
9 "SELECT e.eid, e.asso_id, e.short_name, al.vid, pl.vid
10 FROM groupex.evenements AS e
11 LEFT JOIN virtual AS al ON (al.type = 'evt' AND al.alias = CONCAT(short_name, {?}))
12 LEFT JOIN virtual AS pl ON (pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?}))
13 WHERE al.vid IS NOT NULL AND pl.vid IS NOT NULL
14 ORDER BY e.eid",
15 '-absents@'.$globals->xnet->evts_domain,
16 '-participants@'.$globals->xnet->evts_domain);
17
18// Fixes the alias recipients for each list.
19while (list($eid, $asso_id, $shortname, $absent_vid, $participant_vid) = $events->next()) {
20 $recipient_count = array();
21 foreach (array($absent_vid, $participant_vid) as $vid) {
22 $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid);
23 $recipient_count[$vid] = $res->fetchOneCell();
24 }
25
26 // Updates the alias for participants.
27 XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $participant_vid);
28 XDB::execute(
29 "INSERT INTO virtual_redirect (
30 SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
31 FROM groupex.evenements_participants AS ep
32 LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid)
33 LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid)
34 LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie')
35 WHERE ep.eid = {?} AND ep.nb > 0
36 GROUP BY ep.uid)",
37 $participant_vid, '@'.$globals->mail->domain, $eid);
38
39 // Updates the alias for absents.
40 XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $absent_vid);
41 XDB::execute(
42 "INSERT INTO virtual_redirect (
43 SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
44 FROM groupex.membres AS m
45 LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
46 LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid)
47 LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie')
48 WHERE m.asso_id = {?} AND ep.uid IS NULL
49 GROUP BY m.uid)",
50 $absent_vid, "@".$globals->mail->domain, $eid, $asso_id);
51
52 // Lists alias recipient count changes.
53 $new_recipient_count = array();
54 foreach (array($absent_vid, $participant_vid) as $vid) {
55 $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid);
56 $new_recipient_count[$vid] = $res->fetchOneCell();
57 }
58
59 if ($new_recipient_count[$absent_vid] != $recipient_count[$absent_vid] ||
60 $new_recipient_count[$participant_vid] != $recipient_count[$participant_vid]) {
61 printf(" Fixed aliases for event %d (%s): absent list %d -> %d, participant list %d -> %d\n",
62 $eid, $shortname,
63 $recipient_count[$absent_vid], $new_recipient_count[$absent_vid],
64 $recipient_count[$participant_vid], $new_recipient_count[$participant_vid]);
65 }
66}