]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/clear_jabber.php
Make attachment fit better in notice: drop text and link
[quix0rs-gnu-social.git] / scripts / clear_jabber.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2008, 2009, 2010, StatusNet, Inc.
6  *
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.
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 Affero General Public License for more details.
16  *
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/>.
19  */
20
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
23
24 $shortoptions = 'i::n::y';
25 $longoptions = array('id=', 'nickname=', 'yes', 'all', 'dry-run');
26
27 $helptext = <<<END_OF_DELETEUSER_HELP
28 clear_jabber.php [options]
29 Deletes a user's confirmed Jabber/XMPP address from the database.
30
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.
35
36 END_OF_DELETEUSER_HELP;
37
38 require_once INSTALLDIR.'/scripts/commandline.inc';
39
40 if (have_option('i', 'id')) {
41     $id = get_option_value('i', 'id');
42     $user = User::getKV('id', $id);
43     if (empty($user)) {
44         print "Can't find user with ID $id\n";
45         exit(1);
46     }
47 } else if (have_option('n', 'nickname')) {
48     $nickname = get_option_value('n', 'nickname');
49     $user = User::getKV('nickname', $nickname);
50     if (empty($user)) {
51         print "Can't find user with nickname '$nickname'\n";
52         exit(1);
53     }
54 } else if (have_option('all')) {
55     $user = new User();
56     $user->whereAdd("jabber != ''");
57     $user->find(true);
58     if ($user->N == 0) {
59         print "No users with registered Jabber addresses in database.\n";
60         exit(1);
61     }
62 } else {
63     print "You must provide either an ID or a nickname.\n";
64     print "\n";
65     print $helptext;
66     exit(1);
67 }
68
69 function clear_jabber($id)
70 {
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')) {
75             echo " (SKIPPING)";
76         } else {
77             $original = clone($user);
78             $user->jabber = null;
79             try {
80                 $user->updateWithKeys($original);
81             } catch (Exception $e) {
82                 echo "WARNING: user update failed (setting jabber to null): ".$e->getMessage()."\n";
83             }
84         }
85         echo "\n";
86     } else if (!$user) {
87         echo "Missing user for $id\n";
88     } else {
89         echo "Cleared jabber already for $id\n";
90     }
91 }
92
93 do {
94     clear_jabber($user->id);
95 } while ($user->fetch());
96
97 print "DONE.\n";