X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FShredder.pm;h=e4cb157aefb4054fb7c334ac42d936dda58c6d42;hb=919e930aa9279b3c5cd12b593889cd6de79d67bf;hp=024a50ba4ff184685d1fd91de041c21a71c4c60b;hpb=fc6209f398899f0211cfcedeb81a3cd65e04a941;p=freeside.git diff --git a/rt/lib/RT/Shredder.pm b/rt/lib/RT/Shredder.pm index 024a50ba4..e4cb157ae 100644 --- a/rt/lib/RT/Shredder.pm +++ b/rt/lib/RT/Shredder.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -52,6 +52,7 @@ use strict; use warnings; + =head1 NAME RT::Shredder - Permanently wipeout data from RT @@ -61,8 +62,7 @@ RT::Shredder - Permanently wipeout data from RT =head2 CLI - rt-shredder --force --plugin 'Tickets=queue,general;status,deleted' - + rt-shredder --force --plugin 'Tickets=query,Queue="General" and Status="deleted"' =head1 DESCRIPTION @@ -138,29 +138,49 @@ shredding session when the file had been created. =head1 CONFIGURATION -=head2 $RT::DependenciesLimit +=head2 $DependenciesLimit Shredder stops with an error if the object has more than -C<$RT::DependenciesLimit> dependencies. For example: a ticket has 1000 +C<$DependenciesLimit> dependencies. For example: a ticket has 1000 transactions or a transaction has 1000 attachments. This is protection from bugs in shredder from wiping out your whole database, but sometimes when you have big mail loops you may hit it. -Defaults to 1000. +Defaults to 1000. To change this (for example, to 10000) add the +following to your F: -You can change the default value, in F add C + Set( $DependenciesLimit, 10_000 );> =head2 $ShredderStoragePath -Directory containing Shredder backup dumps. +Directory containing Shredder backup dumps; defaults to +F (assuming an /opt/rt4 installation). + +To change this (for example, to /some/backup/path) add the following to +your F: + + Set( $ShredderStoragePath, "/some/backup/path" );> + +Be sure to specify an absolute path. + +=head1 Database Indexes + +We have found that the following indexes significantly speed up +shredding on most databases. + + CREATE INDEX SHREDDER_CGM1 ON CachedGroupMembers(MemberId, GroupId, Disabled); + CREATE INDEX SHREDDER_CGM2 ON CachedGroupMembers(ImmediateParentId,MemberId); + CREATE INDEX SHREDDER_CGM3 on CachedGroupMembers (Via, Id); -Defaults to F. + CREATE UNIQUE INDEX SHREDDER_GM1 ON GroupMembers(MemberId, GroupId); -You can change the default value, in F add C Be sure to use an absolute path. + CREATE INDEX SHREDDER_TXN1 ON Transactions(ReferenceType, OldReference); + CREATE INDEX SHREDDER_TXN2 ON Transactions(ReferenceType, NewReference); + CREATE INDEX SHREDDER_TXN3 ON Transactions(Type, OldValue); + CREATE INDEX SHREDDER_TXN4 ON Transactions(Type, NewValue); + CREATE INDEX SHREDDER_ATTACHMENTS1 ON Attachments(Creator); =head1 INFORMATION FOR DEVELOPERS @@ -176,7 +196,7 @@ example from L: use RT::Shredder; RT::Shredder::Init( force => 1 ); - my $deleted = RT::Tickets->new( $RT::SystemUser ); + my $deleted = RT::Tickets->new( RT->SystemUser ); $deleted->{'allow_deleted_search'} = 1; $deleted->LimitQueue( VALUE => 'general' ); $deleted->LimitStatus( VALUE => 'deleted' ); @@ -202,7 +222,6 @@ BEGIN { # RT lib path ### after: push @INC, qw(@RT_LIB_PATH@); - push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib); use RT::Shredder::Constants; use RT::Shredder::Exceptions; @@ -349,10 +368,12 @@ sub CastObjectsToRecords } elsif ( UNIVERSAL::isa( $targets, 'SCALAR' ) || !ref $targets ) { $targets = $$targets if ref $targets; my ($class, $id) = split /-/, $targets; + RT::Shredder::Exception->throw( "Unsupported class $class" ) + unless $class =~ /^\w+(::\w+)*$/; $class = 'RT::'. $class unless $class =~ /^RTx?::/i; eval "require $class"; die "Couldn't load '$class' module" if $@; - my $obj = $class->new( $RT::SystemUser ); + my $obj = $class->new( RT->SystemUser ); die "Couldn't construct new '$class' object" unless $obj; $obj->Load( $id ); unless ( $obj->id ) { @@ -535,9 +556,9 @@ sub WipeoutAll { my $self = $_[0]; - while ( my ($k, $v) = each %{ $self->{'cache'} } ) { - next if $v->{'State'} & (WIPED | IN_WIPING); - $self->Wipeout( Object => $v->{'Object'} ); + foreach my $cache_val ( values %{ $self->{'cache'} } ) { + next if $cache_val->{'State'} & (WIPED | IN_WIPING); + $self->Wipeout( Object => $cache_val->{'Object'} ); } } @@ -553,10 +574,11 @@ sub Wipeout die "Couldn't commit transaction" unless $RT::Handle->Commit; }; if( $@ ) { + my $error = $@; $RT::Handle->Rollback('force'); $self->RollbackDumpTo( Mark => $mark ) if $mark; - die $@ if RT::Shredder::Exception::Info->caught; - die "Couldn't wipeout object: $@"; + die $error if RT::Shredder::Exception::Info->caught; + die "Couldn't wipeout object: $error"; } } @@ -715,7 +737,7 @@ sub GetFileName =head4 StoragePath Returns an absolute path to the storage dir. See -L. +L. See also description of the L method.