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');
25 $helptext = <<<END_OF_USERROLE_HELP
26 fixup_shadow.php [options]
27 Patches up stray ostatus_profile entries with corrupted shadow entries
28 for local users and groups.
30 --dry-run look but don't touch
34 require_once INSTALLDIR.'/scripts/commandline.inc';
36 $dry = have_option('dry-run');
38 $oprofile = new Ostatus_profile();
40 $marker = mt_rand(31337, 31337000);
42 $profileTemplate = common_local_url('userbyid', array('id' => $marker));
43 $encProfile = $oprofile->escape($profileTemplate, true);
44 $encProfile = str_replace($marker, '%', $encProfile);
46 $groupTemplate = common_local_url('groupbyid', array('id' => $marker));
47 $encGroup = $oprofile->escape($groupTemplate, true);
48 $encGroup = str_replace($marker, '%', $encGroup);
50 $sql = "SELECT * FROM ostatus_profile WHERE uri LIKE '%s' OR uri LIKE '%s'";
51 $oprofile->query(sprintf($sql, $encProfile, $encGroup));
53 $count = $oprofile->N;
54 echo "Found $count bogus ostatus_profile entries shadowing local users and groups:\n";
56 while ($oprofile->fetch()) {
57 $uri = $oprofile->uri;
58 if (preg_match('!/group/(\d+)/id!', $oprofile->uri, $matches)) {
59 $id = intval($matches[1]);
60 $group = Local_group::staticGet('group_id', $id);
62 $nick = $group->nickname;
66 echo "group $id ($nick) hidden by $uri";
67 } else if (preg_match('!/user/(\d+)!', $uri, $matches)) {
68 $id = intval($matches[1]);
69 $user = User::staticGet('id', $id);
71 $nick = $user->nickname;
75 echo "user $id ($nick) hidden by $uri";
77 echo "$uri matched query, but we don't recognize it.\n";
84 echo " - removing bogus ostatus_profile entry...";
85 $evil = clone($oprofile);
92 echo "NO CHANGES MADE -- To delete the bogus entries, run again without --dry-run option.\n";