From 9e64ae59ba4a7888fa1643f02448a68109de6317 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 7 Sep 2011 16:14:21 -0400 Subject: [PATCH] move fixup group uri code to upgrade.php --- scripts/fixup_group_uri.php | 102 ------------------------------------ scripts/upgrade.php | 19 +++++++ 2 files changed, 19 insertions(+), 102 deletions(-) delete mode 100644 scripts/fixup_group_uri.php diff --git a/scripts/fixup_group_uri.php b/scripts/fixup_group_uri.php deleted file mode 100644 index 90938dac3e..0000000000 --- a/scripts/fixup_group_uri.php +++ /dev/null @@ -1,102 +0,0 @@ -#!/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"; - } -} diff --git a/scripts/upgrade.php b/scripts/upgrade.php index ab1d29e417..6878d0e52d 100755 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -40,6 +40,7 @@ function main() fixupNoticeRendered(); fixupNoticeConversation(); + fixupGroupURI(); } function tableDefs() @@ -134,4 +135,22 @@ function fixupNoticeConversation() printfnq("DONE.\n"); } +function fixupGroupURI() +{ + printfnq("Ensuring all groups have an URI..."); + + $group = new User_group(); + $group->whereAdd('uri IS NULL'); + + if ($group->find()) { + while ($group->fetch()) { + $orig = User_group::staticGet('id', $group->id); + $group->uri = $group->getUri(); + $group->update($orig); + } + } + + printfnq("DONE.\n"); +} + main(); -- 2.39.5