This commit was generated by cvs2svn to compensate for changes in r2526,
[freeside.git] / rt / lib / RT / Action / StallDependent.pm
1 # This Action will stall the BASE if a dependency or membership link
2 # (according to argument) is created and if BASE is open.
3
4 # TODO: Rename this .pm
5
6 package RT::Action::StallDependent;
7 require RT::Action::Generic;
8 @ISA=qw|RT::Action::Generic|;
9
10 # {{{ sub Describe 
11 sub Describe  {
12   my $self = shift;
13   return (ref $self . " will stall a [local] BASE if it's dependent [or member] of a linked up request.");
14 }
15 # }}}
16
17
18 # {{{ sub Prepare 
19 sub Prepare  {
20     # nothing to prepare
21     return 1;
22 }
23 # }}}
24
25 sub Commit {
26     my $self = shift;
27     # Find all Dependent
28     my $arg=$self->Argument || "DependsOn";
29     unless ($self->TransactionObj->Data =~ /^([^ ]+) $arg /) {
30         warn; return 0;
31     }
32     my $base_id=$1;
33     my $base;
34     if ($1 eq "THIS") {
35         $base=$self->TicketObj;
36     } else {
37         $base_id=&RT::Link::_IsLocal(undef, $base_id) || return 0;
38         $base=RT::Ticket->new($self->TicketObj->CurrentUser);
39         $base->Load($base_id);
40     }
41     $base->Stall if $base->Status eq 'open';
42     return 0;
43 }
44
45
46 # {{{ sub IsApplicable 
47
48 # Only applicable if:
49 # 1. the link action is a dependency
50 # 2. BASE is a local ticket
51
52 sub IsApplicable  {
53   my $self = shift;
54
55   my $arg=$self->Argument || "DependsOn";
56
57   # 1:
58   $self->TransactionObj->Data =~ /^([^ ]*) $arg / || return 0;
59
60   # 2:
61   # (dirty!)
62   &RT::Link::_IsLocal(undef,$1) || return 0;
63
64   return 1;
65 }
66 # }}}
67
68 1;