From 6d3c00d68835bdbe98b1f3996e5def3e7f4fed61 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 18 Jan 2015 07:07:00 +0100 Subject: [PATCH] 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 --- scripts/fixup_group_profiles.php | 98 ++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 scripts/fixup_group_profiles.php 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__); + } +} -- 2.39.5