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

ruz at bestpractical.com ruz at bestpractical.com
Sun Aug 6 23:01:06 EDT 2006


Author: ruz
Date: Sun Aug  6 23:01:04 2006
New Revision: 5699

Added:
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base/
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base/Search.pm
Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Attachments.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Objects.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Users.pm

Log:
 r3595 at cubic-pc:  cubic | 2006-08-05 06:15:21 +0400
 * use lib/RT/Shredder/Plugin/Base/Search.pm as base for search plugins


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Attachments.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Attachments.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Attachments.pm	Sun Aug  6 23:01:04 2006
@@ -2,16 +2,12 @@
 
 use strict;
 use warnings FATAL => 'all';
-use base qw(RT::Shredder::Plugin::Base);
+use base qw(RT::Shredder::Plugin::Base::Search);
 
 =head1 NAME
 
 RT::Shredder::Plugin::Attachments - search plugin for wiping attachments.
 
-=cut
-
-sub Type { return 'search' }
-
 =head1 ARGUMENTS
 
 =head2 files_only - boolean value

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base.pm	Sun Aug  6 23:01:04 2006
@@ -37,14 +37,6 @@
 2) C<?> matches exactly one character.
 For example C<????> will match any string four characters long.
 
-=head1 ARGUMENTS
-
-Arguments which all plugins support.
-
-=head2 limit - unsigned integer
-
-Allow you to limit search results. B<< Default value is C<10> >>.
-
 =head1 METHODS
 
 =head2 for subclassing in plugins
@@ -67,13 +59,13 @@
 
 =cut
 
-sub SupportArgs { return qw(limit) }
+sub SupportArgs { return () }
 
 =head3 HasSupportForArgs
 
-Takes list of the argument names.
-Returns true if all arguments are supported by plugin
-and returns C<(0, $msg)> in other case.
+Takes a list of argument names. Returns true if
+all arguments are supported by plugin and returns
+C<(0, $msg)> in other case.
 
 =cut
 
@@ -105,16 +97,6 @@
 {
     my $self = shift;
     my %args = @_;
-    if( defined $args{'limit'} && $args{'limit'} ne '' ) {
-        my $limit = $args{'limit'};
-        $limit =~ s/[^0-9]//g;
-        unless( $args{'limit'} eq $limit ) {
-            return( 0, "Argmument limit should be an unsigned integer");
-        }
-        $args{'limit'} = $limit;
-    } else {
-        $args{'limit'} = 10;
-    }
     $self->{'opt'} = \%args;
     return 1;
 }
@@ -134,8 +116,6 @@
 
 sub Run { return (0, "This is abstract plugin, you couldn't use it directly") }
 
-sub SetResolvers { return (1) }
-
 =head2 utils
 
 =head3 ConvertMaskToSQL

Added: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base/Search.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Base/Search.pm	Sun Aug  6 23:01:04 2006
@@ -0,0 +1,55 @@
+package RT::Shredder::Plugin::Base::Search;
+
+use strict;
+use warnings FATAL => 'all';
+
+use base qw(RT::Shredder::Plugin::Base);
+
+=head1 NAME
+
+RT::Shredder::Plugin::Base - base class for Shredder plugins.
+
+=cut
+
+sub Type { return 'search' }
+
+=head1 ARGUMENTS
+
+Arguments which all plugins support.
+
+=head2 limit - unsigned integer
+
+Allow you to limit search results. B<< Default value is C<10> >>.
+
+=cut
+
+sub SupportArgs
+{
+    my %seen;
+    return sort
+        grep $_ && !$seen{$_},
+            shift->SUPER::SupportArgs(@_),
+            qw(limit);
+}
+
+sub TestArgs
+{
+    my $self = shift;
+    my %args = @_;
+    if( defined $args{'limit'} && $args{'limit'} ne '' ) {
+        my $limit = $args{'limit'};
+        $limit =~ s/[^0-9]//g;
+        unless( $args{'limit'} eq $limit ) {
+            return( 0, "'limit' should be an unsigned integer");
+        }
+        $args{'limit'} = $limit;
+    } else {
+        $args{'limit'} = 10;
+    }
+    return $self->SUPER::TestArgs( %args );
+}
+
+sub SetResolvers { return 1 }
+
+1;
+

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Objects.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Objects.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Objects.pm	Sun Aug  6 23:01:04 2006
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings FATAL => 'all';
-use base qw(RT::Shredder::Plugin::Base);
+use base qw(RT::Shredder::Plugin::Base::Search);
 
 use RT::Shredder;
 
@@ -10,10 +10,6 @@
 
 RT::Shredder::Plugin::Objects - search plugin for wiping any selected object.
 
-=cut
-
-sub Type { return 'search' }
-
 =head1 ARGUMENTS
 
 This plugin searches and RT object you want, so you can use
@@ -61,4 +57,3 @@
 }
 
 1;
-

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Shredder/Plugin/Tickets.pm	Sun Aug  6 23:01:04 2006
@@ -2,16 +2,12 @@
 
 use strict;
 use warnings FATAL => 'all';
-use base qw(RT::Shredder::Plugin::Base);
+use base qw(RT::Shredder::Plugin::Base::Search);
 
 =head1 NAME
 
 RT::Shredder::Plugin::Tickets - search plugin for wiping tickets.
 
-=cut
-
-sub Type { return 'search' }
-
 =head1 ARGUMENTS
 
 =head2 queue - queue name

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	Sun Aug  6 23:01:04 2006
@@ -8,10 +8,6 @@
 
 RT::Shredder::Plugin::Users - search plugin for wiping users.
 
-=cut
-
-sub Type { return 'search' }
-
 =head1 ARGUMENTS
 
 =head2 status - string
@@ -94,6 +90,10 @@
     my $self = shift;
     my %args = ( Shredder => undef, @_ );
     my $objs = RT::Users->new( $RT::SystemUser );
+    # XXX: we want preload only things we need, but later while
+    # logging we need all data, TODO envestigate this
+    # $objs->Columns(qw(id Name EmailAddress Lang Timezone
+    #                   Creator Created LastUpdated LastUpdatedBy));
     if( my $s = $self->{'opt'}{'status'} ) {
         if( $s eq 'any' ) {
             $objs->{'find_disabled_rows'} = 1;
@@ -194,9 +194,9 @@
     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
+    # 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
     $tickets->RowsPerPage(1);
     return !$tickets->First;
 }


More information about the Rt-commit mailing list