1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
49 package RT::Shredder::Plugin::Tickets;
52 use warnings FATAL => 'all';
53 use base qw(RT::Shredder::Plugin::Base::Search);
57 RT::Shredder::Plugin::Tickets - search plugin for wiping tickets.
61 =head2 query - query string
63 Search tickets with query string.
65 Queue = 'my queue' AND ( Status = 'deleted' OR Status = 'rejected' )
66 LastUpdated < '2003-12-31 23:59:59'
68 B<Hint:> You can construct query with the query builder in RT's web
69 interface and then open advanced page and copy query string.
71 Arguments C<queue>, C<status> and C<updated_before> have been dropped
72 as you can easy make the same search with the C<query> option.
75 =head2 with_linked - boolen
77 Deletes all tickets that are linked to tickets that match L<query>.
79 =head2 apply_query_to_linked - boolean
81 Delete linked tickets only if those too match L<query>.
83 See also L<with_linked>.
87 sub SupportArgs { return $_[0]->SUPER::SupportArgs, qw(query with_linked apply_query_to_linked) }
94 if( $args{'query'} ) {
95 my $objs = RT::Tickets->new( RT->SystemUser );
96 $objs->{'allow_deleted_search'} = 1;
97 my ($status, $msg) = $objs->FromSQL( $args{'query'} );
98 return( 0, "Bad query argument, error: $msg" ) unless $status;
99 $self->{'opt'}{'objects'} = $objs;
101 $args{'with_linked'} = 1 if $args{'apply_query_to_linked'};
103 return $self->SUPER::TestArgs( %args );
109 my $objs = $self->{'opt'}{'objects'}
110 or return (1, undef);
112 $objs->OrderByCols( { FIELD => 'id', ORDER => 'ASC' } );
113 unless ( $self->{'opt'}{'with_linked'} ) {
114 if( $self->{'opt'}{'limit'} ) {
115 $objs->RowsPerPage( $self->{'opt'}{'limit'} );
120 my (@top, @linked, %seen);
121 $self->FetchNext($objs, 1);
122 while ( my $obj = $self->FetchNext( $objs ) ) {
123 next if $seen{ $obj->id }++;
124 push @linked, $self->GetLinked( Object => $obj, Seen => \%seen );
126 last if $self->{'opt'}{'limit'}
127 && @top >= $self->{'opt'}{'limit'};
129 return (1, @top, @linked);
137 my $query = 'Linked = '. $arg{'Object'}->id;
138 if ( $self->{'opt'}{'apply_query_to_linked'} ) {
139 $query .= " AND ( ". $self->{'opt'}{'query'} ." )";
141 my $objs = RT::Tickets->new( RT->SystemUser );
142 $objs->{'allow_deleted_search'} = 1;
143 $objs->FromSQL( $query );
144 $self->FetchNext( $objs, 1 );
145 while ( my $linked_obj = $self->FetchNext( $objs ) ) {
146 next if $arg{'Seen'}->{ $linked_obj->id }++;
147 push @res, $self->GetLinked( %arg, Object => $linked_obj );
148 push @res, $linked_obj;