2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2016 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 = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
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 );
73 use RT::Interface::CLI qw(Init);
76 "limit-to-privileged|l",
87 id Created Creator LastUpdated LastUpdatedBy
92 my $SystemUserId = RT->SystemUser->Id;
94 Users Groups Queues ScripActions ScripConditions
95 Templates Scrips ACL CustomFields
97 foreach my $class (@classes) {
98 my $objects = "RT::$class"->new( RT->SystemUser );
99 $objects->{find_disabled_rows} = 1 unless $opt{'skip-disabled'};
101 $objects->LimitToPrivileged if $class eq 'Users'
102 && $opt{'limit-to-privileged'};
106 VALUE => 'UserDefined',
108 ) if $class eq 'Groups';
110 if ( $class eq 'CustomFields' ) {
111 $objects->OrderByCols(
112 { FIELD => 'LookupType' },
113 { FIELD => 'SortOrder' },
117 $objects->OrderBy( FIELD => 'Id' );
121 next if $class eq 'ACL'; # XXX - would go into infinite loop - XXX
123 FIELD => 'LastUpdatedBy',
125 VALUE => $SystemUserId
126 ) unless $class eq 'Groups';
130 VALUE => $SystemUserId
131 ) if $class eq 'Users';
136 while ( my $obj = $objects->Next ) {
138 if $obj->can('LastUpdatedBy')
139 and $obj->LastUpdatedBy == $SystemUserId;
142 %fields = map { $_ => 1 } keys %{ $obj->_ClassAccessible };
143 delete @fields{ @{ $Ignore{$class} ||= [] },
144 @{ $Ignore{All} ||= [] }, };
149 if ( $class ne 'ACL' ) {
150 # next if $obj-> # skip default names
151 foreach my $field ( sort keys %fields ) {
152 my $value = $obj->__Value($field);
153 $rv->{$field} = $value if ( defined($value) && length($value) );
155 delete $rv->{Disabled} unless $rv->{Disabled};
157 foreach my $record ( map { /ACL/ ? 'ACE' : substr( $_, 0, -1 ) }
160 foreach my $key ( map "$record$_", ( '', 'Id' ) ) {
161 next unless exists $rv->{$key};
162 my $id = $rv->{$key} or next;
163 next unless $id =~ /^\d+$/;
164 my $obj = "RT::$record"->new( RT->SystemUser );
165 $obj->LoadByCols( Id => $id ) or next;
166 $rv->{$key} = $obj->__Value('Name') || 0;
170 if ( $class eq 'Users' and defined $obj->Privileged ) {
171 $rv->{Privileged} = int( $obj->Privileged );
172 } elsif ( $class eq 'CustomFields' ) {
173 my $values = $obj->Values;
174 while ( my $value = $values->Next ) {
175 push @{ $rv->{Values} }, {
176 map { ( $_ => $value->__Value($_) ) }
178 Name Description SortOrder
182 if ( $obj->LookupType eq 'RT::Queue-RT::Ticket' ) {
183 # XXX-TODO: unused CF's turn into global CF when importing
184 # as the sub InsertData in RT::Handle creates a global CF
185 # when no queue is specified.
187 my $applies = $obj->AppliedTo;
188 while ( my $queue = $applies->Next ) {
189 push @{ $rv->{Queue} }, $queue->Name;
196 $rv->{Right} = $obj->RightName;
198 # 2) Pick a level: Granted on Queue, CF, CF+Queue, or Globally?
199 for ( $obj->ObjectType ) {
200 if ( /^RT::Queue$/ ) {
201 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
202 $rv->{Queue} = $obj->Object->Name;
204 elsif ( /^RT::CustomField$/ ) {
205 next OBJECT if $opt{'skip-disabled'} && $obj->Object->Disabled;
206 $rv->{CF} = $obj->Object->Name;
208 elsif ( /^RT::Group$/ ) {
209 # No support for RT::Group ACLs in RT::Handle yet.
212 elsif ( /^RT::System$/ ) {
213 # skip setting anything on $rv;
214 # "Specifying none of the above will get you a global right."
218 # 3) Pick a Principal; User or Group or Role
219 if ( $obj->PrincipalType eq 'Group' ) {
220 next OBJECT if $opt{'skip-disabled'} && $obj->PrincipalObj->Disabled;
221 my $group = $obj->PrincipalObj->Object;
222 for ( $group->Domain ) {
223 # An internal user group
224 if ( /^SystemInternal$/ ) {
225 $rv->{GroupDomain} = $group->Domain;
226 $rv->{GroupType} = $group->Name;
229 elsif ( /^ACLEquivalence$/ ) {
230 my $member = $group->MembersObj->Next->MemberObj;
231 next OBJECT if $opt{'skip-disabled'} && $member->Disabled;
232 $rv->{UserId} = $member->Object->Name;
234 # A group you created
235 elsif ( /^UserDefined$/ ) {
236 $rv->{GroupDomain} = 'UserDefined';
237 $rv->{GroupId} = $group->Name;
241 $rv->{GroupType} = $obj->PrincipalType;
242 # A system-level role
243 if ( $obj->ObjectType eq 'RT::System' ) {
244 $rv->{GroupDomain} = 'RT::System-Role';
247 elsif ( $obj->ObjectType eq 'RT::Queue' ) {
248 $rv->{GroupDomain} = 'RT::Queue-Role';
253 if ( RT::Attributes->require ) {
254 my $attributes = $obj->Attributes;
255 while ( my $attribute = $attributes->Next ) {
256 my $content = $attribute->Content;
257 if ( $class eq 'Users' and $attribute->Name eq 'Bookmarks' ) {
260 $rv->{Attributes}{ $attribute->Name } = $content
265 push @{ $RV{$class} }, $rv;
270 no strict; use XML::Simple; *_ = XMLin(do { local \$/; readline(DATA) }, ForceArray => [qw(
272 )], NoAttr => 1, SuppressEmpty => ''); *\$_ = (\$_{\$_} || []) for keys \%_; 1; # vim: ft=xml
276 print XML::Simple::XMLout(
277 { map { ( $_ => ( $RV{$_} || [] ) ) } @classes },
278 RootName => 'InitialData',
281 XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>',
288 rt-dump-metadata - dump configuration metadata from an RT database
292 rt-dump-metdata [--all]
296 C<rt-dump-metadata> is a tool that dumps configuration metadata from the
297 Request Tracker database into XML format, suitable for feeding into
298 C<rt-setup-database>. To dump and load a full RT database, you should generally
299 use the native database tools instead, as well as performing any necessary
300 steps from UPGRADING.
302 This is NOT a tool for backing up an RT database. See also
303 L<docs/initialdata> for more straightforward means of importing data.
309 =item C<--all> or C<-a>
311 When run with C<--all>, the dump will include all configuration
312 metadata; otherwise, the metadata dump will only include 'local'
313 configuration changes, i.e. those done manually in the web interface.
315 =item C<--limit-to-privileged> or C<-l>
317 Causes the dumper to only dump privileged users.
319 =item C<--skip-disabled> or C<-s>
321 Ignores disabled rows in the database.