[rt-devel] Failure report : RT 2.0.60 / Data migration

Jesse Vincent jesse at bestpractical.com
Tue Jan 21 22:51:51 EST 2003


> Looking into the original RT2 base, it appears the queue it belongs to is
> disabled. I checked in the RT3 database and it has not been imported.
> 
> I guess you should export and import disabled objects just in case there are
> some dependencies.

I concur. Attached is a new 2.0-export which should export disabled
objects. Thanks very much for being my guinea pig on this one.


> Its almost 3am in France, so I guess I'll try your next version tomorrow
> morning...

Hope you had a pleasant night's sleep.

> Blaise


	Jesse

-- 
»|« http://www.bestpractical.com/rt  -- Trouble Ticketing. Free.
-------------- next part --------------
#!/usr/bin/perl -w
# RT is (c) 1996-2001 Jesse Vincent <jesse at fsck.com>

use strict;
use Carp;
use Getopt::Long qw(:config pass_through);
use Data::Dumper;

use lib "/opt/fsck.com-rt2/lib";
use lib "/opt/fsck.com-rt2/etc";

use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
  GetCurrentUser GetMessageContent);
use RT::Groups;
use RT::Users;
use RT::Queues;
use RT::ACL;
use RT::Tickets;

#Clean out all the nasties from the environment
CleanEnv();

#Load etc/config.pm and drop privs
LoadConfig();

#Connect to the database and get RT::SystemUser and RT::Nobody loaded
DBConnect();

package RT::Faketix;


use RT::EasySearch;
use RT::Ticket;

use vars qw( @ISA );
@ISA= qw(RT::EasySearch);


sub _Init {
    my $self = shift;
    $self->{'table'} = 'Tickets';
    $self->{'primary_key'} = 'id';
    return ( $self->SUPER::_Init(@_) );
}


sub NewItem {
    RT::Ticket->new(shift->CurrentUser);
}



package main;

my $ds;

my $blank_Group = RT::Group->new($RT::SystemUser);
$blank_Group->_Accessible( 'Foo', 'read' );
my $acc = $blank_Group->{_AccessibleCache};

my $Groups = RT::Groups->new($RT::SystemUser);
$Groups->LimitToReal();
$Groups->{'find_disabled_rows'} = 1;
foreach my $Group ( @{ $Groups->ItemsArrayRef } ) {

        my $group;

    foreach my $param ( sort keys %$acc, 'id' ) {
        $group->{$param} = $Group->_Value($param)
          if ( $Group->_Value($param) );
    }
    my $members = $Group->MembersObj();
    foreach my $member ( @{ $members->ItemsArrayRef } ) {
        push @{ $group->{Member} }, $member->UserObj->Id;

    }
        push @{$ds->{'Group'}},$group;
}


my $blank_User = RT::User->new($RT::SystemUser);
$blank_User->_Accessible( 'Foo', 'read' );
$acc = $blank_User->{_AccessibleCache};

my $users = RT::Users->new($RT::SystemUser);
$users->UnLimit();
$users->{'find_disabled_rows'} = 1;

foreach my $user ( @{ $users->ItemsArrayRef } ) {
        my $user_ds;
    foreach my $param ( sort keys %$acc, 'id' ) {
        $user_ds->{$param} = $user->_Value($param)
          if ( $user->_Value($param) );
    }
    push (@{$ds->{'User'}},$user_ds);
}

my $blank_Queue = RT::Queue->new($RT::SystemUser);
$blank_Queue->_Accessible( 'Foo', 'read' );
$acc = $blank_Queue->{_AccessibleCache};

my $Queues = RT::Queues->new($RT::SystemUser);
$Queues->UnLimit();
$Queues->{'find_disabled_rows'} = 1;

