[Rt-commit] r7145 - in rt/branches/3.7-EXPERIMENTAL-TUNIS: lib/RT

clkao at bestpractical.com clkao at bestpractical.com
Mon Mar 5 08:26:09 EST 2007


Author: clkao
Date: Mon Mar  5 08:26:08 2007
New Revision: 7145

Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm
   rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in

Log:
Move all interesting logic into RT::Handle that can be reused by tests.

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm	Mon Mar  5 08:26:08 2007
@@ -167,6 +167,48 @@
     }
 }
 
+=head2 drop_db
+
+=cut
+
+sub drop_db {
+    my $self = shift;
+    my $dbh  = shift || $self->dbh;
+    my %args = %{ shift || {}};
+    my $db_type = RT->Config->Get('DatabaseType');
+    my $db_name = RT->Config->Get('DatabaseName');
+    my $db_host = RT->Config->Get('DatabaseHost');
+    if ( $db_type eq 'Oracle' ) {
+        print <<END;
+
+To delete the tables and sequences of the RT Oracle database by running
+    \@etc/drop.Oracle
+through SQLPlus.
+
+END
+        return;
+    }
+    unless ( $args{'force'} ) {
+        print <<END;
+
+About to drop $db_type database $db_name on $db_host.
+WARNING: This will erase all data in $db_name.
+
+END
+        exit unless _yesno();
+
+    }
+
+    print "Dropping ". $db_type ." database ". $db_name .".\n";
+
+    if ( $db_type eq 'SQLite' ) {
+        unlink $RT::VarPath.'/'.$db_name or warn $!;
+        return;
+    }
+    $dbh->do("DROP DATABASE ". $db_name) or warn $DBI::errstr;
+}
+
+
 =head2 insert_acl
 
 =cut
@@ -292,6 +334,364 @@
 }
 
 
