diff options
| author | mark <mark> | 2010-11-17 20:44:11 +0000 | 
|---|---|---|
| committer | mark <mark> | 2010-11-17 20:44:11 +0000 | 
| commit | 5ef064aeca4a22dbe38b538e65d512d5d398fe2f (patch) | |
| tree | 81959e7fd86bc537b61cf530983df26b01ca4fba /rt/lib | |
| parent | 2a874cdff2e2bc0d5d6920aae306d5b7c3d4aa97 (diff) | |
create ticket on custom field change, RT#10139
Diffstat (limited to 'rt/lib')
| -rwxr-xr-x | rt/lib/RT/Action.pm | 11 | ||||
| -rw-r--r-- | rt/lib/RT/Action/CreateTickets.pm | 19 | ||||
| -rwxr-xr-x | rt/lib/RT/Condition.pm | 13 | ||||
| -rw-r--r-- | rt/lib/RT/Condition/CustomFieldChange.pm | 56 | ||||
| -rw-r--r-- | rt/lib/RT/Scrip_Overlay.pm | 4 | 
5 files changed, 103 insertions, 0 deletions
diff --git a/rt/lib/RT/Action.pm b/rt/lib/RT/Action.pm index 1918a7e37..42bf767e7 100755 --- a/rt/lib/RT/Action.pm +++ b/rt/lib/RT/Action.pm @@ -204,6 +204,17 @@ sub IsApplicable  {  }  # }}} +sub Options { +  my $self = shift; +  return(); +} + +sub Rules { +  my $self = shift; +  return () if !$self->ScripObj or !$self->ScripObj->ActionRules; +  return(split "\n", $self->ScripObj->ActionRules); +} +  # {{{ sub DESTROY  sub DESTROY {      my $self = shift; diff --git a/rt/lib/RT/Action/CreateTickets.pm b/rt/lib/RT/Action/CreateTickets.pm index 4883ae3a8..74520ca69 100644 --- a/rt/lib/RT/Action/CreateTickets.pm +++ b/rt/lib/RT/Action/CreateTickets.pm @@ -762,6 +762,7 @@ sub ParseLines {          FinalPriority   => $args{'finalpriority'} || 0,          SquelchMailTo   => $args{'squelchmailto'},          Type            => $args{'type'}, +        $self->Rules      );      if ( $args{content} ) { @@ -1238,6 +1239,24 @@ sub PostProcess {  } +sub Options { +  my $self = shift; +  my $queues = RT::Queues->new($self->CurrentUser); +  $queues->UnLimit; +  my @names; +  while (my $queue = $queues->Next) { +    push @names, $queue->Id, $queue->Name; +  } +  return ( +    { +      'name'    => 'Queue', +      'label'   => 'In queue', +      'type'    => 'select', +      'options' => \@names +    } +  ) +} +  eval "require RT::Action::CreateTickets_Vendor";  die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Action/CreateTickets_Vendor.pm} );  eval "require RT::Action::CreateTickets_Local"; diff --git a/rt/lib/RT/Condition.pm b/rt/lib/RT/Condition.pm index be7c4c56d..dfd58e757 100755 --- a/rt/lib/RT/Condition.pm +++ b/rt/lib/RT/Condition.pm @@ -210,6 +210,19 @@ sub IsApplicable  {  }  # }}} +sub Options { +  my $self = shift; +  return(); +} + +sub Rules { +  my $self = shift; +  return () if !$self->ScripObj or !$self->ScripObj->ConditionRules; +  # By default, option names and values are on consecutive lines. +  # Override this if you need anything more interesting. +  return(split "\n", $self->ScripObj->ConditionRules); +} +  # {{{ sub DESTROY  sub DESTROY {      my $self = shift; diff --git a/rt/lib/RT/Condition/CustomFieldChange.pm b/rt/lib/RT/Condition/CustomFieldChange.pm new file mode 100644 index 000000000..b9228a50f --- /dev/null +++ b/rt/lib/RT/Condition/CustomFieldChange.pm @@ -0,0 +1,56 @@ +package RT::Condition::CustomFieldChange; +use base 'RT::Condition'; +use strict; + +=head2 IsApplicable + +If a custom field has a particular value. + +=cut + +# Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06 + +sub IsApplicable { +    my $self = shift; +    my $trans = $self->TransactionObj; +    my $scrip = $self->ScripObj; +    my %Rules = $self->Rules; +    my ($field, $value) = @Rules{'field', 'value'}; +    return if !defined($field) or !defined($value); + +    if ($trans->Type eq 'Create') { +        return 1 if $trans->TicketObj->FirstCustomFieldValue($field) eq $value; +    } +    if ($trans->Type eq 'CustomField') { +        my $cf = RT::CustomField->new($self->CurrentUser); +        $cf->Load($field); +        return 1 if $trans->Field == $cf->Id and $trans->NewValue eq $value; +    } +    return undef; +} + +sub Options { +  my $self = shift; +  my %args = ( 'QueueObj' => undef, @_ ); +  my $QueueObj = $args{'QueueObj'}; +  my $cfs = $QueueObj->TicketCustomFields(); +  my @fieldnames; +  while ( my $cf = $cfs->Next ) { +    push @fieldnames, $cf->Name, $cf->Name; +  } +  return ( +    {  +      'name'    => 'field', +      'label'   => 'Custom Field', +      'type'    => 'select', +      'options' => \@fieldnames, +    }, +    { +      'name'    => 'value', +      'label'   => 'Value', +      'type'    => 'text', +    }, +  ); +} +1; + diff --git a/rt/lib/RT/Scrip_Overlay.pm b/rt/lib/RT/Scrip_Overlay.pm index 6c2cbd58e..b5beb3434 100644 --- a/rt/lib/RT/Scrip_Overlay.pm +++ b/rt/lib/RT/Scrip_Overlay.pm @@ -103,6 +103,8 @@ sub Create {          CustomPrepareCode      => undef,          CustomCommitCode       => undef,          CustomIsApplicableCode => undef, +        ConditionRules         => undef, +        ActionRules            => undef,          @_      ); @@ -162,6 +164,8 @@ sub Create {          CustomPrepareCode      => $args{'CustomPrepareCode'},          CustomCommitCode       => $args{'CustomCommitCode'},          CustomIsApplicableCode => $args{'CustomIsApplicableCode'}, +        ConditionRules         => $args{'ConditionRules'}, +        ActionRules            => $args{'ActionRules'},      );      if ( $id ) {          return ( $id, $self->loc('Scrip Created') );  | 
