[Rt-commit] r5417 - in rt/branches/3.7-EXPERIMENTAL: . lib/RT/Shredder/Plugin

ruz at bestpractical.com ruz at bestpractical.com
Thu Jun 22 20:53:11 EDT 2006


Author: ruz
Date: Thu Jun 22 20:53:10 2006
New Revision: 5417

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/index.html
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Users.pm

Log:
 r3304 at cubic-pc:  cubic | 2006-06-23 05:02:32 +0400
  r3303 at cubic-pc:  cubic | 2006-06-23 05:02:21 +0400
  * new option 'no_tickets' in RT::Shredder::Plugin::Users
 


Modified: rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/index.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/index.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Admin/Tools/Shredder/index.html	Thu Jun 22 20:53:10 2006
@@ -38,7 +38,7 @@
         $Search = ''; @objs = ();
         return 1;
     }
-    if ( UNIVERSAL::isa( $@, Class::Exception ) ) {
+    if ( UNIVERSAL::isa( $@, 'Class::Exception' ) ) {
         $@->rethrow;
     } else {
         die $@;

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Users.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Users.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Users.pm	Thu Jun 22 20:53:10 2006
@@ -38,12 +38,20 @@
 
 This argument could be user id or name.
 
+=head2 no_tickets - boolean
+
+If true then plugin looks for users who are not watchers (Owners,
+Requestors, Ccs or AdminCcs) of any ticket.
+
+B<Note> that found users still may have relations with other objects
+and you most probably want to use C<replace_relations> option.
+
 =cut
 
 sub SupportArgs
 {
     return $_[0]->SUPER::SupportArgs,
-           qw(status name email replace_relations);
+           qw(status name email replace_relations no_tickets);
 }
 
 sub TestArgs
@@ -86,17 +94,17 @@
     my $self = shift;
     my %args = ( Shredder => undef, @_ );
     my $objs = RT::Users->new( $RT::SystemUser );
-    if( $self->{'opt'}{'status'} ) {
-        my $s = $self->{'opt'}{'status'};
+    if( my $s = $self->{'opt'}{'status'} ) {
         if( $s eq 'any' ) {
             $objs->{'find_disabled_rows'} = 1;
         } elsif( $s eq 'disabled' ) {
             $objs->{'find_disabled_rows'} = 1;
-            $objs->Limit( ALIAS => $objs->PrincipalsAlias,
-                      FIELD    => 'Disabled',
-                      OPERATOR => '!=',
-                      VALUE    => '0',
-                    );
+            $objs->Limit(
+                ALIAS => $objs->PrincipalsAlias,
+                FIELD    => 'Disabled',
+                OPERATOR => '!=',
+                VALUE    => '0',
+            );
         } else {
             $objs->LimitToEnabled;
         }
@@ -113,8 +121,16 @@
                   VALUE => $self->{'opt'}{'name'},
                 );
     }
-    if( $self->{'opt'}{'limit'} ) {
-        $objs->RowsPerPage( $self->{'opt'}{'limit'} );
+
+    if( $self->{'opt'}{'no_tickets'} ) {
+        return $self->FilterWithoutTickets(
+            Shredder => $args{'Shredder'},
+            Objects  => $objs,
+        );
+    } else {
+        if( $self->{'opt'}{'limit'} ) {
+            $objs->RowsPerPage( $self->{'opt'}{'limit'} );
+        }
     }
     return (1, $objs);
 }
@@ -139,4 +155,50 @@
     return (1);
 }
 
+use constant PAGE_SIZE => 100;
+
+sub FetchNext {
+    my ($self, $objs, $init) = @_;
+    if ( $init ) {
+        $objs->RowsPerPage( PAGE_SIZE );
+        $objs->FirstPage;
+        return;
+    }
+
+    for (1..3) {
+        my $obj = $objs->Next;
+        return $obj if $obj;
+        $objs->NextPage;
+    }
+}
+
+sub FilterWithoutTickets {
+    my $self = shift;
+    my %args = (
+        Shredder => undef,
+        Objects  => undef,
+        @_,
+    );
+    my $users = $args{Objects};
+    $self->FetchNext( $users, 'init' );
+
+    my @res;
+    while ( my $user = $self->FetchNext( $users ) ) {
+        push @res, $user if $self->_WithoutTickets( $user );
+        return (1, \@res) if $self->{'opt'}{'limit'} && @res >= $self->{'opt'}{'limit'};
+    }
+    return (1, \@res);
+}
+
+sub _WithoutTickets {
+    my ($self, $user) = @_;
+    my $tickets = RT::Tickets->new( $RT::SystemUser );
+    $tickets->FromSQL( 'Watcher.id = '. $user->id );
+    # HACK: Count - is count all that match condtion,
+    # but we really want to know if at least one record record exist,
+    # so we fetch first only
+    $tickets->RowsPerPage(1);
+    return !$tickets->First;
+}
+
 1;


More information about the Rt-commit mailing list