[Rt-commit] rt branch, 4.4/custom-fields-set-from-rtconfig, updated. rt-4.4.3-69-g000600fda

John Waller john at bestpractical.com
Tue Nov 27 22:21:45 EST 2018


The branch, 4.4/custom-fields-set-from-rtconfig has been updated
       via  000600fdabfc3602c0e16e7d86432f907f5874d4 (commit)
      from  4e17fef8e85461d6dda7e6507ea18fc204dc9c98 (commit)

Summary of changes:
 etc/RT_SiteConfig.d/Lifecycle_Config.pm |  4 ++--
 lib/RT/Lifecycle.pm                     | 39 +++++++++++++++++++++++----------
 lib/RT/Ticket.pm                        | 29 ++++++++++++------------
 3 files changed, 44 insertions(+), 28 deletions(-)

- Log -----------------------------------------------------------------
commit 000600fdabfc3602c0e16e7d86432f907f5874d4
Author: John Waller <john at bestpractical.com>
Date:   Tue Nov 27 22:21:35 2018 -0500

    Decided to not be fancy with multiple values on one transition. Since we only do this on rights, just follow convention.

diff --git a/etc/RT_SiteConfig.d/Lifecycle_Config.pm b/etc/RT_SiteConfig.d/Lifecycle_Config.pm
index 1bd7d809d..eeaf54a68 100644
--- a/etc/RT_SiteConfig.d/Lifecycle_Config.pm
+++ b/etc/RT_SiteConfig.d/Lifecycle_Config.pm
@@ -52,8 +52,8 @@ Set(%Lifecycles,
             'escalation1 -> open' => { label => 'Re-open' }, # loc{label}
         ],
 		dates => {
-			'Stalled' => 'open -> escalation1',
-			'Setup' => 'open -> escalation1' ,
+			'open -> escalation1' => 'Stalled',
+			'escalation1 -> open' => 'Setup',
 		},
     },
     '__maps__' => {
diff --git a/lib/RT/Lifecycle.pm b/lib/RT/Lifecycle.pm
index d577bda93..314f696ce 100644
--- a/lib/RT/Lifecycle.pm
+++ b/lib/RT/Lifecycle.pm
@@ -48,7 +48,29 @@
 
 use strict;
 use warnings;
-
+use Data::Printer {
+  color => {
+     array       => 'bright_white',  # array index numbers
+     number      => 'bright_blue',   # numbers
+     string      => 'bright_yellow', # strings
+     class       => 'bright_green',  # class names
+     method      => 'bright_green',  # method names
+     undef       => 'bright_red',    # the 'undef' value
+     hash        => 'magenta',       # hash keys
+     regex       => 'yellow',        # regular expressions
+     code        => 'green',         # code references
+     glob        => 'bright_cyan',   # globs (usually file handles)
+     vstring     => 'bright_blue',   # version strings (v5.16.0, etc)
+     repeated    => 'white on_red',  # references to seen values
+     caller_info => 'bright_cyan',   # details on what's being printed
+     weak        => 'cyan',          # weak references
+     tainted     => 'red',           # tainted content
+     escaped     => 'bright_red',    # escaped characters (\t, \n, etc)
+ 
+     # potential new Perl datatypes, unknown to Data::Printer
+     unknown     => 'bright_yellow on_blue',
+  },
+};
 package RT::Lifecycle;
 
 our %LIFECYCLES;
@@ -460,9 +482,6 @@ sub CheckRight {
 Takes two statuses (from -> to) and returns the field that should
 be updated on the ticket.
 
-Note: field -> transition is reverse, because field is unique, but transition may not be - multiple fields to update on 
-on ticket is possible this way
-
 =cut
 
 sub DateFields {
@@ -471,17 +490,13 @@ sub DateFields {
     my $to = shift;
 	
 	my $list = $self->{'data'}{'dates'};
-	my @datefields;	
-	my %list = %$list;
 	
-	foreach my $field (keys %list) {
-		my $transition = $list->{$field};
+	foreach my $transition (keys %$list) {
+		my $field = $list->{$transition};
 		if ($transition eq "$from -> $to" || $transition eq "* => *" || $transition eq "* => $to" || $transition eq "$from => *") {
-			push @datefields, $field;	
+			return $field;	
 		}
-	}
-	return @datefields;
-	
+	}	
 }
 
 =head3 RightsDescription [TYPE]
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index e85e6aeee..608576861 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -2499,6 +2499,7 @@ sub _SetStatus {
         Lifecycle => $self->LifecycleObj,
         @_,
     );
+	
     $args{Status} = lc $args{Status} if defined $args{Status};
     $args{NewLifecycle} ||= $args{Lifecycle};
 
@@ -2532,25 +2533,25 @@ sub _SetStatus {
             RecordTransaction => 0,
         );
     }
+	
+	# When we are in transition to an active status in THIS queue, or another queue
+	if(	$args{Lifecycle}->IsActive($args{Status}) 
+		|| $args{NewLifecycle}->IsActive($args{Status}) ) {
 
-
-	# When we are in an active status run.
-	if(	$args{Lifecycle}->IsActive($args{Status}) ){
 		my $cnow = RT::Date->new( $self->CurrentUser );
 	    $cnow->SetToNow();
-		my @datefields = $args{Lifecycle}->DateFields($old,$args{Status});	
-		#my @datefields = $self->LifecycleObj->DateField($old, $args{Status})	
-		if(@datefields){
-			foreach my $field (@datefields){ 
-				#Data::Printer::p $field;
-				my ($ok, $e) = $self->AddCustomFieldValue( Field => $field , Value => $cnow->ISO);	
-				if(not $ok){
-					RT::Logger->error("Unable to update $field : $e");
-				}else{
-					warn "Update $field";
-				}
+
+		my $field= $args{Lifecycle}->DateFields($old,$args{Status});	
+	
+		if( $field ) { 
+			my ( $ok, $e ) = $self->AddCustomFieldValue( Field => $field , Value => $cnow->ISO );	
+			if(not $ok){
+				RT::Logger->error("Unable to update $field : $e");
 			}
 		}
+		else {
+			RT::Logger->debug("No custom data field matches")
+		}
 		
 	}
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list