X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FTransaction_Overlay.pm;h=89c5273e19b8110df9bc5c19fbac98bfd7e2a491;hb=36bb53a4a79512e7e24321873ddbbff525d629fb;hp=96ccf51d44a75f0246515baea498013fa1af9026;hpb=b4b0c7e72d7eaee2fbfc7022022c9698323203dd;p=freeside.git diff --git a/rt/lib/RT/Transaction_Overlay.pm b/rt/lib/RT/Transaction_Overlay.pm index 96ccf51d4..89c5273e1 100644 --- a/rt/lib/RT/Transaction_Overlay.pm +++ b/rt/lib/RT/Transaction_Overlay.pm @@ -1,40 +1,40 @@ # BEGIN BPS TAGGED BLOCK {{{ -# +# # COPYRIGHT: -# -# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC -# -# +# +# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +# +# # (Except where explicitly superseded by other copyright notices) -# -# +# +# # LICENSE: -# +# # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. -# +# # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 or visit their web page on the internet at # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -# -# +# +# # CONTRIBUTION SUBMISSION POLICY: -# +# # (The following paragraph is not intended to limit the rights granted # to you to modify and distribute this software under the terms of # the GNU General Public License and is only of importance to you if # you choose to contribute your changes and enhancements to the # community by submitting them to Best Practical Solutions, LLC.) -# +# # By intentionally submitting any modifications, corrections or # derivatives to this work, or any other work intended for use with # Request Tracker, to Best Practical Solutions, LLC, you confirm that @@ -43,7 +43,7 @@ # royalty-free, perpetual, license to use, copy, create derivative # works based on those contributions, and sublicense and distribute # those contributions and any derivatives thereof. -# +# # END BPS TAGGED BLOCK }}} =head1 NAME @@ -110,12 +110,13 @@ sub Create { NewValue => undef, MIMEObj => undef, ActivateScrips => 1, - CommitScrips => 1, - ObjectType => 'RT::Ticket', - ObjectId => 0, - ReferenceType => undef, - OldReference => undef, - NewReference => undef, + CommitScrips => 1, + ObjectType => 'RT::Ticket', + ObjectId => 0, + ReferenceType => undef, + OldReference => undef, + NewReference => undef, + CustomFields => {}, @_ ); @@ -130,17 +131,17 @@ sub Create { #lets create our transaction my %params = ( - Type => $args{'Type'}, - Data => $args{'Data'}, - Field => $args{'Field'}, - OldValue => $args{'OldValue'}, - NewValue => $args{'NewValue'}, - Created => $args{'Created'}, - ObjectType => $args{'ObjectType'}, - ObjectId => $args{'ObjectId'}, + Type => $args{'Type'}, + Data => $args{'Data'}, + Field => $args{'Field'}, + OldValue => $args{'OldValue'}, + NewValue => $args{'NewValue'}, + Created => $args{'Created'}, + ObjectType => $args{'ObjectType'}, + ObjectId => $args{'ObjectId'}, ReferenceType => $args{'ReferenceType'}, - OldReference => $args{'OldReference'}, - NewReference => $args{'NewReference'}, + OldReference => $args{'OldReference'}, + NewReference => $args{'NewReference'}, ); # Parameters passed in during an import that we probably don't want to touch, otherwise @@ -158,6 +159,10 @@ sub Create { } } + # Set up any custom fields passed at creation. Has to happen + # before scrips. + + $self->UpdateCustomFields(%{ $args{'CustomFields'} }); #Provide a way to turn off scrips if we need to $RT::Logger->debug('About to think about scrips for transaction #' .$self->Id); @@ -176,7 +181,7 @@ sub Create { # Entry point of the rule system my $ticket = RT::Ticket->new($RT::SystemUser); $ticket->Load($args{'ObjectId'}); - my $rules = RT::Ruleset->FindAllRules( + my $rules = $self->{rules} = RT::Ruleset->FindAllRules( Stage => 'TransactionCreate', Type => $args{'Type'}, TicketObj => $ticket, @@ -211,6 +216,22 @@ sub Scrips { } +=head2 Rules + +Returns the array of Rule objects for this transaction. +This routine is only useful on a freshly created transaction object. +Rules do not get persisted to the database with transactions. + + +=cut + + +sub Rules { + my $self = shift; + return($self->{'rules'}); +} + + # {{{ sub Delete =head2 Delete @@ -286,27 +307,30 @@ textual part (as defined in RT::I18N::IsTextualContentType). Otherwise, returns undef. Takes a paramhash. If the $args{'Quote'} parameter is set, wraps this message -at $args{'Wrap'}. $args{'Wrap'} defaults to 70. +at $args{'Wrap'}. $args{'Wrap'} defaults to $RT::MessageBoxWidth - 2 or 70. If $args{'Type'} is set to C, this will return an HTML part of the message, if available. Otherwise it looks for a text/plain part. If $args{'Type'} is missing, it defaults to the value of C<$RT::Transaction::PreferredContentType>, if that's missing too, -defaults to 'text/plain'. +defaults to textual. =cut sub Content { my $self = shift; my %args = ( - Type => $PreferredContentType || 'text/plain', + Type => $PreferredContentType || '', Quote => 0, Wrap => 70, + Wrap => ( $RT::MessageBoxWidth || 72 ) - 2, @_ ); my $content; - if ( my $content_obj = $self->ContentObj( Type => $args{Type} ) ) { + if ( my $content_obj = + $self->ContentObj( $args{Type} ? ( Type => $args{Type} ) : () ) ) + { $content = $content_obj->Content ||''; if ( lc $content_obj->ContentType eq 'text/html' ) { @@ -346,7 +370,7 @@ sub Content { $max = length if length > $max; } - if ( $max > 76 ) { + if ( $max > $args{'Wrap'}+6 ) { # 76 ) { require Text::Wrapper; my $wrapper = new Text::Wrapper( columns => $args{'Wrap'}, @@ -397,12 +421,16 @@ Returns the RT::Attachment object which contains the content for this Transactio sub ContentObj { my $self = shift; - my %args = ( Type => $PreferredContentType || 'text/plain', - @_ ); + my %args = ( Type => $PreferredContentType, Attachment => undef, @_ ); # If we don't have any content, return undef now. # Get the set of toplevel attachments to this transaction. - return undef unless my $Attachment = $self->Attachments->First; + + my $Attachment = $args{'Attachment'}; + + $Attachment ||= $self->Attachments->First; + + return undef unless ($Attachment); # If it's a textual part, just return the body. if ( RT::I18N::IsTextualContentType($Attachment->ContentType) ) { @@ -412,14 +440,23 @@ sub ContentObj { # If it's a multipart object, first try returning the first part with preferred # MIME type ('text/plain' by default). - elsif ( $Attachment->ContentType =~ '^multipart/' ) { - my $plain_parts = $Attachment->Children; - $plain_parts->ContentType( VALUE => $args{Type} ); - $plain_parts->LimitNotEmpty; - - # If we actully found a part, return its content - if ( my $first = $plain_parts->First ) { - return $first; + elsif ( $Attachment->ContentType =~ qr|^multipart/mixed|i ) { + my $kids = $Attachment->Children; + while (my $child = $kids->Next) { + my $ret = $self->ContentObj(%args, Attachment => $child); + return $ret if ($ret); + } + } + elsif ( $Attachment->ContentType =~ qr|^multipart/|i ) { + if ( $args{Type} ) { + my $plain_parts = $Attachment->Children; + $plain_parts->ContentType( VALUE => $args{Type} ); + $plain_parts->LimitNotEmpty; + + # If we actully found a part, return its content + if ( my $first = $plain_parts->First ) { + return $first; + } } # If that fails, return the first textual part which has some content. @@ -526,6 +563,8 @@ sub ContentAsMIME { my $self = shift; my $main_content = $self->ContentObj; + return unless $main_content; + my $entity = $main_content->ContentAsMIME; if ( $main_content->Parent ) { @@ -557,11 +596,7 @@ sub ContentAsMIME { OPERATOR => 'NOT STARTSWITH', VALUE => 'multipart/', ); - $attachments->Limit( - FIELD => 'Content', - OPERATOR => '!=', - VALUE => '', - ); + $attachments->LimitNotEmpty; while ( my $a = $attachments->Next ) { $entity->make_multipart unless $entity->is_multipart; $entity->add_part( $a->ContentAsMIME ); @@ -655,6 +690,9 @@ sub BriefDescription { ) ); } + elsif ( $type =~ /SystemError/ ) { + return $self->loc("System error"); + } if ( my $code = $_BriefDescriptions{$type} ) { return $code->($self); @@ -1130,6 +1168,7 @@ sub UpdateCustomFields { unless ( $arg =~ /^(?:Object-RT::Transaction--)?CustomField-(\d+)/ ); next if $arg =~ /-Magic$/; + next if $arg =~ /-TimeUnits$/; my $cfid = $1; my $values = $args->{$arg}; foreach