+=head2 insert_initial_data
+
+=cut
+
+sub insert_initial_data {
+    my $self    = shift;
+    my $db_type = RT->Config->Get('DatabaseType');
+    RT::InitLogging();
+
+    # connect to the db, for actual RT work
+    $RT::Handle = RT::Handle->new;
+    $RT::Handle->BuildDSN;
+    $RT::Handle->Connect;
+
+    #Put together a current user object so we can create a User object
+    my $CurrentUser = new RT::CurrentUser();
+
+    print "Checking for existing system user...";
+    my $test_user = RT::User->new($CurrentUser);
+    $test_user->Load('RT_System');
+    if ( $test_user->id ) {
+        print "found!\n\nYou appear to have a functional RT database.\n"
+          . "Exiting, so as not to clobber your existing data.\n";
+        exit(-1);
+
+    }
+    else {
+        print "not found.  This appears to be a new installation.\n";
+    }
+
+    print "Creating system user...";
+    my $RT_System = RT::User->new($CurrentUser);
+
+    my ( $val, $msg ) = $RT_System->_BootstrapCreate(
+        Name     => 'RT_System',
+        RealName => 'The RT System itself',
+        Comments => 'Do not delete or modify this user. '
+            . 'It is integral to RT\'s internal database structures',
+        Creator  => '1',
+        LastUpdatedBy => '1',
+    );
+
+    unless ( $val ) {
+        print "$msg\n";
+        exit(-1);
+    }
+    print "done.\n";
+    $RT::Handle->Disconnect() unless $db_type eq 'SQLite';
+}
+
+=head insert_data
+
+=cut
+
+# load some sort of data into the database
+sub insert_data {
+    my $self     = shift;
+    my $datafile = shift;
+
+    #Connect to the database and get RT::SystemUser and RT::Nobody loaded
+    RT::Init;
+
+    my $CurrentUser = RT::CurrentUser->new();
+    $CurrentUser->LoadByName('RT_System');
+
+    if ( $datafile eq $RT::EtcPath . "/initialdata" ) {
+
+        print "Creating Superuser  ACL...";
+
+        my $superuser_ace = RT::ACE->new($CurrentUser);
+        $superuser_ace->_BootstrapCreate(
+                             PrincipalId => ACLEquivGroupId( $CurrentUser->Id ),
+                             PrincipalType => 'Group',
+                             RightName     => 'SuperUser',
+                             ObjectType    => 'RT::System',
+                             ObjectId      => '1' );
+
+        print "done.\n";
+    }
+
+    # Slurp in stuff to insert from the datafile. Possible things to go in here:-
+    our (@Groups, @Users, @ACL, @Queues, @ScripActions, @ScripConditions,
+	   @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);
+    local (@Groups, @Users, @ACL, @Queues, @ScripActions, @ScripConditions,
+	   @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);
+
+    require $datafile
+      || die "Couldn't find initial data for import\n" . $@;
+
+    if ( @Initial ) {
+        print "Running initial actions...\n";
+        # Don't trap errors here, as they *should* be fatal
+        $_->() for @Initial;
+    }
+    if ( @Groups ) {
+        print "Creating groups...";
+        foreach my $item (@Groups) {
+            my $new_entry = RT::Group->new($CurrentUser);
+            my $member_of = delete $item->{'MemberOf'};
+            my ( $return, $msg ) = $new_entry->_Create(%$item);
+            print "(Error: $msg)" unless $return;
+            print $return. ".";
+            if ( $member_of ) {
+                $member_of = [ $member_of ] unless ref $member_of eq 'ARRAY';
+                foreach( @$member_of ) {
+                    my $parent = RT::Group->new($CurrentUser);
+                    if ( ref $_ eq 'HASH' ) {
+                        $parent->LoadByCols( %$_ );
+                    }
+                    elsif ( !ref $_ ) {
+                        $parent->LoadUserDefinedGroup( $_ );
+                    }
+                    else {
+                        print "(Error: wrong format of MemberOf field."
+                            ." Should be name of user defined group or"
+                            ." hash reference with 'column => value' pairs."
+                            ." Use array reference to add to multiple groups)";
+                        next;
+                    }
+                    unless ( $parent->Id ) {
+                        print "(Error: couldn't load group to add member)";
+                        next;
+                    }
+                    my ( $return, $msg ) = $parent->AddMember( $new_entry->Id );
+                    print "(Error: $msg)" unless ($return);
+                    print $return. ".";
+                }
+            }
+        }
+        print "done.\n";
+    }
+    if ( @Users ) {
+        print "Creating users...";
+        foreach my $item (@Users) {
+            my $new_entry = new RT::User($CurrentUser);
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            print "(Error: $msg)" unless $return;
+            print $return. ".";
+        }
+        print "done.\n";
+    }
+    if ( @Queues ) {
+        print "Creating queues...";
+        for my $item (@Queues) {
+            my $new_entry = new RT::Queue($CurrentUser);
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            print "(Error: $msg)" unless $return;
+            print $return. ".";
+        }
+        print "done.\n";
+    }
+    if ( @CustomFields ) {
+        print "Creating custom fields...";
+        for my $item ( @CustomFields ) {
+            my $new_entry = new RT::CustomField( $CurrentUser );
+            my $values    = delete $item->{'Values'};
+
+            my @queues;
+            if ( $item->{'Queue'} ) {
+                my $queue_ref = delete $item->{'Queue'};
+                @queues = ref $queue_ref ? @{$queue_ref} : ($queue_ref);
+                $item->{'LookupType'} = 'RT::Queue-RT::Ticket';
+            }
+
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            print "(Error: $msg)\n" and next unless $return;
+
+            foreach my $value ( @{$values} ) {
+                ( $return, $msg ) = $new_entry->AddValue(%$value);
+                print "(Error: $msg)\n" unless $return;
+            }
+
+            if ($item->{LookupType}) { # enable by default
+                my $ocf = RT::ObjectCustomField->new($CurrentUser);
+                $ocf->Create( CustomField => $new_entry->Id );
+            }
+       
+            for my $q (@queues) {
+                my $q_obj = RT::Queue->new($CurrentUser);
+                $q_obj->Load($q);
+                unless ( $q_obj->Id ) {
+                    print "(Error: Could not find queue " . $q . ")\n";
+                    next;
+                }
+                my $OCF = RT::ObjectCustomField->new($CurrentUser);
+                ( $return, $msg ) = $OCF->Create(
+                    CustomField => $new_entry->Id,
+                    ObjectId    => $q_obj->Id,
+                );
+                print "(Error: $msg)\n" unless $return and $OCF->Id;
+            }
+
+            print $new_entry->Id. ".";
+        }
+
+        print "done.\n";
+    }
+    if ( @ACL ) {
+        print "Creating ACL...";
+        for my $item (@ACL) {
+
+            my ($princ, $object);
+
+            # Global rights or Queue rights?
+            if ( $item->{'CF'} ) {
+                $object = RT::CustomField->new( $CurrentUser );
+                my @columns = ( Name => $item->{'CF'} );
+                push @columns, Queue => $item->{'Queue'} if $item->{'Queue'} and not ref $item->{'Queue'};
+                $object->LoadByName( @columns );
+            } elsif ( $item->{'Queue'} ) {
+                $object = RT::Queue->new($CurrentUser);
+                $object->Load( $item->{'Queue'} );
+            } else {
+                $object = $RT::System;
+            }
+
+            print "Couldn't load object" and next unless $object and $object->Id;
+
+            # Group rights or user rights?
+            if ( $item->{'GroupDomain'} ) {
+                $princ = RT::Group->new($CurrentUser);
+                if ( $item->{'GroupDomain'} eq 'UserDefined' ) {
+                  $princ->LoadUserDefinedGroup( $item->{'GroupId'} );
+                } elsif ( $item->{'GroupDomain'} eq 'SystemInternal' ) {
+                  $princ->LoadSystemInternalGroup( $item->{'GroupType'} );
+                } elsif ( $item->{'GroupDomain'} eq 'RT::System-Role' ) {
+                  $princ->LoadSystemRoleGroup( $item->{'GroupType'} );
+                } elsif ( $item->{'GroupDomain'} eq 'RT::Queue-Role' &&
+                          $item->{'Queue'} )
+                {
+                  $princ->LoadQueueRoleGroup( Type => $item->{'GroupType'},
+                                              Queue => $object->id);
+                } else {
+                  $princ->Load( $item->{'GroupId'} );
+                }
+            } else {
+                $princ = RT::User->new($CurrentUser);
+                $princ->Load( $item->{'UserId'} );
+            }
+
+            # Grant it
+            my ( $return, $msg ) = $princ->PrincipalObj->GrantRight(
+                                                     Right => $item->{'Right'},
+                                                     Object => $object );
+
+            if ( $return ) {
+                print $return. ".";
+            }
+            else {
+                print $msg . ".";
+
+            }
+
+        }
+        print "done.\n";
+    }
+
+    if ( @ScripActions ) {
+        print "Creating ScripActions...";
+
+        for my $item (@ScripActions) {
+            my $new_entry = RT::ScripAction->new($CurrentUser);
+            my $return    = $new_entry->Create(%$item);
+            print $return. ".";
+        }
+
+        print "done.\n";
+    }
+
+    if ( @ScripConditions ) {
+        print "Creating ScripConditions...";
+
+        for my $item (@ScripConditions) {
+            my $new_entry = RT::ScripCondition->new($CurrentUser);
+            my $return    = $new_entry->Create(%$item);
+            print $return. ".";
+        }
+
+        print "done.\n";
+    }
+
+    if ( @Templates ) {
+        print "Creating templates...";
+
+        for my $item (@Templates) {
+            my $new_entry = new RT::Template($CurrentUser);
+            my $return    = $new_entry->Create(%$item);
+            print $return. ".";
+        }
+        print "done.\n";
+    }
+    if ( @Scrips ) {
+        print "Creating scrips...";
+
+        for my $item (@Scrips) {
+            my $new_entry = new RT::Scrip($CurrentUser);
+
+            my @queues = ref $item->{'Queue'} eq 'ARRAY'? @{ $item->{'Queue'} }: $item->{'Queue'} || 0;
+            push @queues, 0 unless @queues; # add global queue at least
+
+            foreach my $q ( @queues ) {
+                my ( $return, $msg ) = $new_entry->Create( %$item, Queue => $q );
+            if ( $return ) {
+                    print $return. ".";
+                }
+                else {
+                    print "(Error: $msg)\n";
+                }
+            }
+        }
+        print "done.\n";
+    }
+    if ( @Attributes ) {
+        print "Creating predefined searches...";
+        my $sys = RT::System->new($CurrentUser);
+
+        for my $item (@Attributes) {
+            my $obj = delete $item->{Object}; # XXX: make this something loadable
+            $obj ||= $sys;
+            my ( $return, $msg ) = $obj->AddAttribute (%$item);
+            if ( $return ) {
+                print $return. ".";
+            }
+            else {
+                print "(Error: $msg)\n";
+            }
+        }
+        print "done.\n";
+    }
+    if ( @Final ) {
+        print "Running final actions...\n";
+        for ( @Final ) {
+            eval { $_->(); };
+            print "(Error: $@)\n" if $@;
+        }
+    }
+
+    my $db_type = RT->Config->Get('DatabaseType');
+    $RT::Handle->Disconnect() unless $db_type eq 'SQLite';
+    print "Done setting up database content.\n";
+}
+
+=head2 ACLEquivGroupId
+
+Given a userid, return that user's acl equivalence group
+
+=cut
+
+sub ACLEquivGroupId {
+    my $username = shift;
+    my $user     = RT::User->new($RT::SystemUser);
+    $user->Load($username);
+    my $equiv_group = RT::Group->new($RT::SystemUser);
+    $equiv_group->LoadACLEquivalenceGroup($user);
+    return ( $equiv_group->Id );
+}
+
+
 
 eval "require RT::Handle_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Handle_Vendor.pm});

Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in	Mon Mar  5 08:26:08 2007
@@ -1,4 +1,4 @@
-#!@PERL@ -w
+#!/usr/bin/perl -w
 # BEGIN BPS TAGGED BLOCK {{{
 #
 # COPYRIGHT:
