From 05e373d29b91cf929d0ac2ad74a90dce264df022 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 8 Apr 2010 17:05:02 -0700 Subject: scripts/strip_geo.php to remove geodata from notices by a given user/profile. May be slow or run out of memory if run on particularly prolific posters -- not yet optimized for that case. Note that geodata that has already been sent out to other services (via ostatus, omb, twitter, etc) will not be removed from them. (fixed version -- previous had accidentally undone another commit) --- scripts/strip_geo.php | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 scripts/strip_geo.php (limited to 'scripts/strip_geo.php') diff --git a/scripts/strip_geo.php b/scripts/strip_geo.php new file mode 100755 index 000000000..010fb31f5 --- /dev/null +++ b/scripts/strip_geo.php @@ -0,0 +1,116 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i::n::y'; +$longoptions = array('id=', 'nickname=', 'yes', 'dry-run'); + +$helptext = <<getProfile(); +} else { + print "You must provide either an ID or a nickname.\n\n"; + show_help(); + exit(1); +} + +if (!have_option('y', 'yes') && !have_option('--dry-run')) { + print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] "; + $response = fgets(STDIN); + if (strtolower(trim($response)) != 'y') { + print "Aborting.\n"; + exit(0); + } +} + +// @fixme for a very prolific poster this could be too many. +print "Finding notices with geolocation data..."; +$notice = new Notice(); +$notice->profile_id = $profile->id; +$notice->whereAdd("lat != ''"); +$notice->find(); + +if ($notice->N) { + print " $notice->N found.\n"; + while ($notice->fetch()) { + print "notice id $notice->id "; + if (have_option('v') || have_option('--verbose')) { + print "({$notice->lat},{$notice->lon}) "; + if ($notice->location_ns) { + print "ns {$notice->location_ns} id {$notice->location_id} "; + } + } + if (have_option('--dry-run')) { + // sucka + echo "(skipped)"; + } else { + // note: setting fields to null and calling update() doesn't save the nulled fields + $orig = clone($notice); + $update = clone($notice); + + // In theory we could hit a chunk of notices at once in the UPDATE, + // but we're going to have to decache them individually anyway and + // it doesn't hurt to make sure we don't hold up replication with + // what might be a very slow single UPDATE. + $query = sprintf('UPDATE notice ' . + 'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' . + 'WHERE id=%d', $notice->id); + $ok = $update->query($query); + if ($ok) { + // And now we decache him manually, as query() doesn't know what we're doing... + $orig->blow(); + echo "(removed)"; + } else { + echo "(failed?)"; + } + } + print "\n"; + } +} else { + print " none found.\n"; +} + +print "DONE.\n"; -- cgit v1.2.3-54-g00ecf From b47fc9c0bcd9f37438d2aaeb7b5bc98183b554ea Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 9 Apr 2010 11:36:02 -0700 Subject: Fix for strip_geo's decaching; also added --all option to run over all notices by given profile to help in fixing up cache inconsistencies --- scripts/strip_geo.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'scripts/strip_geo.php') diff --git a/scripts/strip_geo.php b/scripts/strip_geo.php index 010fb31f5..b3f27be61 100755 --- a/scripts/strip_geo.php +++ b/scripts/strip_geo.php @@ -21,7 +21,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'i::n::y'; -$longoptions = array('id=', 'nickname=', 'yes', 'dry-run'); +$longoptions = array('id=', 'nickname=', 'yes', 'dry-run', 'all'); $helptext = <<profile_id = $profile->id; -$notice->whereAdd("lat != ''"); +if (have_option('--all')) { + print "Finding all notices by $profile->nickname..."; +} else { + print "Finding notices by $profile->nickname with geolocation data..."; + $notice->whereAdd("lat != ''"); +} $notice->find(); if ($notice->N) { @@ -101,10 +107,10 @@ if ($notice->N) { $ok = $update->query($query); if ($ok) { // And now we decache him manually, as query() doesn't know what we're doing... - $orig->blow(); + $orig->decache(); echo "(removed)"; } else { - echo "(failed?)"; + echo "(unchanged?)"; } } print "\n"; -- cgit v1.2.3-54-g00ecf