rt 4.2.13 ticket#13852
[freeside.git] / rt / sbin / rt-dump-metadata.in
index 5e0e5c3..c212749 100644 (file)
@@ -3,7 +3,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -54,22 +54,15 @@ use warnings;
 binmode( STDOUT, ":utf8" );
 
 # fix lib paths, some may be relative
-BEGIN {
+BEGIN { # BEGIN RT CMD BOILERPLATE
     require File::Spec;
-    my @libs = ( "@RT_LIB_PATH@", "@LOCAL_LIB_PATH@" );
+    require Cwd;
+    my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
     my $bin_path;
 
     for my $lib (@libs) {
         unless ( File::Spec->file_name_is_absolute($lib) ) {
-            unless ($bin_path) {
-                if ( File::Spec->file_name_is_absolute(__FILE__) ) {
-                    $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
-                } else {
-                    require FindBin;
-                    no warnings "once";
-                    $bin_path = $FindBin::Bin;
-                }
-            }
+            $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
             $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
         }
         unshift @INC, $lib;
@@ -77,26 +70,16 @@ BEGIN {
 
 }
 
-use Getopt::Long;
+use RT::Interface::CLI qw(Init);
 my %opt;
-GetOptions( \%opt, "help|h",
+Init( \%opt,
     "limit-to-privileged|l",
     "skip-disabled|s",
     "all|a",
 );
 
-if ( $opt{help} ) {
-    require Pod::Usage;
-    Pod::Usage::pod2usage( { verbose => 2 } );
-    exit;
-}
-
-require RT;
 require XML::Simple;
 
-RT::LoadConfig();
-RT::Init();
-
 my %RV;
 my %Ignore = (
     All => [
@@ -104,11 +87,6 @@ my %Ignore = (
             id Created Creator LastUpdated LastUpdatedBy
             )
            ],
-    Templates => [
-        qw(
-            TranslationOf
-            )
-    ],
 );
 
 my $SystemUserId = RT->SystemUser->Id;
@@ -117,7 +95,6 @@ my @classes      = qw(
     Templates Scrips ACL CustomFields
     );
 foreach my $class (@classes) {
-    require "RT/$class.pm";
     my $objects = "RT::$class"->new( RT->SystemUser );
     $objects->{find_disabled_rows} = 1 unless $opt{'skip-disabled'};
     $objects->UnLimit;
@@ -126,7 +103,8 @@ foreach my $class (@classes) {
     $objects->Limit(
         FIELD    => 'Domain',
         OPERATOR => '=',
-        VALUE    => 'UserDefined'
+        VALUE    => 'UserDefined',
+        CASESENSITIVE => 0,
     ) if $class eq 'Groups';
 
     if ( $class eq 'CustomFields' ) {
@@ -182,6 +160,7 @@ OBJECT:
                 foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
                     next unless exists $rv->{$key};
                     my $id = $rv->{$key} or next;
+                    next unless $id =~ /^\d+$/;
                     my $obj = "RT::$record"->new( RT->SystemUser );
                     $obj->LoadByCols( Id => $id ) or next;
                     $rv->{$key} = $obj->__Value('Name') || 0;
@@ -244,7 +223,7 @@ OBJECT:
                     # An internal user group
                     if ( /^SystemInternal$/ ) {
                         $rv->{GroupDomain} = $group->Domain;
-                        $rv->{GroupType} = $group->Type;
+                        $rv->{GroupType}   = $group->Name;
                     }
                     # An individual user
                     elsif ( /^ACLEquivalence$/ ) {
@@ -269,19 +248,9 @@ OBJECT:
                     $rv->{GroupDomain} = 'RT::Queue-Role';
                 }
             }
-            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 } ) {
+        if ( RT::Attributes->require ) {
             my $attributes = $obj->Attributes;
             while ( my $attribute = $attributes->Next ) {
                 my $content = $attribute->Content;