[Bps-public-commit] r12996 - RT-Extension-MergeUsers/bin
ruz at bestpractical.com
ruz at bestpractical.com
Fri Jun 6 16:42:23 EDT 2008
Author: ruz
Date: Fri Jun 6 16:42:22 2008
New Revision: 12996
Added:
RT-Extension-MergeUsers/bin/
RT-Extension-MergeUsers/bin/rt-merge-users (contents, props changed)
Log:
* add simple rt-merge-users utility
Added: RT-Extension-MergeUsers/bin/rt-merge-users
==============================================================================
--- (empty file)
+++ RT-Extension-MergeUsers/bin/rt-merge-users Fri Jun 6 16:42:22 2008
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $usage = "usage: perl -I/opt/rt3/local/lib -I/opt/rt3/lib $0 <user> <into>";
+
+my ($from, $into) = @ARGV;
+die "\n$usage\n" unless $from && $into;
+
+eval { require RT } or die "$@\n\n$usage\n";
+RT::LoadConfig();
+RT::Init();
+
+my $merge = RT::User->new( $RT::SystemUser );
+$merge->Load( $from );
+die "Couldn't load user using '$from'" unless $merge->id;
+
+my $user = RT::User->new( $RT::SystemUser );
+$user->Load( $into );
+die "Couldn't load user using '$into'" unless $user->id;
+
+print "Going to merge user #". $merge->id ." into user #". $user->id ."\n";
+exit 0 unless prompt_yN("Are you sure you want to do that?");
+
+my ($status, $msg) = $merge->MergeInto( $user );
+die "Couldn't merge users: $msg" unless $status;
+
+print "DONE.\n";
+exit 0;
+
+sub prompt_yN {
+ my $msg = shift;
+ print $msg ." [N]: ";
+ my $a = <STDIN>;
+ return 1 if $a =~ /^(y|yes)$/i;
+ return 0;
+}
More information about the Bps-public-commit
mailing list