From: Roland Haeder Date: Sun, 18 Jan 2015 06:07:00 +0000 (+0100) Subject: Added fixup script to fix bad profile URLs: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=43fde606e4b485c22518d3d3d45e432b00281354;p=quix0rs-gnu-social.git Added fixup script to fix bad profile URLs: https://social.mxchange.org/conversation/83342#notice-83342 "I have written a small fixup script that fixes invalid profile URLs: If the group is a remote group but #profileurl shows to https://your.instance.tld/group/groupname then the profileurl field must be fixed. cc !gnusocial I will commit it very soon." Signed-off-by: Roland Haeder --- diff --git a/scripts/fixup_group_profiles.php b/scripts/fixup_group_profiles.php new file mode 100755 index 0000000000..43cdfd0242 --- /dev/null +++ b/scripts/fixup_group_profiles.php @@ -0,0 +1,98 @@ +#!/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__); + } +}