foreach my $Queue ( @{ $Queues->ItemsArrayRef } ) {
        my $queue_ds;
    foreach my $param ( sort keys %$acc, 'id' ) {
        $queue_ds->{$param} = $Queue->_Value($param)
          if ( $Queue->_Value($param) );
    }
    my $watchers = $Queue->Watchers();
    my $watchers_ds;
    foreach my $w ( @{ $watchers->ItemsArrayRef } ) {
        my $ds = { Type => $w->Type,
                   Email => $w->Email,
                   Id => $w->Id };

        push (@{$watchers_ds}, $ds);
        }
        $queue_ds->{'Watchers'} = $watchers_ds;
    


    my $blank_KeywordSelect = RT::KeywordSelect->new($RT::SystemUser);
    $blank_KeywordSelect->_Accessible( 'Foo', 'read' );
    my $ksacc = $blank_KeywordSelect->{_AccessibleCache};

    my $ks = $Queue->KeywordSelects();
    $ks->{'find_disabled_rows'}= 1;
    foreach my $keysel ( @{ $ks->ItemsArrayRef } ) {
        my $ks_ds;
        foreach my $param ( sort keys %$ksacc, 'id' ) {
            $ks_ds->{$param} = $keysel->_Value($param) if ( $keysel->_Value($param) );
        }
        my $descendents = $keysel->KeywordObj->Descendents;
        foreach my $desc ( keys %{$descendents} ) {
            push @{ $ks_ds->{Value} }, $descendents->{$desc};

        }
        push (@{$queue_ds->{'CustomField'}}, $ks_ds);
    }

    my $ACL = RT::ACL->new($RT::SystemUser);
    $ACL->LimitToQueue( $Queue->Id );

    foreach my $ace ( @{ $ACL->ItemsArrayRef } ) {
        my $right_ds = { PrincipalType => $ace->PrincipalType,
                         PrincipalId => $ace->PrincipalObj->Id,
                         Name => $ace->RightName };
        if ($ace->PrincipalType eq 'Group' && $ace->PrincipalObj->Pseudo) {
                $right_ds->{'Role'} =  $ace->PrincipalObj->Name;
                delete $right_ds->{'PrincipalId'};
                }
        push ( @{ $queue_ds->{'Right'}}, $right_ds);
    }
	my $scrips = RT::Scrips->new($RT::SystemUser);
	$scrips->LimitToQueue($Queue->Id);
	foreach my $scrip (@{$scrips->ItemsArrayRef}) {
                my $scrip_ds = {
                Condition => $scrip->ConditionObj->Name(),
                Template => $scrip->TemplateObj->Name(),
                Action => $scrip->ActionObj->Name(),
                };
                push (@{$queue_ds->{'Scrip'}}, $scrip_ds);
	} 
        push (@{$ds->{'Queue'}}, $queue_ds);

}
my $blank_KeywordSelect = RT::KeywordSelect->new($RT::SystemUser);
$blank_KeywordSelect->_Accessible( 'Foo', 'read' );
my $global_ksacc = $blank_KeywordSelect->{_AccessibleCache};
my $global_ks    = RT::KeywordSelects->new($RT::SystemUser);
$global_ks->LimitToQueue(0);
$global_ks->{'find_disabled_rows'}= 1;
foreach my $keysel ( @{ $global_ks->ItemsArrayRef } ) {
    foreach my $param ( sort keys %$global_ksacc, 'id' ) {
        $ds->{Global}->{ $keysel->id }->{$param} = $keysel->_Value($param)
          if ( $keysel->_Value($param) );
    }
    my $descendents = $keysel->KeywordObj->Descendents;
    foreach my $desc ( keys %{$descendents} ) {
        push @{ $ds->{Global}->{ $keysel->id }->{Value} },
          $descendents->{$desc};

    }
}

	my $scrips = RT::Scrips->new($RT::SystemUser);
	$scrips->LimitToGlobal();
	foreach my $scrip (@{$scrips->ItemsArrayRef}) {
                my $scrip_ds = {
                Condition => $scrip->ConditionObj->Name(),
                Template => $scrip->TemplateObj->Name(),
                Action => $scrip->ActionObj->Name(),
                };
                push (@{$ds->{'Global'}->{'Scrip'}}, $scrip_ds);

	} 


my $ACL = RT::ACL->new($RT::SystemUser);
$ACL->LimitToSystem();

