4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, 2010, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
24 $shortoptions = 'i::n::y';
25 $longoptions = array('id=', 'nickname=', 'yes', 'all', 'dry-run');
27 $helptext = <<<END_OF_DELETEUSER_HELP
28 clear_jabber.php [options]
29 Deletes a user's confirmed Jabber/XMPP address from the database.
31 -i --id ID of the user
32 -n --nickname nickname of the user
33 --all all users with confirmed Jabber addresses
34 --dry-run Don't actually delete info.
36 END_OF_DELETEUSER_HELP;
38 require_once INSTALLDIR.'/scripts/commandline.inc';
40 if (have_option('i', 'id')) {
41 $id = get_option_value('i', 'id');
42 $user = User::getKV('id', $id);
44 print "Can't find user with ID $id\n";
47 } else if (have_option('n', 'nickname')) {
48 $nickname = get_option_value('n', 'nickname');
49 $user = User::getKV('nickname', $nickname);
51 print "Can't find user with nickname '$nickname'\n";
54 } else if (have_option('all')) {
56 $user->whereAdd("jabber != ''");
59 print "No users with registered Jabber addresses in database.\n";
63 print "You must provide either an ID or a nickname.\n";
69 function clear_jabber($id)
71 $user = User::getKV('id', $id);
72 if ($user && $user->jabber) {
73 echo "clearing user $id's user.jabber, was: $user->jabber";
74 if (have_option('dry-run')) {
77 $original = clone($user);
80 $user->updateWithKeys($original);
81 } catch (Exception $e) {
82 echo "WARNING: user update failed (setting jabber to null): ".$e->getMessage()."\n";
87 echo "Missing user for $id\n";
89 echo "Cleared jabber already for $id\n";
94 clear_jabber($user->id);
95 } while ($user->fetch());