CloseAll

From Request Tracker Wiki
Jump to navigation Jump to search

CloseAll

Simple perl script to change all TT, but the one in state deleted, in a queue to Resolved

Take one argument "queue name"

#!/usr/bin/perl -w
 
 use strict;
 use Carp;
 use Getopt::Long;
 
 use lib '/http/www/rt-3.4.5/lib';
 use lib '/http/www/rt-3.4.5/etc';
 
 use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
 CleanEnv();
 
 use RT;
 use RT::Ticket;
 use RT::Tickets;
 
 #Load RT's config file
 RT::LoadConfig();
 
 # Connect to the database. set up loggign
 RT::Init();
 
 #Get the current queue all loaded
 my $queue = shift || '--help';
 
 if ($queue eq '--help') {
 print <<END;
 closeall <queue>
 END
 exit(0);
 }
 
 my $Tickets = new RT::Tickets($RT::SystemUser);
 $Tickets->LimitWatcher(TYPE => 'Queue', VALUE => $queue);
 $Tickets->LimitStatus(VALUE => 'Deleted', OPERATOR => '!=');
 
 unless ($Tickets->Count) {
 print "tickets not found with queue $queue\n";
 }
 print "Amount of tickets in $queue is ".$Tickets->Count."\n";
 
 while (my $t=$Tickets->Next) {
 my ($val,$msg) = $t->Resolve();
 if ($val) {
 print "OK: $msg\n";
 } else {
 print "Not Ok: $msg\n";
 }
 }
 
 $RT::Handle->Disconnect();