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