2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2015 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
59 my @libs = ( "@RT_LIB_PATH@", "@LOCAL_LIB_PATH@" );
63 unless ( File::Spec->file_name_is_absolute($lib) ) {
65 if ( File::Spec->file_name_is_absolute(__FILE__) ) {
66 $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
70 $bin_path = $FindBin::Bin;
73 $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
82 GetOptions( \%opt, "help|h",
83 "limit-to-privileged|l",
90 Pod::Usage::pod2usage( { verbose => 2 } );
104 id Created Creator LastUpdated LastUpdatedBy
114 my $SystemUserId = RT->SystemUser->Id;
116 Users Groups Queues ScripActions ScripConditions
117 Templates Scrips ACL CustomFields
119 foreach my $class (@classes) {
120 require "RT/$class.pm";
121 my $objects = "RT::$class"->new( RT->SystemUser );
122 $objects->{find_disabled_rows} = 1 unless $opt{'skip-disabled'};
124 $objects->LimitToPrivileged if $class eq 'Users'
125 && $opt{'limit-to-privileged'};
129 VALUE => 'UserDefined'
130 ) if $class eq 'Groups';
132 if ( $class eq 'CustomFields' ) {
133 $objects->OrderByCols(
134 { FIELD => 'LookupType' },
135 { FIELD => 'SortOrder' },
139 $objects->OrderBy( FIELD => 'Id' );
143 next if $class eq 'ACL'; # XXX - would go into infinite loop - XXX
145 FIELD => 'LastUpdatedBy',
147 VALUE => $SystemUserId
148 ) unless $class eq 'Groups';
152 VALUE => $SystemUserId
153 ) if $class eq 'Users';
158 while ( my $obj = $objects->Next ) {
160 if $obj->can('LastUpdatedBy')
161 and $obj->LastUpdatedBy == $SystemUserId;
164 %fields = map { $_ => 1 } keys %{ $obj->_ClassAccessible };
165 delete @fields{ @{ $Ignore{$class} ||= [] },
166 @{ $Ignore{All} ||= [] }, };
171 if ( $class ne 'ACL' ) {
172 # next if $obj-> # skip default names
173 foreach my $field ( sort keys %fields ) {
174 my $value = $obj->__Value($field);
175 $rv->{$field} = $value if ( defined($value) && length($value) );
177 delete $rv->{Disabled} unless $rv->{Disabled};
179 foreach my $record ( map { /ACL/ ? 'ACE' : substr( $_, 0, -1 ) }
182 foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
183 next unless exists $rv->{$key};
184 my $id = $rv->{$key} or next;
185 my $obj = "RT::$record"->new( RT->SystemUser );
186 $obj->LoadByCols( Id => $id ) or next;
187 $rv->{$key} = $obj->__Value('Name') || 0;
191 if ( $class eq 'Users' and defined $obj->Privileged ) {
192 $rv->{Privileged} = int( $obj->Privileged );
193 } elsif ( $class eq 'CustomFields' ) {
194 my $values = $obj->Values;
195 while ( my $value = $values->Next ) {
196 push @{ $rv->{Values} }, {
197 map { ( $_ => $value->__Value($_) ) }
199 Name Description SortOrder
203 if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
204 # XXX-TODO: unused CF's turn into global CF when importing
205 # as the sub InsertData in RT::Handle creates a global CF
206 # when no queue is specified.
208 my $applies = $obj->AppliedTo;
209 while ( my $queue = $applies->Next ) {
210 push @{ $rv->{Queue} }, $queue->Name;
217 $rv->{Right} = $obj->RightName;
219 # 2) Pick a level: Granted on Queue, CF, CF+Queue, or Globally?
220 for ( $obj->ObjectType ) {
221 if ( /^RT::Queue$/ ) {
222 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
223 $rv->{Queue} = $obj->Object->Name;
225 elsif ( /^RT::CustomField$/ ) {
226 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
227 $rv->{CF} = $obj->Object->Name;
229 elsif ( /^RT::Group$/ ) {
230 # No support for RT::Group ACLs in RT::Handle yet.
233 elsif ( /^RT::System$/ ) {
234 # skip setting anything on $rv;
235 # "Specifying none of the above will get you a global right."
239 # 3) Pick a Principal; User or Group or Role
240 if ( $obj->PrincipalType eq 'Group' ) {
241 next OBJECT if $opt{'skip-disabled'} && $obj->PrincipalObj->Disabled;
242 my $group = $obj->PrincipalObj->Object;
243 for ( $group->Domain ) {
244 # An internal user group
245 if ( /^SystemInternal$/ ) {
246 $rv->{GroupDomain} = $group->Domain;
247 $rv->{GroupType} = $group->Type;
250 elsif ( /^ACLEquivalence$/ ) {
251 my $member = $group->MembersObj->Next->MemberObj;
252 next OBJECT if $opt{'skip-disabled'} && $member->Disabled;
253 $rv->{UserId} = $member->Object->Name;
255 # A group you created
256 elsif ( /^UserDefined$/ ) {
257 $rv->{GroupDomain} = 'UserDefined';
258 $rv->{GroupId} = $group->Name;
262 $rv->{GroupType} = $obj->PrincipalType;
263 # A system-level role
264 if ( $obj->ObjectType eq 'RT::System' ) {
265 $rv->{GroupDomain} = 'RT::System-Role';
268 elsif ( $obj->ObjectType eq 'RT::Queue' ) {
269 $rv->{GroupDomain} = 'RT::Queue-Role';
272 if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
273 # XXX-TODO: unused CF's turn into global CF when importing
274 # as the sub InsertData in RT::Handle creates a global CF
275 # when no queue is specified.
277 my $applies = $obj->AppliedTo;
278 while ( my $queue = $applies->Next ) {
279 push @{ $rv->{Queue} }, $queue->Name;
284 if ( eval { require RT::Attributes; 1 } ) {
285 my $attributes = $obj->Attributes;
286 while ( my $attribute = $attributes->Next ) {
287 my $content = $attribute->Content;
288 if ( $class eq 'Users' and $attribute->Name eq 'Bookmarks' ) {
291 $rv->{Attributes}{ $attribute->Name } = $content
296 push @{ $RV{$class} }, $rv;
301 no strict; use XML::Simple; *_ = XMLin(do { local \$/; readline(DATA) }, ForceArray => [qw(
303 )], NoAttr => 1, SuppressEmpty => ''); *\$_ = (\$_{\$_} || []) for keys \%_; 1; # vim: ft=xml
307 print XML::Simple::XMLout(
308 { map { ( $_ => ( $RV{$_} || [] ) ) } @classes },
309 RootName => 'InitialData',
312 XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>',
319 rt-dump-metadata - dump configuration metadata from an RT database
323 rt-dump-metdata [--all]
327 C<rt-dump-metadata> is a tool that dumps configuration metadata from the
328 Request Tracker database into XML format, suitable for feeding into
329 C<rt-setup-database>. To dump and load a full RT database, you should generally
330 use the native database tools instead, as well as performing any necessary
331 steps from UPGRADING.
333 This is NOT a tool for backing up an RT database. See also
334 L<docs/initialdata> for more straightforward means of importing data.
340 =item C<--all> or C<-a>
342 When run with C<--all>, the dump will include all configuration
343 metadata; otherwise, the metadata dump will only include 'local'
344 configuration changes, i.e. those done manually in the web interface.
346 =item C<--limit-to-privileged> or C<-l>
348 Causes the dumper to only dump privileged users.
350 =item C<--skip-disabled> or C<-s>
352 Ignores disabled rows in the database.