@@ -46,8 +46,6 @@
 # END BPS TAGGED BLOCK }}}
 use strict;
 use vars qw($PROMPT $VERSION $Nobody $SystemUser $item);
-use vars qw(@Groups @Users @ACL @Queues @ScripActions @ScripConditions
-            @Templates @CustomFields @Scrips @Attributes @Initial @Final);
 
 use lib ("@LOCAL_LIB_PATH@", "@RT_LIB_PATH@");
 
@@ -126,22 +124,22 @@
     print "Now inserting database ACLs\n";
     $RT::Handle->insert_acl($dbh) unless $db_type eq 'Oracle';
     print "Now inserting RT core system objects\n";
-    insert_initial_data();
+    $RT::Handle->insert_initial_data();
     print "Now inserting RT data\n";
-    insert_data( $RT::EtcPath . "/initialdata" );
+    $RT::Handle->insert_data( $RT::EtcPath . "/initialdata" );
 }
 elsif ( $args{'action'} eq 'drop' ) {
     $dbh = get_system_dbh();
-    drop_db();
+    RT::Handle->drop_db($dbh, \%args);
 }
 elsif ( $args{'action'} eq 'insert' ) {
     $dbh = get_rt_dbh();
     check_db_compatibility();
-    insert_data( $args{'datafile'} || ($args{'datadir'}."/content") );
+    $RT::Handle->insert_data( $args{'datafile'} || ($args{'datadir'}."/content") );
 }
 elsif ( $args{'action'} eq 'acl' ) {
     $dbh = get_rt_dbh( $args{'dba'}, $args{'dba-password'} );
-    insert_acl($args{'datadir'});
+    $RT::Handle->insert_acl($dbh, $args{'datadir'});
 }
 elsif ( $args{'action'} eq 'schema' ) {
     $dbh = get_rt_dbh( $args{'dba'}, $args{'dba-password'} );
@@ -153,365 +151,6 @@
     exit(-1);
 }
 
