[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.5-131-g7f153df

Ruslan Zakirov ruz at bestpractical.com
Wed Sep 23 15:34:54 EDT 2009


The branch, 3.8-trunk has been updated
       via  7f153dfed7209698159b03783bd56b3e675ac7e6 (commit)
       via  b5aedb8db1cfcd46162785587002ecf8c27b1335 (commit)
       via  1732459125923ac6d1691a78a2abbb0ef37fdebb (commit)
       via  572f766c0888e02009d611357ec0184ea6764129 (commit)
      from  a7535fd20725523f2c75fbcea5775f2c9a726bba (commit)

Summary of changes:
 lib/RT/Ticket_Overlay.pm                    |   61 ++++++++++++++++++++-------
 share/html/Elements/EditCustomField         |   14 ++++--
 share/html/Elements/ShowCustomFields        |    6 ++-
 share/html/Ticket/Elements/EditCustomFields |    5 ++-
 share/html/Ticket/Modify.html               |    9 +---
 5 files changed, 66 insertions(+), 29 deletions(-)

- Log -----------------------------------------------------------------
commit 572f766c0888e02009d611357ec0184ea6764129
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Sep 22 19:39:26 2009 +0400

    pass more data into a callback

diff --git a/share/html/Elements/ShowCustomFields b/share/html/Elements/ShowCustomFields
index 7053594..ddb8b72 100644
--- a/share/html/Elements/ShowCustomFields
+++ b/share/html/Elements/ShowCustomFields
@@ -74,7 +74,11 @@
 </table>
 % }
 <%INIT>
