2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
7 # <sales@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
52 # As we specify that XML is UTF-8 and we output it to STDOUT, we must be sure
53 # it is UTF-8 so further XMLin will not break
54 binmode( STDOUT, ":utf8" );
56 # fix lib paths, some may be relative
57 BEGIN { # BEGIN RT CMD BOILERPLATE
60 my @libs = ("lib", "local/lib");
64 unless ( File::Spec->file_name_is_absolute($lib) ) {
65 $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
66 $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
75 GetOptions( \%opt, "help|h",
76 "limit-to-privileged|l",
83 Pod::Usage::pod2usage( { verbose => 2 } );
97 id Created Creator LastUpdated LastUpdatedBy
102 my $SystemUserId = RT->SystemUser->Id;
104 Users Groups Queues ScripActions ScripConditions
105 Templates Scrips ACL CustomFields
107 foreach my $class (@classes) {
108 require "RT/$class.pm";
109 my $objects = "RT::$class"->new( RT->SystemUser );
110 $objects->{find_disabled_rows} = 1 unless $opt{'skip-disabled'};
112 $objects->LimitToPrivileged if $class eq 'Users'
113 && $opt{'limit-to-privileged'};
117 VALUE => 'UserDefined',
119 ) if $class eq 'Groups';
121 if ( $class eq 'CustomFields' ) {
122 $objects->OrderByCols(
123 { FIELD => 'LookupType' },
124 { FIELD => 'SortOrder' },
128 $objects->OrderBy( FIELD => 'Id' );
132 next if $class eq 'ACL'; # XXX - would go into infinite loop - XXX
134 FIELD => 'LastUpdatedBy',
136 VALUE => $SystemUserId
137 ) unless $class eq 'Groups';
141 VALUE => $SystemUserId
142 ) if $class eq 'Users';
147 while ( my $obj = $objects->Next ) {
149 if $obj->can('LastUpdatedBy')
150 and $obj->LastUpdatedBy == $SystemUserId;
153 %fields = map { $_ => 1 } keys %{ $obj->_ClassAccessible };
154 delete @fields{ @{ $Ignore{$class} ||= [] },
155 @{ $Ignore{All} ||= [] }, };
160 if ( $class ne 'ACL' ) {
161 # next if $obj-> # skip default names
162 foreach my $field ( sort keys %fields ) {
163 my $value = $obj->__Value($field);
164 $rv->{$field} = $value if ( defined($value) && length($value) );
166 delete $rv->{Disabled} unless $rv->{Disabled};
168 foreach my $record ( map { /ACL/ ? 'ACE' : substr( $_, 0, -1 ) }
171 foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
172 next unless exists $rv->{$key};
173 my $id = $rv->{$key} or next;
174 my $obj = "RT::$record"->new( RT->SystemUser );
175 $obj->LoadByCols( Id => $id ) or next;
176 $rv->{$key} = $obj->__Value('Name') || 0;
180 if ( $class eq 'Users' and defined $obj->Privileged ) {
181 $rv->{Privileged} = int( $obj->Privileged );
182 } elsif ( $class eq 'CustomFields' ) {
183 my $values = $obj->Values;
184 while ( my $value = $values->Next ) {
185 push @{ $rv->{Values} }, {
186 map { ( $_ => $value->__Value($_) ) }
188 Name Description SortOrder
192 if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
193 # XXX-TODO: unused CF's turn into global CF when importing
194 # as the sub InsertData in RT::Handle creates a global CF
195 # when no queue is specified.
197 my $applies = $obj->AppliedTo;
198 while ( my $queue = $applies->Next ) {
199 push @{ $rv->{Queue} }, $queue->Name;
206 $rv->{Right} = $obj->RightName;
208 # 2) Pick a level: Granted on Queue, CF, CF+Queue, or Globally?
209 for ( $obj->ObjectType ) {
210 if ( /^RT::Queue$/ ) {
211 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
212 $rv->{Queue} = $obj->Object->Name;
214 elsif ( /^RT::CustomField$/ ) {
215 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
216 $rv->{CF} = $obj->Object->Name;
218 elsif ( /^RT::Group$/ ) {
219 # No support for RT::Group ACLs in RT::Handle yet.
222 elsif ( /^RT::System$/ ) {
223 # skip setting anything on $rv;
224 # "Specifying none of the above will get you a global right."
228 # 3) Pick a Principal; User or Group or Role
229 if ( $obj->PrincipalType eq 'Group' ) {
230 next OBJECT if $opt{'skip-disabled'} && $obj->PrincipalObj->Disabled;
231 my $group = $obj->PrincipalObj->Object;
232 for ( $group->Domain ) {
233 # An internal user group
234 if ( /^SystemInternal$/ ) {
235 $rv->{GroupDomain} = $group->Domain;
236 $rv->{GroupType} = $group->Type;
239 elsif ( /^ACLEquivalence$/ ) {
240 my $member = $group->MembersObj->Next->MemberObj;
241 next OBJECT if $opt{'skip-disabled'} && $member->Disabled;
242 $rv->{UserId} = $member->Object->Name;
244 # A group you created
245 elsif ( /^UserDefined$/ ) {
246 $rv->{GroupDomain} = 'UserDefined';
247 $rv->{GroupId} = $group->Name;
251 $rv->{GroupType} = $obj->PrincipalType;
252 # A system-level role
253 if ( $obj->ObjectType eq 'RT::System' ) {
254 $rv->{GroupDomain} = 'RT::System-Role';
257 elsif ( $obj->ObjectType eq 'RT::Queue' ) {
258 $rv->{GroupDomain} = 'RT::Queue-Role';
263 if ( eval { require RT::Attributes; 1 } ) {
264 my $attributes = $obj->Attributes;
265 while ( my $attribute = $attributes->Next ) {
266 my $content = $attribute->Content;
267 if ( $class eq 'Users' and $attribute->Name eq 'Bookmarks' ) {
270 $rv->{Attributes}{ $attribute->Name } = $content
275 push @{ $RV{$class} }, $rv;
280 no strict; use XML::Simple; *_ = XMLin(do { local \$/; readline(DATA) }, ForceArray => [qw(
282 )], NoAttr => 1, SuppressEmpty => ''); *\$_ = (\$_{\$_} || []) for keys \%_; 1; # vim: ft=xml
286 print XML::Simple::XMLout(
287 { map { ( $_ => ( $RV{$_} || [] ) ) } @classes },
288 RootName => 'InitialData',
291 XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>',
298 rt-dump-metadata - dump configuration metadata from an RT database
302 rt-dump-metdata [--all]
306 C<rt-dump-metadata> is a tool that dumps configuration metadata from the
307 Request Tracker database into XML format, suitable for feeding into
308 C<rt-setup-database>. To dump and load a full RT database, you should generally
309 use the native database tools instead, as well as performing any necessary
310 steps from UPGRADING.
312 This is NOT a tool for backing up an RT database. See also
313 L<docs/initialdata> for more straightforward means of importing data.
319 =item C<--all> or C<-a>
321 When run with C<--all>, the dump will include all configuration
322 metadata; otherwise, the metadata dump will only include 'local'
323 configuration changes, i.e. those done manually in the web interface.
325 =item C<--limit-to-privileged> or C<-l>
327 Causes the dumper to only dump privileged users.
329 =item C<--skip-disabled> or C<-s>
331 Ignores disabled rows in the database.