-sub drop_db {
-    if ( $db_type eq 'Oracle' ) {
-        print <<END;
-
-To delete the tables and sequences of the RT Oracle database by running
-    \@etc/drop.Oracle
-through SQLPlus.
-
-END
-        return;
-    }
-    unless ( $args{'force'} ) {
-        print <<END;
-
-About to drop $db_type database $db_name on $db_host.
-WARNING: This will erase all data in $db_name.
-
-END
-        exit unless _yesno();
-
-    }
-
-    print "Dropping ". $db_type ." database ". $db_name .".\n";
-
-    if ( $db_type eq 'SQLite' ) {
-        unlink $RT::VarPath.'/'.$db_name or warn $!;
-        return;
-    }
-    $dbh->do("DROP DATABASE ". $db_name) or warn $DBI::errstr;
-}
-
-
-
-sub insert_initial_data {
-
-    RT::InitLogging();
-
-    #connect to the db, for actual RT work
-    connect_rt_handle();
-
-    #Put together a current user object so we can create a User object
-    my $CurrentUser = new RT::CurrentUser();
-
-    print "Checking for existing system user...";
-    my $test_user = RT::User->new($CurrentUser);
-    $test_user->Load('RT_System');
-    if ( $test_user->id ) {
-        print "found!\n\nYou appear to have a functional RT database.\n"
-          . "Exiting, so as not to clobber your existing data.\n";
-        exit(-1);
-
-    }
-    else {
-        print "not found.  This appears to be a new installation.\n";
-    }
-
-    print "Creating system user...";
-    my $RT_System = RT::User->new($CurrentUser);
-
-    my ( $val, $msg ) = $RT_System->_BootstrapCreate(
-        Name     => 'RT_System',
-        RealName => 'The RT System itself',
-        Comments => 'Do not delete or modify this user. '
-            . 'It is integral to RT\'s internal database structures',
-        Creator  => '1',
-        LastUpdatedBy => '1',
-    );
-
-    unless ( $val ) {
-        print "$msg\n";
-        exit(-1);
-    }
-    print "done.\n";
-    $RT::Handle->Disconnect() unless $db_type eq 'SQLite';
-}
-
-# load some sort of data into the database
-
-sub insert_data {
-    my $datafile = shift;
-
-    #Connect to the database and get RT::SystemUser and RT::Nobody loaded
-    RT::Init;
-
-    my $CurrentUser = RT::CurrentUser->new();
-    $CurrentUser->LoadByName('RT_System');
-
-    if ( $datafile eq $RT::EtcPath . "/initialdata" ) {
-
-        print "Creating Superuser  ACL...";
-
-        my $superuser_ace = RT::ACE->new($CurrentUser);
-        $superuser_ace->_BootstrapCreate(
-                             PrincipalId => ACLEquivGroupId( $CurrentUser->Id ),
-                             PrincipalType => 'Group',
-                             RightName     => 'SuperUser',
-                             ObjectType    => 'RT::System',
-                             ObjectId      => '1' );
-
-        print "done.\n";
-    }
-
-    # Slurp in stuff to insert from the datafile. Possible things to go in here:-
-    # @groups, @users, @acl, @queues, @ScripActions, @ScripConditions, @templates
-
-    require $datafile
-      || die "Couldn't find initial data for import\n" . $@;
-
-    if ( @Initial ) {
-        print "Running initial actions...\n";
-        # Don't trap errors here, as they *should* be fatal
-        $_->() for @Initial;
-    }
-    if ( @Groups ) {
-        print "Creating groups...";
-        foreach $item (@Groups) {
-            my $new_entry = RT::Group->new($CurrentUser);
-            my $member_of = delete $item->{'MemberOf'};
-            my ( $return, $msg ) = $new_entry->_Create(%$item);
-            print "(Error: $msg)" unless $return;
-            print $return. ".";
-            if ( $member_of ) {
-                $member_of = [ $member_of ] unless ref $member_of eq 'ARRAY';
-                foreach( @$member_of ) {
-                    my $parent = RT::Group->new($CurrentUser);
-                    if ( ref $_ eq 'HASH' ) {
-                        $parent->LoadByCols( %$_ );
-                    }
-                    elsif ( !ref $_ ) {
-                        $parent->LoadUserDefinedGroup( $_ );
-                    }
-                    else {
-                        print "(Error: wrong format of MemberOf field."
-                            ." Should be name of user defined group or"
-                            ." hash reference with 'column => value' pairs."
-                            ." Use array reference to add to multiple groups)";
-                        next;
-                    }
-                    unless ( $parent->Id ) {
-                        print "(Error: couldn't load group to add member)";
-                        next;
-                    }
-                    my ( $return, $msg ) = $parent->AddMember( $new_entry->Id );
-                    print "(Error: $msg)" unless ($return);
-                    print $return. ".";
-                }
-            }
-        }
-        print "done.\n";
-    }
-    if ( @Users ) {
-        print "Creating users...";
-        foreach $item (@Users) {
-            my $new_entry = new RT::User($CurrentUser);
-            my ( $return, $msg ) = $new_entry->Create(%$item);
-            print "(Error: $msg)" unless $return;
-            print $return. ".";
-        }
-        print "done.\n";
-    }
-    if ( @Queues ) {
-        print "Creating queues...";
-        for $item (@Queues) {
-            my $new_entry = new RT::Queue($CurrentUser);
-            my ( $return, $msg ) = $new_entry->Create(%$item);
-            print "(Error: $msg)" unless $return;
-            print $return. ".";
-        }
-        print "done.\n";
-    }
-    if ( @CustomFields ) {
-        print "Creating custom fields...";
-        for $item ( @CustomFields ) {
-            my $new_entry = new RT::CustomField( $CurrentUser );
-            my $values    = delete $item->{'Values'};
-
-            my @queues;
-            if ( $item->{'Queue'} ) {
-                my $queue_ref = delete $item->{'Queue'};
-                @queues = ref $queue_ref ? @{$queue_ref} : ($queue_ref);
-                $item->{'LookupType'} = 'RT::Queue-RT::Ticket';
-            }
-
-            my ( $return, $msg ) = $new_entry->Create(%$item);
-            print "(Error: $msg)\n" and next unless $return;
-
-            foreach my $value ( @{$values} ) {
-                ( $return, $msg ) = $new_entry->AddValue(%$value);
-                print "(Error: $msg)\n" unless $return;
-            }
-
-            if ($item->{LookupType}) { # enable by default
-                my $ocf = RT::ObjectCustomField->new($CurrentUser);
-                $ocf->Create( CustomField => $new_entry->Id );
-            }
-       
-            for my $q (@queues) {
-                my $q_obj = RT::Queue->new($CurrentUser);
-                $q_obj->Load($q);
-                unless ( $q_obj->Id ) {
-                    print "(Error: Could not find queue " . $q . ")\n";
-                    next;
-                }
-                my $OCF = RT::ObjectCustomField->new($CurrentUser);
-                ( $return, $msg ) = $OCF->Create(
-                    CustomField => $new_entry->Id,
-                    ObjectId    => $q_obj->Id,
-                );
-                print "(Error: $msg)\n" unless $return and $OCF->Id;
-            }
-
-            print $new_entry->Id. ".";
-        }
-
-        print "done.\n";
-    }
-    if ( @ACL ) {
-        print "Creating ACL...";
-        for my $item (@ACL) {
-
-            my ($princ, $object);
-
-            # Global rights or Queue rights?
-            if ( $item->{'CF'} ) {
-                $object = RT::CustomField->new( $CurrentUser );
-                my @columns = ( Name => $item->{'CF'} );
-                push @columns, Queue => $item->{'Queue'} if $item->{'Queue'} and not ref $item->{'Queue'};
-                $object->LoadByName( @columns );
-            } elsif ( $item->{'Queue'} ) {
-                $object = RT::Queue->new($CurrentUser);
-                $object->Load( $item->{'Queue'} );
-            } else {
-                $object = $RT::System;
-            }
-
-            print "Couldn't load object" and next unless $object and $object->Id;
-
-            # Group rights or user rights?
-            if ( $item->{'GroupDomain'} ) {
-                $princ = RT::Group->new($CurrentUser);
-                if ( $item->{'GroupDomain'} eq 'UserDefined' ) {
-                  $princ->LoadUserDefinedGroup( $item->{'GroupId'} );
-                } elsif ( $item->{'GroupDomain'} eq 'SystemInternal' ) {
-                  $princ->LoadSystemInternalGroup( $item->{'GroupType'} );
-                } elsif ( $item->{'GroupDomain'} eq 'RT::System-Role' ) {
-                  $princ->LoadSystemRoleGroup( $item->{'GroupType'} );
-                } elsif ( $item->{'GroupDomain'} eq 'RT::Queue-Role' &&
-                          $item->{'Queue'} )
-                {
-                  $princ->LoadQueueRoleGroup( Type => $item->{'GroupType'},
-                                              Queue => $object->id);
-                } else {
-                  $princ->Load( $item->{'GroupId'} );
-                }
-            } else {
-                $princ = RT::User->new($CurrentUser);
-                $princ->Load( $item->{'UserId'} );
-            }
-
-            # Grant it
-            my ( $return, $msg ) = $princ->PrincipalObj->GrantRight(
-                                                     Right => $item->{'Right'},
-                                                     Object => $object );
-
-            if ( $return ) {
-                print $return. ".";
-            }
-            else {
-                print $msg . ".";
-
-            }
-
-        }
-        print "done.\n";
-    }
-
-    if ( @ScripActions ) {
-        print "Creating ScripActions...";
-
-        for $item (@ScripActions) {
-            my $new_entry = RT::ScripAction->new($CurrentUser);
-            my $return    = $new_entry->Create(%$item);
-            print $return. ".";
-        }
-
-        print "done.\n";
-    }
-
-    if ( @ScripConditions ) {
-        print "Creating ScripConditions...";
-
-        for $item (@ScripConditions) {
-            my $new_entry = RT::ScripCondition->new($CurrentUser);
-            my $return    = $new_entry->Create(%$item);
-            print $return. ".";
-        }
-
-        print "done.\n";
-    }
-
-    if ( @Templates ) {
-        print "Creating templates...";
-
-        for $item (@Templates) {
-            my $new_entry = new RT::Template($CurrentUser);
-            my $return    = $new_entry->Create(%$item);
-            print $return. ".";
-        }
-        print "done.\n";
-    }
-    if ( @Scrips ) {
-        print "Creating scrips...";
-
-        for $item (@Scrips) {
-            my $new_entry = new RT::Scrip($CurrentUser);
-
-            my @queues = ref $item->{'Queue'} eq 'ARRAY'? @{ $item->{'Queue'} }: $item->{'Queue'} || 0;
-            push @queues, 0 unless @queues; # add global queue at least
-
-            foreach my $q ( @queues ) {
-                my ( $return, $msg ) = $new_entry->Create( %$item, Queue => $q );
-            if ( $return ) {
-                    print $return. ".";
-                }
-                else {
-                    print "(Error: $msg)\n";
-                }
-            }
-        }
-        print "done.\n";
-    }
-    if ( @Attributes ) {
-        print "Creating predefined searches...";
-        my $sys = RT::System->new($CurrentUser);
-
-        for $item (@Attributes) {
-            my $obj = delete $item->{Object}; # XXX: make this something loadable
-            $obj ||= $sys;
-            my ( $return, $msg ) = $obj->AddAttribute (%$item);
-            if ( $return ) {
-                print $return. ".";
-            }
-            else {
-                print "(Error: $msg)\n";
-            }
-        }
-        print "done.\n";
-    }
-    if ( @Final ) {
-        print "Running final actions...\n";
-        for ( @Final ) {
-            eval { $_->(); };
-            print "(Error: $@)\n" if $@;
-        }
-    }
-    $RT::Handle->Disconnect() unless $db_type eq 'SQLite';
-    print "Done setting up database content.\n";
-}
-
 sub check_db_compatibility {
     if ( lc $db_type eq "mysql" ) {
         # Check which version we're running
@@ -663,60 +302,6 @@
     return $dbh;
 }
 
-=head2 connect_rt_handle
-
-Returns connected C<RT::Handle> object. Connects with credentials
-from RT config.Alos, inits C<$RT::Handle> global variable.
-
-=cut
-
-sub connect_rt_handle {
-
-    require RT::Handle;
-
-    $RT::Handle = RT::Handle->new;
-    $RT::Handle->BuildDSN;
-    $RT::Handle->Connect;
-
-    return $RT::Handle;
-}
-
-=head2 get_rt_handle_as_dba
-
-Returns connected C<$RT::Handle> object. Uses DBA's credentials.
-
-=cut
-
-sub get_rt_handle_as_dba {
-    require RT::Handle;
-    RT->Config->Set( DatabaseUser => $args{'dba'} );
-    RT->Config->Set( DatabasePassword => $args{'dba-password'} );
-
-    my $rt_handle = RT::Handle->new;
-    $rt_handle->BuildDSN;
-    $rt_handle->Connect;
-
-    RT->Config->Set( DatabaseUser => $db_user );
-    RT->Config->Set( DatabasePassword => $db_pass );
-
-    return $rt_handle;
-}
-
-=head2 ACLEquivGroupId
-
-Given a userid, return that user's acl equivalence group
-
-=cut
-
-sub ACLEquivGroupId {
-    my $username = shift;
-    my $user     = RT::User->new($RT::SystemUser);
-    $user->Load($username);
-    my $equiv_group = RT::Group->new($RT::SystemUser);
-    $equiv_group->LoadACLEquivalenceGroup($user);
-    return ( $equiv_group->Id );
-}
-
 sub help {
 
     print <<EOF;


More information about the Rt-commit mailing list