1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 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::Action::SetStatus;
53 use base qw(RT::Action);
57 RT::Action::SetStatus - RT's scrip action to set status of a ticket
61 This action changes status to a new value according to the rules in L</ARGUMENT>.
62 Status is not changed if the transition is invalid or another error occurs. All
63 issues are logged at apropriate levels.
67 Argument can be one of the following:
71 =item status literally
73 Status is changed from the current value to a new defined by the argument,
74 but only if it's valid status and allowed by transitions of the current lifecycle,
77 * The current status is 'stalled'
78 * Argument of this action is 'open'
79 * The only possible transition in the scheam from 'stalled' is 'open'
82 However, in the example above Status is not changed if argument is anything
83 else as it's just not allowed by the lifecycle.
85 =item 'initial', 'active' or 'inactive'
87 Status is changed from the current value to first possible 'initial',
88 'active' or 'inactive' correspondingly. First possible value is figured
89 according to transitions to the target set, for example:
91 * The current status is 'open'
92 * Argument of this action is 'inactive'
93 * Possible transitions from 'open' are 'resolved', 'rejected' or 'deleted'
94 * Status is changed to 'resolved'
103 my $ticket = $self->TicketObj;
104 my $lifecycle = $ticket->QueueObj->Lifecycle;
105 my $status = $ticket->Status;
107 my $argument = $self->Argument;
108 unless ( $argument ) {
109 $RT::Logger->error("Argument is mandatory for SetStatus action");
114 if ( $argument =~ /^(initial|active|inactive)$/i ) {
115 my $method = 'Is'. ucfirst lc $argument;
116 ($next) = grep $lifecycle->$method($_), $lifecycle->Transitions($status);
118 $RT::Logger->info("No transition from '$status' to $argument set");
122 elsif ( $lifecycle->IsValid( $argument ) ) {
123 unless ( $lifecycle->IsTransition( $status => $argument ) ) {
124 $RT::Logger->warning("Transition '$status -> $argument' is not valid");
130 $RT::Logger->error("Argument for SetStatus action is not valid status or one of set");
134 $self->{'set_status_to'} = $next;
142 return 1 unless my $new_status = $self->{'set_status_to'};
144 my ($val, $msg) = $self->TicketObj->SetStatus( $new_status );
146 $RT::Logger->error( "Couldn't set status: ". $msg );