import rt 3.8.7
[freeside.git] / rt / sbin / rt-dump-database.in
index 10670a2..878a209 100755 (executable)
@@ -2,8 +2,8 @@
 # BEGIN BPS TAGGED BLOCK {{{
 # 
 # COPYRIGHT:
-#  
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
+# 
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
 #                                          <jesse@bestpractical.com>
 # 
 # (Except where explicitly superseded by other copyright notices)
 # END BPS TAGGED BLOCK }}}
 use strict;
 
-use lib "@LOCAL_LIB_PATH@";
-use lib "@RT_LIB_PATH@";
+# fix lib paths, some may be relative
+BEGIN {
+    require File::Spec;
+    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;
+                }
+            }
+            $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
+        }
+        unshift @INC, $lib;
+    }
+
+}
 
 use RT;
 use XML::Simple;
@@ -117,7 +139,7 @@ foreach my $class (@classes) {
        # next if $obj-> # skip default names
        foreach my $field (sort keys %fields) {
            my $value = $obj->__Value($field);
-           $rv->{$field} = $value if length($value);
+           $rv->{$field} = $value if ( defined ($value) && length($value) );
        }
        delete $rv->{Disabled} unless $rv->{Disabled};