4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 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', 'dry-run', 'all');
27 $helptext = <<<END_OF_HELP
28 strip_geo.php [options]
29 Removes geolocation info from the given user's notices.
31 -i --id ID of the user (may be a remote profile)
32 -n --nickname nickname of the user
33 -y --yes do not wait for confirmation
34 --dry-run list affected notices without deleting
35 --all run over and decache all messages, even if they don't
36 have geo data now (helps to fix cache bugs)
40 require_once INSTALLDIR.'/scripts/commandline.inc';
42 if (have_option('i', 'id')) {
43 $id = get_option_value('i', 'id');
44 $profile = Profile::getKV('id', $id);
45 if (empty($profile)) {
46 print "Can't find local or remote profile with ID $id\n";
49 } else if (have_option('n', 'nickname')) {
50 $nickname = get_option_value('n', 'nickname');
51 $user = User::getKV('nickname', $nickname);
53 print "Can't find local user with nickname '$nickname'\n";
56 $profile = $user->getProfile();
58 print "You must provide either an ID or a nickname.\n\n";
63 if (!have_option('y', 'yes') && !have_option('--dry-run')) {
64 print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] ";
65 $response = fgets(STDIN);
66 if (strtolower(trim($response)) != 'y') {
72 // @fixme for a very prolific poster this could be too many.
73 $notice = new Notice();
74 $notice->profile_id = $profile->id;
75 if (have_option('--all')) {
76 print "Finding all notices by $profile->nickname...";
78 print "Finding notices by $profile->nickname with geolocation data...";
79 $notice->whereAdd("lat != ''");
84 print " $notice->N found.\n";
85 while ($notice->fetch()) {
86 print "notice id $notice->id ";
87 if (have_option('v') || have_option('--verbose')) {
88 print "({$notice->lat},{$notice->lon}) ";
89 if ($notice->location_ns) {
90 print "ns {$notice->location_ns} id {$notice->location_id} ";
93 if (have_option('--dry-run')) {
97 // note: setting fields to null and calling update() doesn't save the nulled fields
98 $orig = clone($notice);
99 $update = clone($notice);
101 // In theory we could hit a chunk of notices at once in the UPDATE,
102 // but we're going to have to decache them individually anyway and
103 // it doesn't hurt to make sure we don't hold up replication with
104 // what might be a very slow single UPDATE.
105 $query = sprintf('UPDATE notice ' .
106 'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' .
107 'WHERE id=%d', $notice->id);
108 $ok = $update->query($query);
110 // And now we decache him manually, as query() doesn't know what we're doing...
120 print " none found.\n";