1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2016 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 );
81 my %skip_refs_to = ();
83 sub WriteDownDefault {
85 my %args = ( Object => undef, @_ );
86 return $self->_WriteDownHash(
88 $self->_MakeHash( $args{'Object'} ),
92 # TODO: cover other objects
100 # ObjectCustomFieldValue.pm
106 # ScripAction.pm - works fine with defaults
107 # ScripCondition.pm - works fine with defaults
108 # Template.pm - works fine with defaults
110 sub WriteDownCachedGroupMember { return 1 }
111 sub WriteDownPrincipal { return 1 }
115 my %args = ( Object => undef, @_ );
116 if ( $args{'Object'}->RoleClass ) {
117 return $skip_refs_to{ $args{'Object'}->UID } = 1;
119 return $self->WriteDownDefault( %args );
122 sub WriteDownTransaction {
124 my %args = ( Object => undef, @_ );
126 my $props = $self->_MakeHash( $args{'Object'} );
127 $props->{'Object'} = delete $props->{'ObjectType'};
128 $props->{'Object'} .= '-'. delete $props->{'ObjectId'}
129 if $props->{'ObjectId'};
130 return 1 if $skip_refs_to{ $props->{'Object'} };
132 delete $props->{$_} foreach grep
133 !defined $props->{$_} || $props->{$_} eq '', keys %$props;
135 return $self->_WriteDownHash( $args{'Object'}, $props );
140 my %args = ( Object => undef, @_ );
141 my $props = $self->_MakeHash( $args{'Object'} );
142 $props->{'Action'} = $args{'Object'}->ActionObj->Name;
143 $props->{'Condition'} = $args{'Object'}->ConditionObj->Name;
144 $props->{'Template'} = $args{'Object'}->Template;
145 $props->{'Queue'} = $args{'Object'}->QueueObj->Name || 'global';
147 return $self->_WriteDownHash( $args{'Object'}, $props );
151 my ($self, $obj) = @_;
152 my $hash = $self->__MakeHash( $obj );
153 foreach (grep exists $hash->{$_}, qw(Creator LastUpdatedBy)) {
154 my $method = $_ .'Obj';
155 my $u = $obj->$method();
156 $hash->{ $_ } = $u->EmailAddress || $u->Name || $u->UID;
162 my ($self, $obj) = @_;
164 $hash{ $_ } = $obj->$_()
165 foreach sort keys %{ $obj->_ClassAccessible };
170 my ($self, $obj, $hash) = @_;
171 return (0, 'no handle') unless my $fh = $self->{'opt'}{'file_handle'};
173 print $fh "=== ". $obj->UID ." ===\n"
174 or return (0, "Couldn't write to filehandle");
176 foreach my $key( sort keys %$hash ) {
177 my $val = $hash->{ $key };
178 next unless defined $val;
180 print $fh $key .': '. $val ."\n"
181 or return (0, "Couldn't write to filehandle");
183 print $fh "\n" or return (0, "Couldn't write to filehandle");