| 1 | #!/usr/bin/php5 -q |
| 2 | <?php |
| 3 | /*************************************************************************** |
| 4 | * Copyright (C) 2003-2014 Polytechnique.org * |
| 5 | * http://opensource.polytechnique.org/ * |
| 6 | * * |
| 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. * |
| 11 | * * |
| 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. * |
| 16 | * * |
| 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 * |
| 19 | * Foundation, Inc., * |
| 20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | /** |
| 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(). |
| 26 | * |
| 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 |
| 29 | */ |
| 30 | |
| 31 | require '../connect.db.inc.php'; |
| 32 | require_once '../../classes/address.php'; |
| 33 | |
| 34 | $admin_visibility = Visibility::get(Visibility::VIEW_ADMIN); |
| 35 | |
| 36 | // Enumerate every profile |
| 37 | $pids = XDB::iterRow("SELECT pid from profiles"); |
| 38 | while ($row = $pids->next()) { |
| 39 | $pid = $row[0]; |
| 40 | |
| 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)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | // Just continue if the returned address is already selected |
| 49 | $flags = new PlFlagSet($best_mail['flags']); |
| 50 | if ($flags->hasFlag('dn_best_mail')) { |
| 51 | continue; |
| 52 | } |
| 53 | |
| 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); |
| 59 | |
| 60 | $old_mail = null; |
| 61 | $new_mail = null; |
| 62 | foreach ($addresses as $addr) { |
| 63 | if ($addr->flags->hasFlag('dn_best_mail')) { |
| 64 | $old_mail = $addr; |
| 65 | } else if ($addr->id == $best_mail['id']) { |
| 66 | $new_mail = $addr; |
| 67 | } |
| 68 | } |
| 69 | |
| 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"; |
| 73 | } else { |
| 74 | echo "... currently selected best mail: " . $old_mail->formatted_address . |
| 75 | " (flags: " . $old_mail->flags->flags() . ", pub: " . $old_mail->pub . ")\n"; |
| 76 | } |
| 77 | if (is_null($new_mail)) { |
| 78 | echo "... unable to find newly selected best mail (BUG!)\n"; |
| 79 | } else { |
| 80 | echo "... best mail that would be selected: " . $new_mail->formatted_address . |
| 81 | " (flags: " . $new_mail->flags->flags() . ", pub: " . $new_mail->pub . ")\n"; |
| 82 | } |
| 83 | echo "\n"; |
| 84 | } |
| 85 | |
| 86 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
| 87 | ?> |