]> git.uio.no Git - usit-rt.git/blobdiff - lib/RT/Shredder.pm
Master to 4.2.8
[usit-rt.git] / lib / RT / Shredder.pm
index 40c73b36d4f36f6be3b2dc49aed1062fafa5574e..bda5a39fa3e31b16771068798787526845d13025 100644 (file)
@@ -2,7 +2,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -105,7 +105,7 @@ See also 'rt-shredder --help'.
 =head2 Web based interface (WebUI)
 
 Shredder's WebUI integrates into RT's WebUI.  You can find it in the
-Configuration->Tools->Shredder tab.  The interface is similar to the
+Admin->Tools->Shredder tab.  The interface is similar to the
 CLI and gives you the same functionality. You can find 'Shredder' link
 at the bottom of tickets search results, so you could wipeout tickets
 in the way similar to the bulk update.
@@ -164,6 +164,23 @@ your F<RT_SiteConfig.pm>:
 
 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);
+
+    CREATE UNIQUE INDEX SHREDDER_GM1 ON GroupMembers(MemberId, GroupId);
+
+    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
 
@@ -195,7 +212,6 @@ objects in the cache and backups storage.
 
 =cut
 
-our $VERSION = '0.04';
 use File::Spec ();
 
 
@@ -274,6 +290,7 @@ sub Init
     %opt = @_;
     RT::LoadConfig();
     RT::Init();
+    return;
 }
 
 =head4 new
@@ -290,8 +307,7 @@ sub new
 {
     my $proto = shift;
     my $self = bless( {}, ref $proto || $proto );
-    $self->_Init( @_ );
-    return $self;
+    return $self->_Init( @_ );
 }
 
 sub _Init
@@ -301,6 +317,7 @@ sub _Init
     $self->{'cache'}        = {};
     $self->{'resolver'}     = {};
     $self->{'dump_plugins'} = [];
+    return $self;
 }
 
 =head4 CastObjectsToRecords( Objects => undef )
@@ -354,8 +371,7 @@ sub CastObjectsToRecords
         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 $@;
+        $class->require or die "Failed to load $class: $@";
         my $obj = $class->new( RT->SystemUser );
         die "Couldn't construct new '$class' object" unless $obj;
         $obj->Load( $id );
@@ -539,10 +555,11 @@ 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'} );
     }
+    return;
 }
 
 sub Wipeout
@@ -563,6 +580,7 @@ sub Wipeout
         die $error if RT::Shredder::Exception::Info->caught;
         die "Couldn't wipeout object: $error";
     }
+    return;
 }
 
 sub _Wipeout
@@ -611,17 +629,6 @@ sub _Wipeout
     return;
 }
 
-sub ValidateRelations
-{
-    my $self = shift;
-    my %args = ( @_ );
-
-    foreach my $record( values %{ $self->{'cache'} } ) {
-        next if( $record->{'State'} & VALID );
-        $record->{'Object'}->ValidateRelations( Shredder => $self );
-    }
-}
-
 =head3 Data storage and backups
 
 =head4 GetFileName( FileName => '<ISO DATETIME>-XXXX.sql', FromStorage => 1 )
@@ -720,7 +727,7 @@ sub GetFileName
 =head4 StoragePath
 
 Returns an absolute path to the storage dir.  See
-L<CONFIGURATION/$ShredderStoragePath>.
+L</$ShredderStoragePath>.
 
 See also description of the L</GetFileName> method.
 
@@ -771,6 +778,7 @@ sub DumpObject {
         my ($state, $msg) = $_->Run( %args );
         die "Couldn't run plugin: $msg" unless $state;
     }
+    return;
 }
 
 { my $mark = 1; # XXX: integer overflows?
@@ -786,9 +794,10 @@ sub PushDumpMark {
 sub PopDumpMark {
     my $self = shift;
     foreach (@{ $self->{'dump_plugins'} }) {
-        my ($state, $msg) = $_->PushMark( @_ );
+        my ($state, $msg) = $_->PopMark( @_ );
         die "Couldn't pop mark: $msg" unless $state;
     }
+    return;
 }
 sub RollbackDumpTo {
     my $self = shift;
@@ -796,6 +805,7 @@ sub RollbackDumpTo {
         my ($state, $msg) = $_->RollbackTo( @_ );
         die "Couldn't rollback to mark: $msg" unless $state;
     }
+    return;
 }
 }