4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 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 $longoptions = array('dry-run', 'start=', 'end=');
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.
30 --dry-run look but don't touch
34 require_once INSTALLDIR.'/scripts/commandline.inc';
37 * Fetch subscriptions that should be disallowed by a block
39 function get_blocked_subs()
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);
52 $dry = have_option('dry-run');
53 $sub = get_blocked_subs();
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";
62 print "$subber->nickname ($subber->id) blocked but subbed to $subbed->nickname ($subbed->id)";
64 print ": skipping; dry run\n";
66 Subscription::cancel($subber, $subbed);
72 if ($dry && $count > 0) {
73 print "Be sure to run without --dry-run to remove the bad entries!\n";