[Rt-commit] rt branch, 4.4/record-transaction-cfs, created. rt-4.4.3-146-ge722de789b

Craig Kaiser craig at bestpractical.com
Thu Dec 20 12:07:01 EST 2018


The branch, 4.4/record-transaction-cfs has been created
        at  e722de789b252e45d9f1d6ac4bb5033aef23ac37 (commit)

- Log -----------------------------------------------------------------
commit 3b8343d6ab8700644768eb65c2b00fc7b93e8846
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 20 11:45:16 2018 -0500

    Abstract handle of transaction cf updates on TimeWorked updates
    
    The previous implementation processed any transaction cf updates
    in the same transaction as the TimeWorked update. This was added
    primarily to support work in the TimeTracking extension. However,
    there are use cases where you may want to record transaction cf
    updates independent of a TimeWorked update.
    
    Provide a subroutine stub and pass the transaction object so
    you can record transaction cf updates against it, but don't make
     the default behavior for all transaction cfs.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 66fe3135c0..9bf870283c 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2969,7 +2969,7 @@ sub ProcessTicketBasics {
     if ( defined($ARGSRef->{'TimeWorked'}) && ($ARGSRef->{'TimeWorked'} || 0) != $TicketObj->TimeWorked ) {
         my ( $val, $msg, $txn ) = $TicketObj->SetTimeWorked( $ARGSRef->{'TimeWorked'} );
         push( @results, $msg );
-        $txn->UpdateCustomFields( %$ARGSRef) if $txn;
+        TxnAfterUpdateTimeWorked(TransactionObj => $txn, ARGSRef => $ARGSRef);
     }
 
     # We special case owner changing, so we can use ForceOwnerChange
@@ -2993,6 +2993,11 @@ sub ProcessTicketBasics {
     return (@results);
 }
 
+# This subroutine is a stub to allow you to attach transaction custom field updates
+# to the transaction associated with the time worked update.
+sub TxnAfterUpdateTimeWorked {
+}
+
 sub ProcessTicketReminders {
     my %args = (
         TicketObj => undef,

commit c6baa79f137c34bedbefbdbb4a29e2e7167fd5f5
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 20 11:45:54 2018 -0500

    Record transaction CF updates even when no update message is provided
    
    Provide a way for transaction CFs to be recorded even when an
    update mesage is not provided and TimeWorked isn't updated.
    Transaction CFs submitted without other associated transactions
    will create a new transaction to record the transaction CF values.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 9bf870283c..b2010653d0 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2350,6 +2350,7 @@ sub ProcessUpdateMessage {
         and not $args{ARGSRef}->{'AttachTickets'}
         and not length $args{ARGSRef}->{'UpdateContent'} )
     {
+        $args{'ARGSRef'}->{'NoContentUpdate'} = 1;
         if ( $args{ARGSRef}->{'UpdateTimeWorked'} ) {
             $args{ARGSRef}->{TimeWorked} = $args{TicketObj}->TimeWorked + delete $args{ARGSRef}->{'UpdateTimeWorked'};
         }
@@ -3134,9 +3135,22 @@ sub _ValidateConsistentCustomFieldValues {
 
 sub ProcessObjectCustomFieldUpdates {
     my %args    = @_;
+    my $TicketObj = $args{'TicketObj'};
     my $ARGSRef = $args{'ARGSRef'};
     my @results;
 
+    # This processes transaction cfs with no update content.
+    # Updates with a message are handled in ProcessUpdateMessage
+
+    if ( $TicketObj
+         and $ARGSRef->{'NoContentUpdate'}
+         and grep {/^(?:Object-RT::Transaction--)?CustomField-(\d+)/} keys %$ARGSRef ){
+        my ( $ret, $msg, $TransactionObj ) = $TicketObj->_NewTransaction(
+            Type      => 'TransCustomField',
+        );
+        $TransactionObj->UpdateCustomFields( %$ARGSRef) if $TransactionObj;
+    }
+
     # Build up a list of objects that we want to work with
     my %custom_fields_to_mod = _ParseObjectCustomFieldArgs($ARGSRef);
 
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index c88f43f9d6..66145cca63 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -990,6 +990,10 @@ sub _CanonicalizeRoleName {
         my $self = shift;
         return ("Comments added");          #loc()
     },
+    TransCustomField => sub {
+        my $self = shift;
+        return ("Transaction custom field set"); #loc()
+    },
     CustomField => sub {
         my $self = shift;
         my $field = $self->loc('CustomField');

commit e722de789b252e45d9f1d6ac4bb5033aef23ac37
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 20 12:04:42 2018 -0500

    Add test for when ticket transaction CF updated with no content
    
    A transaction should still be recorded when a ticket transaction CF
    is updated, even if there is no content being updated for that transaction.

diff --git a/t/web/ticket_txn_cf.t b/t/web/ticket_txn_cf.t
index 42a37720ad..97e9eeade8 100644
--- a/t/web/ticket_txn_cf.t
+++ b/t/web/ticket_txn_cf.t
@@ -119,5 +119,25 @@ diag 'submit no value on ticket update page';
         0, 'no txn cf value in db' );
 }
 
+diag 'submit only transaction CF value on ticket update page';
+{
+    $m->follow_link_ok( { text => 'Reply' }, "reply to the ticket" );
+
+    $m->content_contains($cf_name, 'has cf field' );
+
+    $m->form_name('TicketUpdate');
+    $m->field("Object-RT::Transaction--CustomField-$cfid-Values" => 'Only CF value on update');
+    $m->click('SubmitTicket');
+
+    $m->content_contains('Transaction custom field set');
+
+    my $txns = $ticket->Transactions;
+    $txns->Limit(FIELD => 'Type', VALUE => 'TransCustomField');
+    is( $txns->Last->CustomFieldValues($cfid)->Count,
+        1, 'Transaction set for ticket transaction CF update with no content'
+    );
+}
+
+
 done_testing;
 

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


More information about the rt-commit mailing list