1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
49 package RT::Shredder::Plugin::Summary;
52 use warnings FATAL => 'all';
54 use base qw(RT::Shredder::Plugin::SQLDump);
56 sub AppliesToStates { return 'before any action' }
61 my %args = (file_name => '', @_);
62 unless( $args{'file_name'} ) {
64 $args{'file_name'} = POSIX::strftime( "summary-%Y%m%dT%H%M%S.XXXX.txt", gmtime );
66 return $self->SUPER::TestArgs( %args );
72 my %args = ( Object => undef, @_ );
73 my $class = ref $args{'Object'};
76 my $method = 'WriteDown'. $class;
77 $method = 'WriteDownDefault' unless $self->can($method);
78 return $self->$method( %args );
82 my %skip_refs_to = ();
84 sub WriteDownDefault {
86 my %args = ( Object => undef, @_ );
87 return $self->_WriteDownHash(
89 $self->_MakeHash( $args{'Object'} ),
93 # TODO: cover other objects
101 # ObjectCustomFieldValue.pm
107 # ScripAction.pm - works fine with defaults
108 # ScripCondition.pm - works fine with defaults
109 # Template.pm - works fine with defaults
111 sub WriteDownCachedGroupMember { return 1 }
112 sub WriteDownPrincipal { return 1 }
116 my %args = ( Object => undef, @_ );
117 if ( $args{'Object'}->Domain =~ /-Role$/ ) {
118 return $skip_refs_to{ $args{'Object'}->_AsString } = 1;
120 return $self->WriteDownDefault( %args );
123 sub WriteDownTransaction {
125 my %args = ( Object => undef, @_ );
127 my $props = $self->_MakeHash( $args{'Object'} );
128 $props->{'Object'} = delete $props->{'ObjectType'};
129 $props->{'Object'} .= '-'. delete $props->{'ObjectId'}
130 if $props->{'ObjectId'};
131 return 1 if $skip_refs_to{ $props->{'Object'} };
133 delete $props->{$_} foreach grep
134 !defined $props->{$_} || $props->{$_} eq '', keys %$props;
136 return $self->_WriteDownHash( $args{'Object'}, $props );
141 my %args = ( Object => undef, @_ );
142 my $props = $self->_MakeHash( $args{'Object'} );
143 $props->{'Action'} = $args{'Object'}->ActionObj->Name;
144 $props->{'Condition'} = $args{'Object'}->ConditionObj->Name;
145 $props->{'Template'} = $args{'Object'}->TemplateObj->Name;
146 $props->{'Queue'} = $args{'Object'}->QueueObj->Name || 'global';
148 return $self->_WriteDownHash( $args{'Object'}, $props );
152 my ($self, $obj) = @_;
153 my $hash = $self->__MakeHash( $obj );
154 foreach (grep exists $hash->{$_}, qw(Creator LastUpdatedBy)) {
155 my $method = $_ .'Obj';
156 my $u = $obj->$method();
157 $hash->{ $_ } = $u->EmailAddress || $u->Name || $u->_AsString;
163 my ($self, $obj) = @_;
165 $hash{ $_ } = $obj->$_()
166 foreach sort keys %{ $obj->_ClassAccessible };
171 my ($self, $obj, $hash) = @_;
172 return (0, 'no handle') unless my $fh = $self->{'opt'}{'file_handle'};
174 print $fh "=== ". $obj->_AsString ." ===\n"
175 or return (0, "Couldn't write to filehandle");
177 foreach my $key( sort keys %$hash ) {
178 my $val = $hash->{ $key };
179 next unless defined $val;
181 print $fh $key .': '. $val ."\n"
182 or return (0, "Couldn't write to filehandle");
184 print $fh "\n" or return (0, "Couldn't write to filehandle");