[Rt-commit] rt branch, 4.0/shredder-leftovers, created. rt-4.0.7-63-ge80a3f5

Thomas Sibley trs at bestpractical.com
Fri Aug 2 19:09:11 EDT 2013


The branch, 4.0/shredder-leftovers has been created
        at  e80a3f50f1ce0edf9a39b1605b83b3e4060b1e1e (commit)

- Log -----------------------------------------------------------------
commit cbc1cd2bbb597f12ba364685be9f1c8355ef4c53
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Sep 17 16:10:04 2012 -0700

    Shredder: Target the specific group when resolving Owner membership
    
    Close over the group id instead of processing any Owner role group on
    the dependency stack.  Some Owner roles may want to be wiped.

diff --git a/lib/RT/Shredder/GroupMember.pm b/lib/RT/Shredder/GroupMember.pm
index 5f06fae..3e11800 100644
--- a/lib/RT/Shredder/GroupMember.pm
+++ b/lib/RT/Shredder/GroupMember.pm
@@ -92,6 +92,8 @@ sub __DependsOn
         return $self->SUPER::__DependsOn( %args );
     }
 
+    my $target_group_id = $group->id;
+
     # we don't delete group, so we have to fix Ticket and Group
     $deps->_PushDependencies(
                 BaseObject => $self,
@@ -106,8 +108,7 @@ sub __DependsOn
                 my %args = (@_);
                 my $group = $args{'TargetObject'};
                 return if $args{'Shredder'}->GetState( Object => $group ) & (WIPED|IN_WIPING);
-                return unless ($group->Type || '') eq 'Owner';
-                return unless ($group->Domain || '') eq 'RT::Ticket-Role';
+                return if $group->id != $target_group_id; # ensure we're resolving the right group
 
                 return if $group->MembersObj->Count > 1;
 

commit 1403be5ddd486873d45115a6bd140199087e631b
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Sep 17 16:12:25 2012 -0700

    Shredder: Wipeout the test objects as root to ensure SeeGroup doesn't interfere
    
    Otherwise the ticket role groups may be left behind, causing test
    failures.

diff --git a/t/shredder/03plugin_users.t b/t/shredder/03plugin_users.t
index 1f4cb49..9d3fafc 100644
--- a/t/shredder/03plugin_users.t
+++ b/t/shredder/03plugin_users.t
@@ -92,7 +92,13 @@ create_savepoint('clean');
     $transaction->Load($trid);
     is ( $transaction->Creator, $uidA, "ticket creator is now user A" );
 
-    $shredder->Wipeout( Object => $ticket );
-    $shredder->Wipeout( Object => $userA );
+    $ticket = RT::Ticket->new( RT->SystemUser );
+    $ticket->Load($tid);
+
+    $shredder->PutObject( Object => $ticket );
+    $shredder->WipeoutAll;
+
+    $shredder->PutObject( Object => $userA );
+    $shredder->WipeoutAll;
 }
 cmp_deeply( dump_current_and_savepoint('clean'), "current DB equal to savepoint");

commit 3fc1409fe42bedb59591bfad1c13341e8dcfeba5
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Sep 17 15:45:01 2012 -0700

    Shredder: Loop until all objects on the stack are WIPED
    
    Visit every object pushed onto the stack and wipe it.  This causes test
    failures because resolvable dependencies (with flags DEPENDS_ON |
    VARIABLE) are pushed onto the stack as well and should not be wiped.
    
    The previous fix, 5bdf351, switched from "while each" to "for values" to
    avoid the well-known side-effects of using each() when the hash is
    modified inside the loop (pushing on new dependent objects).  That
    commit fixed "skipped object" problems caused by an unpredictable
    each(), but didn't address the problem of objects pushed onto the stack
    after "values" was evaluated.

diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 4f96e16..9afe755 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -539,9 +539,11 @@ sub WipeoutAll
 {
     my $self = $_[0];
 
-    foreach my $cache_val ( values %{ $self->{'cache'} } ) {
-        next if $cache_val->{'State'} & (WIPED | IN_WIPING);
-        $self->Wipeout( Object => $cache_val->{'Object'} );
+    while (my @rec = grep { !($_->{State} & WIPED) } values %{ $self->{'cache'} }) {
+        for my $v (@rec) {
+            next if $v->{'State'} & IN_WIPING;
+            $self->Wipeout( Object => $v->{'Object'} );
+        }
     }
 }
 

commit e80a3f50f1ce0edf9a39b1605b83b3e4060b1e1e
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Sep 17 16:00:29 2012 -0700

    Shredder: Don't push resolvable dependencies onto the stack for wiping
    
    If a dependency is marked VARIABLE (resolvable), require it is handled
    by a resolver.  The resolver is free to put the object on the stack
    explicitly if resolution is not actually possible.
    
    Such objects were often safe because of the accidental side-effects of
    modifying the hash iterated by each() and later only calling values()
    once.  It is cleaner and safer to simply never push them onto the stack
    in the first place.  This lets you re-use shredder objects, for example,
    without inadvertently wiping objects you didn't mean to on the second
    call to WipeoutAll.

diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 9afe755..d7df662 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -450,8 +450,8 @@ sub _ParseRefStrArgs
     return '';
 }
 
-sub GetObject { return (shift)->GetRecord( @_ )->{'Object'} }
-sub GetState { return (shift)->GetRecord( @_ )->{'State'} }
+sub GetObject { return ((shift)->GetRecord( @_ ) || {})->{'Object'} }
+sub GetState { return ((shift)->GetRecord( @_ ) || {})->{'State'} }
 sub GetRecord
 {
     my $self = shift;
diff --git a/lib/RT/Shredder/Constants.pm b/lib/RT/Shredder/Constants.pm
index ba160ce..a9ef61e 100644
--- a/lib/RT/Shredder/Constants.pm
+++ b/lib/RT/Shredder/Constants.pm
@@ -84,6 +84,11 @@ This flag is used to mark dependencies that can be resolved with changing
 value in target object. For example ticket can be created by user we can
 change this reference when we delete user.
 
+Dependencies with the VARIABLE flag are B<not> pushed onto the stack of objects
+to be wiped, only the list of dependencies.  They must be handled by a resolver
+which either modifies the necessary values or pushes the object onto the stack
+with L<RT::Shredder/PutObject> if resolution is not possible.
+
 =head2 RELATES
 
 This flag is used to validate relationships integrity. Base object
diff --git a/lib/RT/Shredder/Dependencies.pm b/lib/RT/Shredder/Dependencies.pm
index 4b03cca..19ad8e4 100644
--- a/lib/RT/Shredder/Dependencies.pm
+++ b/lib/RT/Shredder/Dependencies.pm
@@ -105,14 +105,15 @@ sub _PushDependency
             Shredder => undef,
             @_
            );
-    my $rec = $args{'Shredder'}->PutObject( Object => $args{'TargetObject'} );
-    return if $rec->{'State'} & WIPED; # there is no object anymore
+    my $lookup = $args{Flags} & VARIABLE ? 'GetRecord' : 'PutObject';
+    my $rec = $args{'Shredder'}->$lookup( Object => $args{'TargetObject'} );
+    return if $rec and $rec->{'State'} & WIPED; # there is no object anymore
 
     push @{ $self->{'list'} },
         RT::Shredder::Dependency->new(
             BaseObject => $args{'BaseObject'},
             Flags => $args{'Flags'},
-            TargetObject => $rec->{'Object'},
+            TargetObject => $args{'TargetObject'},
         );
 
     if( scalar @{ $self->{'list'} } > ( $RT::DependenciesLimit || 1000 ) ) {
diff --git a/lib/RT/Shredder/GroupMember.pm b/lib/RT/Shredder/GroupMember.pm
index 3e11800..fce6e25 100644
--- a/lib/RT/Shredder/GroupMember.pm
+++ b/lib/RT/Shredder/GroupMember.pm
@@ -107,7 +107,7 @@ sub __DependsOn
             Code => sub {
                 my %args = (@_);
                 my $group = $args{'TargetObject'};
-                return if $args{'Shredder'}->GetState( Object => $group ) & (WIPED|IN_WIPING);
+                return if ($args{'Shredder'}->GetState( Object => $group ) || 0) & (WIPED|IN_WIPING);
                 return if $group->id != $target_group_id; # ensure we're resolving the right group
 
                 return if $group->MembersObj->Count > 1;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list