From: Brion Vibber Date: Mon, 4 Oct 2010 22:13:27 +0000 (-0700) Subject: scripts/fixup_group_uri.php to fill in empty user_group.uri entries; needed before... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c6e8fbebefe7182b9584501d55bc0b32ce7b53a1;p=quix0rs-gnu-social.git scripts/fixup_group_uri.php to fill in empty user_group.uri entries; needed before changing domain names on sites that are hosting groups for remote users --- diff --git a/scripts/fixup_group_uri.php b/scripts/fixup_group_uri.php new file mode 100644 index 0000000000..90938dac3e --- /dev/null +++ b/scripts/fixup_group_uri.php @@ -0,0 +1,102 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i:n:a'; +$longoptions = array('id=', 'nickname=', 'all', 'dry-run'); + +$helptext = <<whereAdd('uri IS NULL'); + if ($group->find()) { + while ($group->fetch()) { + updateGroupUri($group); + } + } + } else { + show_help(); + exit(1); + } +} catch (Exception $e) { + print $e->getMessage()."\n"; + exit(1); +} + +function updateGroupUri($group) +{ + if (!have_option('q', 'quiet')) { + print "Updating URI for group '".$group->nickname."' (".$group->id.")..."; + } + + if (empty($group->uri)) { + // Using clone here was screwing up the group->find() iteration + $orig = User_group::staticGet('id', $group->id); + + $group->uri = $group->getUri(); + if (have_option('dry_run')) { + echo " would have set $group->uri "; + } else { + if (!$group->update($orig)) { + throw new Exception("Can't update uri for group " . $group->nickname . "."); + } + echo " set $group->uri "; + } + } else { + print " already set, keeping $group->uri "; + } + + if (have_option('v', 'verbose')) { + print "DONE."; + } + if (!have_option('q', 'quiet') || have_option('v', 'verbose')) { + print "\n"; + } +}