| 1 |
#!/usr/bin/env php |
| 2 |
<?php |
| 3 |
/* |
| 4 |
* StatusNet - a distributed open-source microblogging tool |
| 5 |
* Copyright (C) 2010 StatusNet, Inc. |
| 6 |
* |
| 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. |
| 11 |
* |
| 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. |
| 16 |
* |
| 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/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); |
| 22 |
|
| 23 |
$longoptions = array('dry-run', 'start=', 'end='); |
| 24 |
|
| 25 |
$helptext = <<<END_OF_HELP |
| 26 |
fixup_blocks.php [options] |
| 27 |
Finds profile blocks where the unsubscription didn't complete, |
| 28 |
and removes the offending subscriptions. |
| 29 |
|
| 30 |
--dry-run look but don't touch |
| 31 |
|
| 32 |
END_OF_HELP; |
| 33 |
|
| 34 |
require_once INSTALLDIR.'/scripts/commandline.inc'; |
| 35 |
|
| 36 |
/** |
| 37 |
* Fetch subscriptions that should be disallowed by a block |
| 38 |
*/ |
| 39 |
function get_blocked_subs() |
| 40 |
{ |
| 41 |
$query = "SELECT subscription.* " . |
| 42 |
"FROM subscription " . |
| 43 |
"INNER JOIN profile_block " . |
| 44 |
"ON blocker=subscribed " . |
| 45 |
"AND blocked=subscriber"; |
| 46 |
$subscription = new Subscription(); |
| 47 |
$subscription->query($query); |
| 48 |
return $subscription; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
$dry = have_option('dry-run'); |
| 53 |
$sub = get_blocked_subs(); |
| 54 |
$count = $sub->N; |
| 55 |
while ($sub->fetch()) { |
| 56 |
$subber = Profile::staticGet('id', $sub->subscriber); |
| 57 |
$subbed = Profile::staticGet('id', $sub->subscribed); |
| 58 |
if (!$subber || !$subbed) { |
| 59 |
print "Bogus entry! $sub->subscriber subbed to $sub->subscribed\n"; |
| 60 |
continue; |
| 61 |
} |
| 62 |
print "$subber->nickname ($subber->id) blocked but subbed to $subbed->nickname ($subbed->id)"; |
| 63 |
if ($dry) { |
| 64 |
print ": skipping; dry run\n"; |
| 65 |
} else { |
| 66 |
Subscription::cancel($subber, $subbed); |
| 67 |
print ": removed\n"; |
| 68 |
} |
| 69 |
} |
| 70 |
print "\n"; |
| 71 |
|
| 72 |
if ($dry && $count > 0) { |
| 73 |
print "Be sure to run without --dry-run to remove the bad entries!\n"; |
| 74 |
} else { |
| 75 |
print "done.\n"; |
| 76 |
} |