4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, 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 // Abort if called from a web server
22 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
23 print "This script must be run from the command line\n";
27 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
29 require_once(INSTALLDIR . '/scripts/commandline.inc.php');
30 error_reporting(E_ALL | E_STRICT);
32 $relative = common_path('group/');
33 print('Searching for profiles with relative=' . $relative . ' ...' . PHP_EOL);
35 $profile = new Profile();
36 $profile->whereAdd("`profileurl` LIKE '" . $relative . "%'");
37 $cnt = $profile->find();
39 print('Found ' . $cnt . ' profiles.' . PHP_EOL);
43 print('All profiles are fixed. :-)' . PHP_EOL);
49 while ($profile->fetch()) {
50 array_push($profiles, "'" . $profile->nickname . "'");
56 print('Have ' . count($profiles) . ' profiles found.' . PHP_EOL);
58 // Make sure both are equal
59 assert(count($profiles) == $cnt);
61 print('Looking for matching user groups without local groups ...' . PHP_EOL);
63 $group = new User_group();
64 $group->whereAdd("`nickname` IN (" . implode(', ', $profiles) . ") AND `uri` NOT LIKE '" . $relative . "%'");
65 $cnt = $group->find();
67 print('Found ' . $cnt . ' groups.' . PHP_EOL);
69 while ($group->fetch()) {
70 print('Fixing profile for group #' . $group->id . ',nickname=' . $group->nickname . ' to ' . $group->uri . ' ...' . PHP_EOL);
72 if ($group->profile_id < 1) {
73 print('INCONSISTENCY - Group ' . $group->nickname . ' has no profile_id set. Cannot fix!' . PHP_EOL);
76 $profile = new Profile();
77 $profile->id = $group->profile_id;
78 $cnt2 = $profile->find();
81 print('INCONSISTENCY - Cannot find profile ' . $group->nickname . ' - skipped!' . PHP_EOL);
83 } elseif ($cnt2 > 1) {
84 print('INCONSISTENCY - Group ' . $group->nickname . ' has more than one (' . $cnt2 . ') profiles - skipped!' . PHP_EOL);
91 $original = clone($profile);
92 $profile->profileurl = $group->uri;
94 $result = $profile->update($original);
96 common_log_db_error($profile, 'UPDATE', __FILE__);