foreach my $ace ( @{ $ACL->ItemsArrayRef } ) {
        my $right_ds = { PrincipalType => $ace->PrincipalType,
                         PrincipalId => $ace->PrincipalObj->Id,
                         Name => $ace->RightName };
        if ($ace->PrincipalType eq 'Group' && $ace->PrincipalObj->Pseudo) {
                $right_ds->{'Role'} =  $ace->PrincipalObj->Name;
                delete $right_ds->{'PrincipalId'};
                }

        push (
            @{ $ds->{'Global'}->{'Right'}}, $right_ds);
}

my $blank_Link = RT::Link->new($RT::SystemUser);
$blank_Link->_Accessible( 'Foo', 'read' );
$acc = $blank_Link->{_AccessibleCache};
my $links = RT::Links->new($RT::SystemUser);
$links->UnLimit();
while (my $l = $links->Next) {
        my $link_ds;
            foreach my $param ( sort keys %$acc ) {
                    $link_ds->{$param} = $l->_Value($param)
                              if ( $l->_Value($param) );
                                  }
        push (@{$ds->{'Link'}}, $link_ds);
}

my $tix = RT::Faketix->new($RT::SystemUser);
$tix->Limit( FIELD => 'id', OPERATOR => "!=", VALUE => "0" );
while ( my $t = $tix->Next ) {
        my $tick_ds;
    print STDERR "Exporting ticket " . $t->Id . "\n";
    foreach my $param ( sort keys %{ $t->{_AccessibleCache} }, 'id' ) {
        $tick_ds->{$param} = $t->_Value($param)
          if ( $t->_Value($param) );
    }
    my $watchers = $t->Watchers();
    my $watchers_ds; 
    foreach my $w ( @{ $watchers->ItemsArrayRef } ) {
        my $ds = { Type => $w->Type,
                   Email => $w->Email,
                   Id => $w->Id };

        push (@{$watchers_ds}, $ds);
        }
        $tick_ds->{'Watchers'} = $watchers_ds;
    



    my $selects = $t->QueueObj->KeywordSelects();
    while ( my $ks = $selects->Next ) {
        my $keywords = $t->KeywordsObj( $ks->Id );
        while ( my $key = $keywords->Next ) {

            my $name = $key->KeywordObj->RelativePath( $ks->KeywordObj );
            push ( @{ $tick_ds->{'CustomFields'} ->{ $ks->id } }, $name
            );
        }
    }



my $blank_Transaction = RT::Transaction->new($RT::SystemUser);
$blank_Transaction->_Accessible( 'Foo', 'read' );
my $tracc = $blank_Transaction->{_AccessibleCache};
    my $tr = $t->Transactions;
    while ( my $trans = $tr->Next ) {
        my $trans_ds;
        print STDERR "  Exporting transaction " . $trans->Id . "\n";
        foreach my $tr_param ( sort keys %$tracc, 'id' ) {
            $trans_ds->{$tr_param} = $trans->_Value($tr_param)
              if ( $trans->_Value($tr_param) );
        }
        my $attachments = RT::Attachments->new($RT::SystemUser);
        $attachments->Limit(
            FIELD    => 'TransactionId',
            OPERATOR => "=",
            VALUE    => $trans->Id
        );

        while ( my $att = $attachments->Next ) {
                my $att_ds;
            print STDERR "   Exporting attachment " . $att->Id . "\n";
            foreach my $att_param ( sort keys %{ $att->{_AccessibleCache} } ) {
                $att_ds->{$att_param} = $att->_Value($att_param)
                  if ( $att->_Value($att_param) );
            }
                push (@{$trans_ds->{'Attachment'}}, $att_ds);
        }

        push (@{$tick_ds->{'Transaction'}}, $trans_ds);
    }
        push (@{$ds->{'Ticket'}}, $tick_ds);
}

print "sub Data {\n";
print scalar Dumper($ds);
print "}\n1;\n";
#print $xml->XMLout($ds);


More information about the Rt-devel mailing list