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 }}}
54 use warnings FATAL => 'redefine';
56 use RT::Shredder::Constants;
57 use RT::Shredder::Exceptions;
61 Returns string in format ClassName-ObjectId.
65 sub _AsString { return ref($_[0]) ."-". $_[0]->id }
69 Returns INSERT query string that duplicates current record and
70 can be used to insert record back into DB after delete.
78 my $dbh = $RT::Handle->dbh;
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 ) .")";
84 $res .= "(". join( ",", map { $dbh->quote( $values->{$_} ) } sort keys %$values ) .")";
90 sub BeforeWipeout { return 1 }
94 Returns L<RT::Shredder::Dependencies> object.
107 unless( $self->id ) {
108 RT::Shredder::Exception->throw('Object is not loaded');
111 my $deps = RT::Shredder::Dependencies->new();
112 if( $args{'Flags'} & DEPENDS_ON ) {
113 $self->__DependsOn( %args, Dependencies => $deps );
115 if( $args{'Flags'} & RELATES ) {
116 $self->__Relates( %args, Dependencies => $deps );
126 Dependencies => undef,
129 my $deps = $args{'Dependencies'};
132 # Object custom field values
133 my $objs = $self->CustomFieldValues;
134 $objs->{'find_expired_rows'} = 1;
135 push( @$list, $objs );
138 $objs = $self->Attributes;
139 push( @$list, $objs );
142 $objs = RT::Transactions->new( $self->CurrentUser );
143 $objs->Limit( FIELD => 'ObjectType', VALUE => ref $self );
144 $objs->Limit( FIELD => 'ObjectId', VALUE => $self->id );
145 push( @$list, $objs );
148 if ( $self->can('_Links') ) {
149 # XXX: We don't use Links->Next as it's dies when object
150 # is linked to object that doesn't exist
151 # also, ->Next skip links to deleted tickets :(
152 foreach ( qw(Base Target) ) {
153 my $objs = $self->_Links( $_ );
155 push @$list, $objs->ItemsArrayRef;
160 $objs = RT::ACL->new( $self->CurrentUser );
161 $objs->LimitToObject( $self );
162 push( @$list, $objs );
164 $deps->_PushDependencies(
167 TargetObjects => $list,
168 Shredder => $args{'Shredder'}
178 Dependencies => undef,
181 my $deps = $args{'Dependencies'};
184 if( $self->_Accessible( 'Creator', 'read' ) ) {
185 my $obj = RT::Principal->new( $self->CurrentUser );
186 $obj->Load( $self->Creator );
188 if( $obj && defined $obj->id ) {
189 push( @$list, $obj );
191 my $rec = $args{'Shredder'}->GetRecord( Object => $self );
192 $self = $rec->{'Object'};
193 $rec->{'State'} |= INVALID;
194 push @{ $rec->{'Description'} },
195 "Have no related User(Creator) #". $self->Creator ." object";
199 if( $self->_Accessible( 'LastUpdatedBy', 'read' ) ) {
200 my $obj = RT::Principal->new( $self->CurrentUser );
201 $obj->Load( $self->LastUpdatedBy );
203 if( $obj && defined $obj->id ) {
204 push( @$list, $obj );
206 my $rec = $args{'Shredder'}->GetRecord( Object => $self );
207 $self = $rec->{'Object'};
208 $rec->{'State'} |= INVALID;
209 push @{ $rec->{'Description'} },
210 "Have no related User(LastUpdatedBy) #". $self->LastUpdatedBy ." object";
214 $deps->_PushDependencies(
217 TargetObjects => $list,
218 Shredder => $args{'Shredder'}
221 # cause of this $self->SUPER::__Relates should be called last
223 my $rec = $args{'Shredder'}->GetRecord( Object => $self );
224 $rec->{'State'} |= VALID unless( $rec->{'State'} & INVALID );
229 # implement proxy method because some RT classes
230 # override Delete method
234 my $msg = $self->_AsString ." wiped out";
235 $self->SUPER::Delete;
236 $RT::Logger->info( $msg );
240 sub ValidateRelations
247 unless( $args{'Shredder'} ) {
248 $args{'Shredder'} = new RT::Shredder();
251 my $rec = $args{'Shredder'}->PutObject( Object => $self );
252 return if( $rec->{'State'} & VALID );
253 $self = $rec->{'Object'};
255 $self->_ValidateRelations( %args, Flags => RELATES );
256 $rec->{'State'} |= VALID unless( $rec->{'State'} & INVALID );
261 sub _ValidateRelations
266 my $deps = $self->Dependencies( %args );
268 $deps->ValidateRelations( %args );