[Rt-commit] rt branch, 4.2/dump-metadata-cleanups, created. rt-4.0.18-31-g94f99e8

Alex Vandiver alexmv at bestpractical.com
Thu Oct 31 18:17:31 EDT 2013


The branch, 4.2/dump-metadata-cleanups has been created
        at  94f99e840766e929be7cb231c0c54e23b2647919 (commit)

- Log -----------------------------------------------------------------
commit e5f431120ccadce6831f305843e3ee219e0127de
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 31 18:06:01 2013 -0400

    Switch to --all instead of an incomprehensible 0

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index 20c2853..d132764 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -79,7 +79,9 @@ BEGIN {
 
 use Getopt::Long;
 my %opt;
-GetOptions( \%opt, "help|h" );
+GetOptions( \%opt, "help|h",
+    "all|a",
+);
 
 if ( $opt{help} ) {
     require Pod::Usage;
@@ -93,8 +95,6 @@ require XML::Simple;
 RT::LoadConfig();
 RT::Init();
 
-my $LocalOnly = @ARGV ? shift(@ARGV) : 1;
-
 my %RV;
 my %Ignore = (
     All => [
@@ -130,7 +130,7 @@ foreach my $class (@classes) {
         $objects->OrderBy( FIELD => 'Id' );
     }
 
-    if ($LocalOnly) {
+    unless ($opt{all}) {
         next if $class eq 'ACL';    # XXX - would go into infinite loop - XXX
         $objects->Limit(
             FIELD    => 'LastUpdatedBy',
@@ -232,7 +232,7 @@ rt-dump-metadata - dump configuration metadata from an RT database
 
 =head1 SYNOPSIS
 
-    rt-dump-metdata [ 0 ]
+    rt-dump-metdata [--all]
 
 =head1 DESCRIPTION
 
@@ -242,11 +242,19 @@ C<rt-setup-database>. To dump and load a full RT database, you should generally
 use the native database tools instead, as well as performing any necessary
 steps from UPGRADING.
 
-When run without arguments, the metadata dump will only include 'local'
+This is NOT a tool for backing up an RT database.
+
+=head1 OPTIONS
+
+=over
+
+=item C<--all>
+
+When run with C<--all>, the dump will include all configuration
+metadata; otherwise, the metadata dump will only include 'local'
 configuration changes, i.e. those done manually in the web interface.
 
-When run with the argument '0', the dump will include all configuration
-metadata.
+=back
 
-This is NOT a tool for backing up an RT database.
+=cut
 

commit fe3cdc3a8644a3de6c566b305781cf49feded6e4
Author: Kai Storbeck <kai at xs4all.nl>
Date:   Thu Oct 31 18:07:10 2013 -0400

    Only ever dump UserDefined groups, even with --all

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index d132764..38bcac6 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -119,6 +119,11 @@ foreach my $class (@classes) {
     my $objects = "RT::$class"->new( RT->SystemUser );
     $objects->{find_disabled_rows} = 1;
     $objects->UnLimit;
+    $objects->Limit(
+        FIELD    => 'Domain',
+        OPERATOR => '=',
+        VALUE    => 'UserDefined'
+    ) if $class eq 'Groups';
 
     if ( $class eq 'CustomFields' ) {
         $objects->OrderByCols(
@@ -142,11 +147,6 @@ foreach my $class (@classes) {
             OPERATOR => '!=',
             VALUE    => $SystemUserId
         ) if $class eq 'Users';
-        $objects->Limit(
-            FIELD    => 'Domain',
-            OPERATOR => '=',
-            VALUE    => 'UserDefined'
-        ) if $class eq 'Groups';
     }
 
     my %fields;

commit 5c37f5100210ef6f103d9feb361ea4a6fdcfc956
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 31 18:09:56 2013 -0400

    fixup! Switch to --all instead of an incomprehensible 0

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index 38bcac6..2f2db30 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -248,7 +248,7 @@ This is NOT a tool for backing up an RT database.
 
 =over
 
-=item C<--all>
+=item C<--all> or C<-a>
 
 When run with C<--all>, the dump will include all configuration
 metadata; otherwise, the metadata dump will only include 'local'

commit a6e417fee855433ffc4e6ce5f1ce176668a4b0fa
Author: Kai Storbeck <kai at xs4all.nl>
Date:   Thu Oct 31 18:10:28 2013 -0400

    Add a --limit-to-privileged option

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index 2f2db30..c7f8535 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -80,6 +80,7 @@ BEGIN {
 use Getopt::Long;
 my %opt;
 GetOptions( \%opt, "help|h",
+    "limit-to-privileged|l",
     "all|a",
 );
 
@@ -119,6 +120,8 @@ foreach my $class (@classes) {
     my $objects = "RT::$class"->new( RT->SystemUser );
     $objects->{find_disabled_rows} = 1;
     $objects->UnLimit;
+    $objects->LimitToPrivileged if $class eq 'Users'
+        && $opt{'limit-to-privileged'};
     $objects->Limit(
         FIELD    => 'Domain',
         OPERATOR => '=',
@@ -254,6 +257,10 @@ When run with C<--all>, the dump will include all configuration
 metadata; otherwise, the metadata dump will only include 'local'
 configuration changes, i.e. those done manually in the web interface.
 
+=item C<--limit-to-privileged> or C<-l>
+
+Causes the dumper to only dump privileged users.
+
 =back
 
 =cut

commit 6dcfa73702f253a1a8a61e60a5d1447694c5269f
Author: Kai Storbeck <kai at xs4all.nl>
Date:   Thu Oct 31 18:11:22 2013 -0400

    Add a --skip-disabled option

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index c7f8535..614f4bf 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -81,6 +81,7 @@ use Getopt::Long;
 my %opt;
 GetOptions( \%opt, "help|h",
     "limit-to-privileged|l",
+    "skip-disabled|s",
     "all|a",
 );
 
@@ -118,7 +119,7 @@ my @classes      = qw(
 foreach my $class (@classes) {
     require "RT/$class.pm";
     my $objects = "RT::$class"->new( RT->SystemUser );
-    $objects->{find_disabled_rows} = 1;
+    $objects->{find_disabled_rows} = 1 unless $opt{'skip-disabled'};
     $objects->UnLimit;
     $objects->LimitToPrivileged if $class eq 'Users'
         && $opt{'limit-to-privileged'};
@@ -261,6 +262,10 @@ configuration changes, i.e. those done manually in the web interface.
 
 Causes the dumper to only dump privileged users.
 
+=item C<--skip-disabled> or C<-s>
+
+Ignores disabled rows in the database.
+
 =back
 
 =cut

commit 4b53069ee84f61201dafe2269c8e3d8a78f90b65
Author: Kai Storbeck <kai at xs4all.nl>
Date:   Thu Oct 31 18:15:20 2013 -0400

    Add Applies-To information about CF's
    
    This still leaves in a small bug: Unused CF's on the sending side turn
    into globally applied CF's when importing this metadata.  Not a huge
    deal IMO.
    
    Note that in 4.2 this structure is renamed to ApplyTo together with a
    field named LookupType.

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index 614f4bf..a62b407 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -198,6 +198,16 @@ foreach my $class (@classes) {
                         ),
                 };
             }
+            if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
+                # XXX-TODO: unused CF's turn into global CF when importing
+                # as the sub InsertData in RT::Handle creates a global CF
+                # when no queue is specified.
+                $rv->{Queue} = [];
+                my $applies = $obj->AppliedTo;
+                while ( my $queue = $applies->Next ) {
+                    push @{ $rv->{Queue} }, $queue->Name;
+                }
+            }
         }
 
         if ( eval { require RT::Attributes; 1 } ) {

commit b97865dd18f434585964403ac6c099a1109cae56
Author: Kai Storbeck <kai at xs4all.nl>
Date:   Thu Oct 31 18:16:44 2013 -0400

    Make dumped ACLs not include references to principal ids

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index a62b407..e93965c 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -154,6 +154,7 @@ foreach my $class (@classes) {
     }
 
     my %fields;
+OBJECT:
     while ( my $obj = $objects->Next ) {
         next
             if $obj->can('LastUpdatedBy')
@@ -167,36 +168,106 @@ foreach my $class (@classes) {
 
         my $rv;
 
-        # next if $obj-> # skip default names
-        foreach my $field ( sort keys %fields ) {
-            my $value = $obj->__Value($field);
-            $rv->{$field} = $value if ( defined($value) && length($value) );
-        }
-        delete $rv->{Disabled} unless $rv->{Disabled};
-
-        foreach my $record ( map { /ACL/ ? 'ACE' : substr( $_, 0, -1 ) }
-            @classes )
-        {
-            foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
-                next unless exists $rv->{$key};
-                my $id = $rv->{$key} or next;
-                my $obj = "RT::$record"->new( RT->SystemUser );
-                $obj->LoadByCols( Id => $id ) or next;
-                $rv->{$key} = $obj->__Value('Name') || 0;
+        if ( $class ne 'ACL' ) {
+            # next if $obj-> # skip default names
+            foreach my $field ( sort keys %fields ) {
+                my $value = $obj->__Value($field);
+                $rv->{$field} = $value if ( defined($value) && length($value) );
+            }
+            delete $rv->{Disabled} unless $rv->{Disabled};
+
+            foreach my $record ( map { /ACL/ ? 'ACE' : substr( $_, 0, -1 ) }
+                @classes )
+            {
+                foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
+                    next unless exists $rv->{$key};
+                    my $id = $rv->{$key} or next;
+                    my $obj = "RT::$record"->new( RT->SystemUser );
+                    $obj->LoadByCols( Id => $id ) or next;
+                    $rv->{$key} = $obj->__Value('Name') || 0;
+                }
+            }
+
+            if ( $class eq 'Users' and defined $obj->Privileged ) {
+                $rv->{Privileged} = int( $obj->Privileged );
+            } elsif ( $class eq 'CustomFields' ) {
+                my $values = $obj->Values;
+                while ( my $value = $values->Next ) {
+                    push @{ $rv->{Values} }, {
+                        map { ( $_ => $value->__Value($_) ) }
+                            qw(
+                            Name Description SortOrder
+                            ),
+                    };
+                }
+                if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
+                    # XXX-TODO: unused CF's turn into global CF when importing
+                    # as the sub InsertData in RT::Handle creates a global CF
+                    # when no queue is specified.
+                    $rv->{Queue} = [];
+                    my $applies = $obj->AppliedTo;
+                    while ( my $queue = $applies->Next ) {
+                        push @{ $rv->{Queue} }, $queue->Name;
+                    }
+                }
             }
         }
+        else {
+            # 1) pick the right
+            $rv->{Right} = $obj->RightName;
+
+            # 2) Pick a level: Granted on Queue, CF, CF+Queue, or Globally?
+            for ( $obj->ObjectType ) {
+                if ( /^RT::Queue$/ ) {
+                    next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
+                    $rv->{Queue} = $obj->Object->Name;
+                }
+                elsif ( /^RT::CustomField$/ ) {
+                    next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
+                    $rv->{CF} = $obj->Object->Name;
+                }
+                elsif ( /^RT::Group$/ ) {
+                    # No support for RT::Group ACLs in RT::Handle yet.
+                    next OBJECT;
+                }
+                elsif ( /^RT::System$/ ) {
+                    # skip setting anything on $rv;
+                    # "Specifying none of the above will get you a global right."
+                }
+            }
 
-        if ( $class eq 'Users' and defined $obj->Privileged ) {
-            $rv->{Privileged} = int( $obj->Privileged );
-        } elsif ( $class eq 'CustomFields' ) {
-            my $values = $obj->Values;
-            while ( my $value = $values->Next ) {
-                push @{ $rv->{Values} }, {
-                    map { ( $_ => $value->__Value($_) ) }
-                        qw(
-                        Name Description SortOrder
-                        ),
-                };
+            # 3) Pick a Principal; User or Group or Role
+            if ( $obj->PrincipalType eq 'Group' ) {
+                next OBJECT if $opt{'skip-disabled'} && $obj->PrincipalObj->Disabled;
+                my $group = $obj->PrincipalObj->Object;
+                for ( $group->Domain ) {
+                    # An internal user group
+                    if ( /^SystemInternal$/ ) {
+                        $rv->{GroupDomain} = $group->Domain;
+                        $rv->{GroupType} = $group->Type;
+                    }
+                    # An individual user
+                    elsif ( /^ACLEquivalence$/ ) {
+                        my $member = $group->MembersObj->Next->MemberObj;
+                        next OBJECT if $opt{'skip-disabled'} && $member->Disabled;
+                        $rv->{UserId} = $member->Object->Name;
+                    }
+                    # A group you created
+                    elsif ( /^UserDefined$/ ) {
+                        $rv->{GroupDomain} = 'UserDefined';
+                        $rv->{GroupId} = $group->Name;
+                    }
+                }
+            } else {
+                $rv->{GroupType} = $obj->PrincipalType;
+                # A system-level role
+                if ( $obj->ObjectType eq 'RT::System' ) {
+                    $rv->{GroupDomain} = 'RT::System-Role';
+                }
+                # A queue-level role
+                elsif ( $obj->ObjectType eq 'RT::Queue' ) {
+                    $rv->{GroupDomain} = 'RT::Queue-Role';
+                }
             }
             if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
                 # XXX-TODO: unused CF's turn into global CF when importing

commit 94f99e840766e929be7cb231c0c54e23b2647919
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 31 18:17:03 2013 -0400

    Add a pointer to the initialdata docs

diff --git a/sbin/rt-dump-metadata.in b/sbin/rt-dump-metadata.in
index e93965c..4c555ae 100644
--- a/sbin/rt-dump-metadata.in
+++ b/sbin/rt-dump-metadata.in
@@ -327,7 +327,8 @@ C<rt-setup-database>. To dump and load a full RT database, you should generally
 use the native database tools instead, as well as performing any necessary
 steps from UPGRADING.
 
-This is NOT a tool for backing up an RT database.
+This is NOT a tool for backing up an RT database.  See also
+L<docs/initialdata> for more straightforward means of importing data.
 
 =head1 OPTIONS
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list