#!/usr/bin/env php . */ // Abort if called from a web server if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { print "This script must be run from the command line\n"; exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); require_once(INSTALLDIR . '/scripts/commandline.inc.php'); error_reporting(E_ALL | E_STRICT); $relative = common_path('group/'); print('Searching for profiles with relative=' . $relative . ' ...' . PHP_EOL); $profile = new Profile(); $profile->whereAdd("`profileurl` LIKE '" . $relative . "%'"); $cnt = $profile->find(); print('Found ' . $cnt . ' profiles.' . PHP_EOL); if ($cnt == 0) { // Nothing to do print('All profiles are fixed. :-)' . PHP_EOL); exit; } $profiles = array(); while ($profile->fetch()) { array_push($profiles, "'" . $profile->nickname . "'"); } // Cleanup unset($profile); print('Have ' . count($profiles) . ' profiles found.' . PHP_EOL); // Make sure both are equal assert(count($profiles) == $cnt); print('Looking for matching user groups without local groups ...' . PHP_EOL); $group = new User_group(); $group->whereAdd("`nickname` IN (" . implode(', ', $profiles) . ") AND `uri` NOT LIKE '" . $relative . "%'"); $cnt = $group->find(); print('Found ' . $cnt . ' groups.' . PHP_EOL); while ($group->fetch()) { print('Fixing profile for group #' . $group->id . ',nickname=' . $group->nickname . ' to ' . $group->uri . ' ...' . PHP_EOL); if ($group->profile_id < 1) { print('INCONSISTENCY - Group ' . $group->nickname . ' has no profile_id set. Cannot fix!' . PHP_EOL); } $profile = new Profile(); $profile->id = $group->profile_id; $cnt2 = $profile->find(); if ($cnt2 == 0) { print('INCONSISTENCY - Cannot find profile ' . $group->nickname . ' - skipped!' . PHP_EOL); continue; } elseif ($cnt2 > 1) { print('INCONSISTENCY - Group ' . $group->nickname . ' has more than one (' . $cnt2 . ') profiles - skipped!' . PHP_EOL); continue; } else { // Dummy fetch $profile->fetch(); } $original = clone($profile); $profile->profileurl = $group->uri; $result = $profile->update($original); if (!$result) { common_log_db_error($profile, 'UPDATE', __FILE__); } }