Upgrade to 4.2.2
[usit-rt.git] / lib / RT / Shredder / Record.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
320f0092 5# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
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
16# from www.gnu.org.
17#
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.
22#
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.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
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.)
37#
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.
46#
47# END BPS TAGGED BLOCK }}}
48
49use RT::Record ();
50package RT::Record;
51
52use strict;
53use warnings;
54use warnings FATAL => 'redefine';
55
56use RT::Shredder::Constants;
57use RT::Shredder::Exceptions;
58
59=head2 _AsString
60
61Returns string in format ClassName-ObjectId.
62
63=cut
64
65sub _AsString { return ref($_[0]) ."-". $_[0]->id }
66
67=head2 _AsInsertQuery
68
69Returns INSERT query string that duplicates current record and
70can be used to insert record back into DB after delete.
71
72=cut
73
74sub _AsInsertQuery
75{
76 my $self = shift;
77
78 my $dbh = $RT::Handle->dbh;
79
80 my $res = "INSERT INTO ". $dbh->quote_identifier( $self->Table );
81 my $values = $self->{'values'};
82 $res .= "(". join( ",", map { $dbh->quote_identifier( $_ ) } sort keys %$values ) .")";
83 $res .= " VALUES";
84 $res .= "(". join( ",", map { $dbh->quote( $values->{$_} ) } sort keys %$values ) .")";
85 $res .= ";";
86
87 return $res;
88}
89
90sub BeforeWipeout { return 1 }
91
92=head2 Dependencies
93
94Returns L<RT::Shredder::Dependencies> object.
95
96=cut
97
98sub Dependencies
99{
100 my $self = shift;
101 my %args = (
102 Shredder => undef,
103 Flags => DEPENDS_ON,
104 @_,
105 );
106
107 unless( $self->id ) {
108 RT::Shredder::Exception->throw('Object is not loaded');
109 }
110
111 my $deps = RT::Shredder::Dependencies->new();
112 if( $args{'Flags'} & DEPENDS_ON ) {
113 $self->__DependsOn( %args, Dependencies => $deps );
114 }
84fb5b46
MKG
115 return $deps;
116}
117
118sub __DependsOn
119{
120 my $self = shift;
121 my %args = (
122 Shredder => undef,
123 Dependencies => undef,
124 @_,
125 );
126 my $deps = $args{'Dependencies'};
127 my $list = [];
128
129# Object custom field values
130 my $objs = $self->CustomFieldValues;
131 $objs->{'find_expired_rows'} = 1;
132 push( @$list, $objs );
133
134# Object attributes
135 $objs = $self->Attributes;
136 push( @$list, $objs );
137
138# Transactions
139 $objs = RT::Transactions->new( $self->CurrentUser );
140 $objs->Limit( FIELD => 'ObjectType', VALUE => ref $self );
141 $objs->Limit( FIELD => 'ObjectId', VALUE => $self->id );
142 push( @$list, $objs );
143
144# Links
af59614d
MKG
145 if ( $self->can('Links') ) {
146 # make sure we don't skip any record
147 no warnings 'redefine';
148 local *RT::Links::IsValidLink = sub { 1 };
149
84fb5b46 150 foreach ( qw(Base Target) ) {
af59614d 151 my $objs = $self->Links( $_ );
84fb5b46
MKG
152 $objs->_DoSearch;
153 push @$list, $objs->ItemsArrayRef;
154 }
155 }
156
157# ACE records
158 $objs = RT::ACL->new( $self->CurrentUser );
159 $objs->LimitToObject( $self );
160 push( @$list, $objs );
161
162 $deps->_PushDependencies(
163 BaseObject => $self,
164 Flags => DEPENDS_ON,
165 TargetObjects => $list,
166 Shredder => $args{'Shredder'}
167 );
168 return;
169}
170
84fb5b46
MKG
171# implement proxy method because some RT classes
172# override Delete method
173sub __Wipeout
174{
175 my $self = shift;
176 my $msg = $self->_AsString ." wiped out";
177 $self->SUPER::Delete;
178 $RT::Logger->info( $msg );
179 return;
180}
181
84fb5b46 1821;