[rt-devel] [contrib] SetStatus ScripAction
Bruce Campbell
bruce_campbell at ripe.net
Sun Dec 22 11:54:41 EST 2002
On Fri, 26 Apr 2002, Phil Homewood wrote:
> Subject: [rt-devel] [contrib] OpenTicket ScripAction
>
> This very simple ScripAction will change a "new" ticket's status
> to "open".
I've extended this, to be able to set the status to any possible status
that RT::Ticket->SetStatus will accept. The status can be defined in the
Argument, or in the Template.
Suggested usage:
with Argument (being just 'resolved'):
OnSomeCondition SetResolved with Template Blank
or
OnCorrespondWhenNew SetOpen with Template Blank
with Template (containing just the word 'resolved'):
OnSomeCondition SetStatus with Template Resolved
Installation instructions:
Copy SetStatus.pm to lib/RT/Action/ as SetStatus.pm
Edit insert_action_SetStatus.pl for your local RT directories, and
referring to the example, choose the name of the Action(s) you
wish to create. By default, the following would be created:
SetStatus, SetResolved, SetNew, SetOpen, SetStalled
Run insert_action_SetStatus.pl to create these.
--
Bruce Campbell RIPE
Systems/Network Engineer NCC
www.ripe.net - PGP562C8B1B Operations/Security
-------------- next part --------------
# SetStatus - change the status of a ticket.
# Bruce Campbell <bruce.campbell at ripe.net> 20021220
package RT::Action::SetStatus;
require RT::Action::Generic;
@ISA = qw(RT::Action::Generic);
# {{{ sub Prepare
sub Prepare {
my $self = shift;
my $retval = undef;
# We're Prepared if the ticket is not what we want to change it to.
# The template or argument contains one word.
my $newstatus = "";
if( defined( $self->Argument ) ){
if( $self->Argument !~ /^\s*$/ ){
$newstatus = $self->Argument;
}
}
if( $newstatus =~ /^\s*$/ ){
$newstatus = join( ' ', split( /\n/, $self->TemplateObj->Content ) );
}
$RT::Logger->debug( "$self: Thinking of $newstatus for status" );
if( $newstatus =~ /^\s*(\S+)\s*$/sm ){
$newstatus = lc( $1 );
$self->{'_ToSet'} = $newstatus;
$retval = 1 if( $self->TicketObj->Status ne $newstatus );
}else{
$self->{'_ToSet'} = undef;
}
return( $retval );
}
# }}}
sub Commit {
my $self = shift;
# Gotta check that the status is still new, other scrips may have
# committed after the Prepare().
if( defined( $self->{'_ToSet'} ) ){
$RT::Logger->debug( "$self: About to attempt to set Status to " . $self->{'_ToSet'} );
return ($self->TicketObj->SetStatus( $self->{'_ToSet'} ) );
}else{
return( undef );
}
}
1;
-------------- next part --------------
#!/usr/bin/perl -w
# Generic insertScripAction Script, original version probably by Jesse
# Vincent. Reordered by Bruce Campbell.
#
############# USER SERVICEABLE PARTS #####################################
#### Set to your local RT directory.
use lib "!! THIS SHOULD BE YOUR RT LIB DIRECTORY !!";
use lib "!! THIS SHOULD BE YOUR RT ETC DIRECTORY !!";
#### Change as appropriate for the ScripAction that you are installing
#### This creates the following ScripActions.
my @ScripActions = (
{
Name => 'SetStatus',
Description => 'Changes the ticket status according to the Template',
ExecModule => 'SetStatus',
Argument => '',
},
{
Name => 'SetResolved',
Description => 'Changes the ticket status to resolved',
ExecModule => 'SetStatus',
Argument => 'resolved',
},
{
Name => 'SetNew',
Description => 'Changes the ticket status to new',
ExecModule => 'SetStatus',
Argument => 'new',
},
{
Name => 'SetOpen',
Description => 'Changes the ticket status to open',
ExecModule => 'SetStatus',
Argument => 'open',
},
{
Name => 'SetStalled',
Description => 'Changes the ticket status to stalled',
ExecModule => 'SetStatus',
Argument => 'stalled',
},
);
#### Remember to comment these two lines out.
print "You need to edit this file before running it.\n";
exit 1;
############# NO USER SERVICEABLE PARTS BELOW ############################
package RT;
use strict;
use vars qw($VERSION $Handle $Nobody $SystemUser $item);
#This drags in RT's config.pm
use config;
use Carp;
use RT::Handle;
use RT::User;
use RT::CurrentUser;
#connect to the db
$RT::Handle = new RT::Handle($RT::DatabaseType);
$RT::Handle->Connect();
#Put together a current user object so we can create a User object
my $CurrentUser = new RT::CurrentUser();
#now that we bootstrapped that little bit, we can use the standard RT cli
# helpers to do what we need
use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
GetCurrentUser GetMessageContent);
#Clean out all the nasties from the environment
CleanEnv();
#Load etc/config.pm and drop privs
LoadConfig();
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
DBConnect();
$CurrentUser->LoadByName('RT_System');
print "Creating ScripActions...";
use RT::ScripAction;
for $item (@ScripActions) {
my $new_entry = new RT::ScripAction($CurrentUser);
my $return = $new_entry->Create(%$item);
print $return.".";
}
print "done.\n";
$RT::Handle->Disconnect();
1;
More information about the Rt-devel
mailing list