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');
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
37 require_once INSTALLDIR.'/scripts/commandline.inc';
39 if (have_option('i', 'id')) {
40 $id = get_option_value('i', 'id');
41 $profile = Profile::staticGet('id', $id);
42 if (empty($profile)) {
43 print "Can't find local or remote profile with ID $id\n";
46 } else if (have_option('n', 'nickname')) {
47 $nickname = get_option_value('n', 'nickname');
48 $user = User::staticGet('nickname', $nickname);
50 print "Can't find local user with nickname '$nickname'\n";
53 $profile = $user->getProfile();
55 print "You must provide either an ID or a nickname.\n\n";
60 if (!have_option('y', 'yes') && !have_option('--dry-run')) {
61 print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] ";
62 $response = fgets(STDIN);
63 if (strtolower(trim($response)) != 'y') {
69 // @fixme for a very prolific poster this could be too many.
70 print "Finding notices with geolocation data...";
71 $notice = new Notice();
72 $notice->profile_id = $profile->id;
73 $notice->whereAdd("lat != ''");
77 print " $notice->N found.\n";
78 while ($notice->fetch()) {
79 print "notice id $notice->id ";
80 if (have_option('v') || have_option('--verbose')) {
81 print "({$notice->lat},{$notice->lon}) ";
82 if ($notice->location_ns) {
83 print "ns {$notice->location_ns} id {$notice->location_id} ";
86 if (have_option('--dry-run')) {
90 // note: setting fields to null and calling update() doesn't save the nulled fields
91 $orig = clone($notice);
92 $update = clone($notice);
94 // In theory we could hit a chunk of notices at once in the UPDATE,
95 // but we're going to have to decache them individually anyway and
96 // it doesn't hurt to make sure we don't hold up replication with
97 // what might be a very slow single UPDATE.
98 $query = sprintf('UPDATE notice ' .
99 'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' .
100 'WHERE id=%d', $notice->id);
101 $ok = $update->query($query);
103 // And now we decache him manually, as query() doesn't know what we're doing...
113 print " none found.\n";