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 echo "Found $oprofile->N bogus ostatus_profile entries:\n";
55 while ($oprofile->fetch()) {
56 echo "$oprofile->uri";
59 echo " (unchanged)\n";
62 $evil = clone($oprofile);