-$m->callback( CallbackName => 'MassageCustomFields', CustomFields => $CustomFields );
+$m->callback(
+    CallbackName => 'MassageCustomFields',
+    Object => $Object,
+    CustomFields => $CustomFields,
+);
 
 my $print_value = sub {
     my ($cf, $value) = @_;

commit 1732459125923ac6d1691a78a2abbb0ef37fdebb
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Sep 23 23:24:19 2009 +0400

    allow developers to manually apply scrips batch staged
    
    In some case we can not track all references to a ticket,
    but really want to apply batched scrips

diff --git a/lib/RT/Ticket_Overlay.pm b/lib/RT/Ticket_Overlay.pm
index f2f22c9..c91f209 100755
--- a/lib/RT/Ticket_Overlay.pm
+++ b/lib/RT/Ticket_Overlay.pm
@@ -3164,10 +3164,11 @@ sub SeenUpTo {
 
 =head2 TransactionBatch
 
-  Returns an array reference of all transactions created on this ticket during
-  this ticket object's lifetime, or undef if there were none.
+Returns an array reference of all transactions created on this ticket during
+this ticket object's lifetime or since last application of a batch, or undef
+if there were none.
 
-  Only works when the C<UseTransactionBatch> config option is set to true.
+Only works when the C<UseTransactionBatch> config option is set to true.
 
 =cut
 
@@ -3176,28 +3177,37 @@ sub TransactionBatch {
     return $self->{_TransactionBatch};
 }
 
-sub DESTROY {
+=head2 ApplyTransactionBatch
+
+Applies scrips on the current batch of transactions and shinks it. Usually
+batch is applied when object is destroyed, but in some cases it's too late.
+
+=cut
+
+sub ApplyTransactionBatch {
     my $self = shift;
 
-    # DESTROY methods need to localize $@, or it may unset it.  This
-    # causes $m->abort to not bubble all of the way up.  See perlbug
-    # http://rt.perl.org/rt3/Ticket/Display.html?id=17650
-    local $@;
+    my $batch = $self->TransactionBatch;
+    return unless $batch && @$batch;
 
-    # The following line eliminates reentrancy.
-    # It protects against the fact that perl doesn't deal gracefully
-    # when an object's refcount is changed in its destructor.
-    return if $self->{_Destroyed}++;
+    $self->_ApplyTransactionBatch;
+
+    $self->{_TransactionBatch} = [];
+}
+
+sub _ApplyTransactionBatch {
+    my $self = shift;
+    my $batch = $self->TransactionBatch;
 
-    my $batch = $self->TransactionBatch or return;
-    return unless @$batch;
+    my %seen;
+    my $types = join ',', grep !$seen{$_}++, map $_->Type, grep defined, @{$batch};
 
     require RT::Scrips;
     RT::Scrips->new($RT::SystemUser)->Apply(
         Stage          => 'TransactionBatch',
         TicketObj      => $self,
         TransactionObj => $batch->[0],
-        Type           => join( ',', map $_->Type, grep defined, @{$batch} )
+        Type           => $types,
     );
 
     # Entry point of the rule system
@@ -3205,11 +3215,30 @@ sub DESTROY {
         Stage          => 'TransactionBatch',
         TicketObj      => $self,
         TransactionObj => $batch->[0],
-        Type           => join( ',', map $_->Type, grep defined, @{$batch} )
+        Type           => $types,
     );
     RT::Ruleset->CommitRules($rules);
 }
 
+sub DESTROY {
+    my $self = shift;
+
+    # DESTROY methods need to localize $@, or it may unset it.  This
+    # causes $m->abort to not bubble all of the way up.  See perlbug
+    # http://rt.perl.org/rt3/Ticket/Display.html?id=17650
+    local $@;
+
+    # The following line eliminates reentrancy.
+    # It protects against the fact that perl doesn't deal gracefully
+    # when an object's refcount is changed in its destructor.
+    return if $self->{_Destroyed}++;
+
+    my $batch = $self->TransactionBatch;
+    return unless $batch && @$batch;
+
+    return $self->_ApplyTransactionBatch;
+}
+
 # }}}
 
 # {{{ PRIVATE UTILITY METHODS. Mostly needed so Ticket can be a DBIx::Record

commit b5aedb8db1cfcd46162785587002ecf8c27b1335
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Sep 23 23:26:06 2009 +0400

    apply batched scrips manually on modify
    
    1) as custom fields have context so the objects can hold reference
    to a ticket. In this case batch is not applied by undefining
    
    2) on display.html we don't need this as we use redirect

diff --git a/share/html/Ticket/Modify.html b/share/html/Ticket/Modify.html
index adfc1e5..ee3a892 100755
--- a/share/html/Ticket/Modify.html
+++ b/share/html/Ticket/Modify.html
@@ -82,19 +82,14 @@ $m->callback( TicketObj => $TicketObj, CustomFields => $CustomFields, ARGSRef =>
 my @results = ProcessTicketBasics(TicketObj => $TicketObj, ARGSRef => \%ARGS);
 push @results, ProcessObjectCustomFieldUpdates(Object => $TicketObj, ARGSRef => \%ARGS);
 
-# undef so that TransactionBatch scrips run and update the ticket
-$TicketObj = undef;
-$TicketObj = LoadTicket($id);
+$TicketObj->ApplyTransactionBatch;
 
 # TODO: display the results, even if we can't display the ticket
-
 unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
     Abort("No permission to view ticket");
 } 
 
 </%INIT>
-
-
 <%ARGS>
 $id => undef
 </%ARGS>

commit 7f153dfed7209698159b03783bd56b3e675ac7e6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Sep 23 23:29:38 2009 +0400

    don't fetch defaults from TOP level arguments
    
    when you first time see Modify.html it has no CF values,
    you submit a change of a CF, scrips are fired and change
    other CFs, but you see nothing. This happened because
    of such defaulting, TOP level arguments are filled with
    old values of the CFs

diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index f514ec5..d1bb0c2 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -56,16 +56,21 @@ unless ( $Type ) {
 
 my $Values;
 if ( $Object && $Object->id ) {
-    $Values = $Object->CustomFieldValues( $CustomField->id );
-    $Values->Columns( qw( id CustomField ObjectType ObjectId Disabled Content ContentType ContentEncoding SortOrder Creator Created LastUpdatedBy LastUpdated ) );
-    $NamePrefix ||= join('-', 'Object', ref($Object), $Object->Id, 'CustomField', '');
+    $NamePrefix ||= join '-', 
+        'Object', ref($Object), $Object->Id, 'CustomField', '';
 
+    $Values = $Object->CustomFieldValues( $CustomField->id );
+    $Values->Columns(
+        qw( id CustomField ObjectType ObjectId Disabled Content
+        ContentType ContentEncoding SortOrder Creator Created
+        LastUpdatedBy LastUpdated )
+    );
     # Don't take care of $Values if there isn't values inside
     undef ( $Values ) unless ( $Values->Count );
 }
 
 # Always fill $Default with submited values if it's empty
-if ( not $Default ) {
+if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
     my %TOP = $m->request_args;
     $Default = $TOP{ $NamePrefix .$CustomField->Id . '-Values' }
             || $TOP{ $NamePrefix .$CustomField->Id . '-Value' };
@@ -107,4 +112,5 @@ $NamePrefix  => undef
 $Rows        => 5
 $Cols        => 15
 $Default     => undef
+$DefaultsFromTopArguments => 1,
 </%ARGS>
diff --git a/share/html/Ticket/Elements/EditCustomFields b/share/html/Ticket/Elements/EditCustomFields
index bbcc8ea..c3a44ee 100755
--- a/share/html/Ticket/Elements/EditCustomFields
+++ b/share/html/Ticket/Elements/EditCustomFields
@@ -58,12 +58,14 @@
       <i><% $CustomField->FriendlyType %></i>
     </td>
     <td class="entry">
+% my $default = $m->notes('Field-' . $CustomField->Id);
+% $default ||= $ARGS{"CustomField-". $CustomField->Id };
       <& /Elements/EditCustomField, 
           %ARGS,
           Object => $TicketObj,
           CustomField => $CustomField,
           NamePrefix => $NamePrefix,
-          Default => $m->notes('Field-' . $CustomField->Id) || $ARGS{"CustomField-".$CustomField->Id},
+          Default => $default,
       &>
 %  if (my $msg = $m->notes('InvalidField-' . $CustomField->Id)) {
         <br />
@@ -102,4 +104,5 @@ $NamePrefix => ''
 $TicketObj => undef
 $QueueObj => undef
 $OnCreate => undef
+$DefaultsFromTopArguments => 1
 </%ARGS>
diff --git a/share/html/Ticket/Modify.html b/share/html/Ticket/Modify.html
index ee3a892..e7d370f 100755
--- a/share/html/Ticket/Modify.html
+++ b/share/html/Ticket/Modify.html
@@ -59,7 +59,7 @@
 
 <&| /Widgets/TitleBox, title => loc('Modify ticket #[_1]',$TicketObj->Id), class=>'ticket-info-basics' &>
 <& Elements/EditBasics, TicketObj => $TicketObj &>
-<& Elements/EditCustomFields, TicketObj => $TicketObj &>
+<& Elements/EditCustomFields, TicketObj => $TicketObj, DefaultsFromTopArguments => 0 &>
 </&>
 
 <& /Elements/Submit, Name => 'SubmitTicket', Label => loc('Save Changes'), Caption => loc("If you've updated anything above, be sure to"), color => "#993333" &>

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


More information about the Rt-commit mailing list