3 /***************************************************************************
4 * Copyright (C) 2003-2014 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
24 * Check that for every profile, the best postal address which is used to
25 * send mail is the right one according to a rule in Address::updateAxMail().
27 * To fix something which has been reported by this script, you only need to
28 * run "Address::updateBestMail($pid)" with $pid being the Profile ID
31 require '../connect.db.inc.php';
32 require_once '../../classes/address.php';
34 $admin_visibility = Visibility
::get(Visibility
::VIEW_ADMIN
);
36 // Enumerate every profile
37 $pids = XDB
::iterRow("SELECT pid from profiles");
38 while ($row = $pids->next()) {
41 // Find the address which would be selected as "AX mail"
42 // But don't update anything
43 $best_mail = Address
::updateBestMail($pid, true
);
44 if (is_null($best_mail)) {
48 // Just continue if the returned address is already selected
49 $flags = new PlFlagSet($best_mail['flags']);
50 if ($flags->hasFlag('dn_best_mail')) {
54 // The current profile is buggy.
55 // Let's fetch more data to print detailed information
56 $profile = Profile
::get($pid);
57 $addresses = ProfileField
::getForPID('ProfileAddresses', array($pid), $admin_visibility);
58 $addresses = $addresses->get(Profile
::ADDRESS_POSTAL
);
62 foreach ($addresses as $addr) {
63 if ($addr->flags
->hasFlag('dn_best_mail')) {
65 } else if ($addr->id
== $best_mail['id']) {
70 echo "Profile " . $profile->hrid() . " ($pid) has a wrongly selected best mail.\n";
71 if (is_null($old_mail)) {
72 echo "... no currently selected best mail\n";
74 echo "... currently selected best mail: " . $old_mail->formatted_address
.
75 " (flags: " . $old_mail->flags
->flags() . ", pub: " . $old_mail->pub
. ")\n";
77 if (is_null($new_mail)) {
78 echo "... unable to find newly selected best mail (BUG!)\n";
80 echo "... best mail that would be selected: " . $new_mail->formatted_address
.
81 " (flags: " . $new_mail->flags
->flags() . ", pub: " . $new_mail->pub
. ")\n";
88 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: