123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- $shortoptions = 'i::n::y';
- $longoptions = array('id=', 'nickname=', 'yes', 'dry-run', 'all');
- $helptext = <<<END_OF_HELP
- strip_geo.php [options]
- Removes geolocation info from the given user's notices.
- -i --id ID of the user (may be a remote profile)
- -n --nickname nickname of the user
- -y --yes do not wait for confirmation
- --dry-run list affected notices without deleting
- --all run over and decache all messages, even if they don't
- have geo data now (helps to fix cache bugs)
- END_OF_HELP;
- require_once INSTALLDIR.'/scripts/commandline.inc';
- if (have_option('i', 'id')) {
- $id = get_option_value('i', 'id');
- $profile = Profile::getKV('id', $id);
- if (empty($profile)) {
- print "Can't find local or remote profile with ID $id\n";
- exit(1);
- }
- } else if (have_option('n', 'nickname')) {
- $nickname = get_option_value('n', 'nickname');
- $user = User::getKV('nickname', $nickname);
- if (empty($user)) {
- print "Can't find local user with nickname '$nickname'\n";
- exit(1);
- }
- $profile = $user->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);
- }
- }
- $notice = new Notice();
- $notice->profile_id = $profile->id;
- 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) {
- 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')) {
-
- echo "(skipped)";
- } else {
-
- $orig = clone($notice);
- $update = clone($notice);
-
-
-
-
- $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) {
-
- $orig->decache();
- echo "(removed)";
- } else {
- echo "(unchanged?)";
- }
- }
- print "\n";
- }
- } else {
- print " none found.\n";
- }
- print "DONE.\n";
|