X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FShredder%2FPlugin%2FUsers.pm;h=0073a9e97f1b986c32f1e1c5429311befff4b8e9;hp=7e1c31f7766610d9305853e8e4171c2560ca1350;hb=7322f2afedcc2f427e997d1535a503613a83f088;hpb=ae14e320388fa5e7f400bff1c251ef885b7952e6 diff --git a/rt/lib/RT/Shredder/Plugin/Users.pm b/rt/lib/RT/Shredder/Plugin/Users.pm index 7e1c31f77..0073a9e97 100644 --- a/rt/lib/RT/Shredder/Plugin/Users.pm +++ b/rt/lib/RT/Shredder/Plugin/Users.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -108,12 +108,21 @@ Note that found users still B with other objects, for example via Creator or LastUpdatedBy fields, and you most probably want to use C option. +=head2 no_ticket_transactions - boolean + +If true then plugin looks for users who have created no ticket transactions. +This is especially useful after wiping out tickets. + +Note that found users still B with other objects, +for example via Creator or LastUpdatedBy fields, and you most probably +want to use C option. + =cut sub SupportArgs { return $_[0]->SUPER::SupportArgs, - qw(status name email member_of not_member_of replace_relations no_tickets); + qw(status name email member_of not_member_of replace_relations no_tickets no_ticket_transactions); } sub TestArgs @@ -209,6 +218,11 @@ sub Run Shredder => $args{'Shredder'}, ); } + if( $self->{'opt'}{'no_ticket_transactions'} ) { + push @filter, $self->FilterWithoutTicketTransactions( + Shredder => $args{'Shredder'}, + ); + } if (@filter) { $self->FetchNext( $objs, 'init' ); @@ -284,11 +298,40 @@ sub _WithoutTickets { my $tickets = RT::Tickets->new( RT->SystemUser ); $tickets->{'allow_deleted_search'} = 1; $tickets->FromSQL( 'Watcher.id = '. $user->id ); - # HACK: we may use Count method which counts all records - # that match condtion, but we really want to know only that - # at least one record exist, so we fetch first row only + + # we could use the Count method which counts all records + # that match, but we really want to know only that + # at least one record exists, so this is faster $tickets->RowsPerPage(1); return !$tickets->First; } +sub FilterWithoutTicketTransactions { + my $self = shift; + my %args = ( + Shredder => undef, + Objects => undef, + @_, + ); + + return sub { + my $user = shift; + $self->_WithoutTicketTransactions( $user ) + }; +} + +sub _WithoutTicketTransactions { + my ($self, $user) = @_; + return unless $user and $user->Id; + my $txns = RT::Transactions->new( RT->SystemUser ); + $txns->Limit(FIELD => 'ObjectType', VALUE => 'RT::Ticket'); + $txns->Limit(FIELD => 'Creator', VALUE => $user->Id); + + # we could use the Count method which counts all records + # that match, but we really want to know only that + # at least one record exists, so this is faster + $txns->RowsPerPage(1); + return !$txns->First; +} + 1;