[Rt-commit] r15683 - in rt/branches/3.999-DANGEROUS: lib/RT/Interface lib/RT/Model lib/RT/ScripAction lib/RT/Shredder share/html/Admin/Tools/Shredder/Elements/Object share/html/Ticket share/html/Ticket/Attachment share/html/Ticket/Elements

ruz at bestpractical.com ruz at bestpractical.com
Mon Sep 1 17:05:53 EDT 2008


Author: ruz
Date: Mon Sep  1 17:05:52 2008
New Revision: 15683

Modified:
   rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/Attachment.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/AttachmentCollection.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/TicketCollection.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/Transaction.pm
   rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Shredder/Attachment.pm
   rt/branches/3.999-DANGEROUS/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment
   rt/branches/3.999-DANGEROUS/share/html/REST/1.0/Forms/ticket/attachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Attachment/dhandler
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/FindAttachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/LoadTextAttachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowAttachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowGnuPGStatus
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowHistory
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowMessageHeaders
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowTransaction
   rt/branches/3.999-DANGEROUS/share/html/Ticket/ShowEmailRecord.html

Log:
* revert as transaction is reserved keyword in sqlite :(

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm	Mon Sep  1 17:05:52 2008
@@ -549,8 +549,9 @@
         # main content is not top most entity, we shouldn't loose
         # From/To/Cc headers that are on a top part
         my $attachments = RT::Model::AttachmentCollection->new( current_user => $txn->current_user );
-        $attachments->query_columns(qw(id parent transaction headers));
-        $attachments->limit( column => 'transaction', value => $txn->id );
+        $attachments->query_columns(qw(id parent transaction_id headers));
+        $attachments->limit( column => 'transaction_id', value => $txn->id );
+        $attachments->limit( column => 'parent',         value => 0 );
         $attachments->limit(
             column      => 'parent',
             operator    => 'IS',
@@ -568,7 +569,7 @@
     }
 
     my $attachments = RT::Model::AttachmentCollection->new( current_user => $txn->current_user );
-    $attachments->limit( column => 'transaction', value => $txn->id );
+    $attachments->limit( column => 'transaction_id', value => $txn->id );
     $attachments->limit(
         column   => 'id',
         operator => '!=',

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/Attachment.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/Attachment.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/Attachment.pm	Mon Sep  1 17:05:52 2008
@@ -78,7 +78,7 @@
 use base 'RT::Record';
 use Jifty::DBI::Schema;
 use Jifty::DBI::Record schema {
-    column transaction => references RT::Model::Transaction;
+    column transaction_id => references RT::Model::Transaction;
     column
         message_id => max_length is 200,
         type is 'varchar(200)', default is '';
@@ -102,7 +102,7 @@
     
     'Attachment' Should be a single MIME body with optional subparts
     'parent' is an optional id of the parent attachment
-    'transaction' is the mandatory id of the transaction this attachment is associated with.;
+    'transaction_id' is the mandatory id of the transaction this attachment is associated with.;
 
 =cut
 
@@ -110,7 +110,7 @@
     my $self = shift;
     my %args = (
         id             => 0,
-        transaction => 0,
+        transaction_id => 0,
         parent         => 0,
         attachment     => undef,
         @_
@@ -120,7 +120,7 @@
     my $Attachment = $args{'attachment'};
 
     # if we didn't specify a ticket, we need to bail
-    unless ( $args{'transaction'} ) {
+    unless ( $args{'transaction_id'} ) {
         Jifty->log->fatal( "RT::Model::Attachment->create couldn't, as you didn't specify a transaction" );
         return (0);
     }
@@ -146,7 +146,7 @@
     # and we should act accordingly.
     unless ( defined $Attachment->bodyhandle ) {
         my ($id) = $self->SUPER::create(
-            transaction => $args{'transaction'},
+            transaction_id => $args{'transaction_id'},
             parent         => $args{'parent'},
             content_type   => $Attachment->mime_type,
             headers        => $Attachment->head->as_string,
@@ -161,7 +161,7 @@
         foreach my $part ( $Attachment->parts ) {
             my $SubAttachment = RT::Model::Attachment->new();
             my ($id) = $SubAttachment->create(
-                transaction => $args{'transaction'},
+                transaction_id => $args{'transaction_id'},
                 parent         => $id,
                 attachment     => $part,
             );
@@ -178,7 +178,7 @@
         my ( $content_encoding, $Body ) = $self->_encode_lob( $Attachment->bodyhandle->as_string, $Attachment->mime_type );
 
         my $id = $self->SUPER::create(
-            transaction   => $args{'transaction'},
+            transaction_id   => $args{'transaction_id'},
             content_type     => $Attachment->mime_type,
             content_encoding => $content_encoding,
             parent           => $args{'parent'},
@@ -212,17 +212,27 @@
     return ( $self->SUPER::create(%args) );
 }
 
-=head2 transaction
+=head2 transaction_obj
 
-Returns the L<RT::Model::Transaction> object this attachment is asscoiated to.
+Returns the transaction object asscoiated with this attachment.
 
 =cut
 
 sub transaction_obj {
-    require Carp; Carp::confess('use transaction method instead of transaction_obj');
+    my $self = shift;
+
+    unless ( $self->{_transaction_obj} ) {
+        $self->{_transaction_obj} = RT::Model::Transaction->new;
+        $self->{_transaction_obj}->load( $self->transaction_id );
+    }
+
+    unless ( $self->{_transaction_obj}->id ) {
+        Jifty->log->fatal( "Attachment " . $self->id . " can't find transaction " . $self->transaction_id . " which it is ostensibly part of. That's bad" );
+    }
+    return $self->{_transaction_obj};
 }
 
-=head2 parent
+=head2 parent_obj
 
 Returns a parent's L<RT::Model::Attachment> object if this attachment
 has a parent, otherwise returns undef.
@@ -230,7 +240,12 @@
 =cut
 
 sub parent_obj {
-    require Carp; Carp::confess('use parent method instead of parent_obj');
+    my $self = shift;
+    return undef unless $self->parent;
+
+    my $parent = RT::Model::Attachment->new;
+    $parent->load_by_id( $self->parent );
+    return $parent;
 }
 
 =head2 children
@@ -325,7 +340,7 @@
 sub content_length {
     my $self = shift;
 
-    return undef unless $self->transaction->current_user_can_see;
+    return undef unless $self->transaction_obj->current_user_can_see;
 
     my $len = $self->get_header('Content-Length');
     unless ( defined $len ) {
@@ -378,7 +393,7 @@
 
         $body =~ s/^/> /gm;
 
-        $body = '[' . $self->transaction->creator_obj->name() . ' - ' . $self->transaction->created_as_string() . "]:\n\n" . $body . "\n\n";
+        $body = '[' . $self->transaction_obj->creator_obj->name() . ' - ' . $self->transaction_obj->created_as_string() . "]:\n\n" . $body . "\n\n";
 
     } else {
         $body = "[Non-text message not quoted]\n\n";
@@ -423,8 +438,8 @@
 
     my %data                 = ();
     my $current_user_address = lc $self->current_user->user_object->email;
-    my $correspond           = lc $self->transaction->ticket_obj->queue_obj->correspond_address;
-    my $comment              = lc $self->transaction->ticket_obj->queue_obj->comment_address;
+    my $correspond           = lc $self->transaction_obj->ticket_obj->queue_obj->correspond_address;
+    my $comment              = lc $self->transaction_obj->ticket_obj->queue_obj->comment_address;
     foreach my $hdr (qw(From To Cc Bcc RT-Send-Cc RT-Send-Bcc)) {
         my @Addresses;
         my $line = $self->get_header($hdr);
@@ -593,7 +608,7 @@
 sub encrypt {
     my $self = shift;
 
-    my $txn = $self->transaction;
+    my $txn = $self->transaction_obj;
     return ( 0, _('Permission Denied') ) unless $txn->current_user_can_see;
     return ( 0, _('Permission Denied') )
         unless $txn->ticket_obj->current_user_has_right('ModifyTicket');
@@ -650,7 +665,7 @@
 sub decrypt {
     my $self = shift;
 
-    my $txn = $self->transaction;
+    my $txn = $self->transaction_obj;
     return ( 0, _('Permission Denied') ) unless $txn->current_user_can_see;
     return ( 0, _('Permission Denied') )
         unless $txn->ticket_obj->current_user_has_right('ModifyTicket');
@@ -698,7 +713,7 @@
         return ( $self->__value( $field, @_ ) );
     }
 
-    return undef unless $self->transaction->current_user_can_see;
+    return undef unless $self->transaction_obj->current_user_can_see;
     return $self->__value( $field, @_ );
 }
 

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/AttachmentCollection.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/AttachmentCollection.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/AttachmentCollection.pm	Mon Sep  1 17:05:52 2008
@@ -107,7 +107,7 @@
     my $res = $self->new_alias('Transactions');
     $self->limit(
         entry_aggregator => 'AND',
-        column           => 'transaction',
+        column           => 'transaction_id',
         value            => $res . '.id',
         quote_value      => 0,
     );
@@ -218,7 +218,7 @@
     my $Attachment = $self->SUPER::next;
     return $Attachment unless $Attachment;
 
-    my $txn = $Attachment->transaction;
+    my $txn = $Attachment->transaction_obj;
     if ( $txn->__value('type') eq 'comment' ) {
         return $Attachment
             if $txn->current_user_has_right('ShowTicketcomments');

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/TicketCollection.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/TicketCollection.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/TicketCollection.pm	Mon Sep  1 17:05:52 2008
@@ -685,7 +685,7 @@
             alias1  => $self->{_sql_transalias},
             column1 => 'id',
             table2  => RT::Model::AttachmentCollection->new,
-            column2 => 'transaction',
+            column2 => 'transaction_id',
         );
     }
 

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/Transaction.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/Transaction.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/Transaction.pm	Mon Sep  1 17:05:52 2008
@@ -468,8 +468,8 @@
 
         $self->{'message'} = RT::Model::AttachmentCollection->new();
         $self->{'message'}->limit(
-            column => 'transaction',
-            value  => $self->id,
+            column => 'transaction_id',
+            value  => $self->id
         );
         $self->{'message'}->children_of(0);
     } else {
@@ -665,7 +665,7 @@
         return $self->{'attachments'};
     }
 
-    $self->{'attachments'}->limit( column => 'transaction', value => $self->id );
+    $self->{'attachments'}->limit( column => 'transaction_id', value => $self->id );
 
     # Get the self->{'attachments'} in the order they're put into
     # the database.  Arguably, we should be returning a tree
@@ -696,8 +696,8 @@
 
     my $Attachment = RT::Model::Attachment->new;
     my ( $id, $msg ) = $Attachment->create(
-        transaction => $self,
-        attachment  => $mime_object
+        transaction_id => $self->id,
+        attachment     => $mime_object
     );
     return ( $Attachment, $msg || _("Attachment Created") );
 }

Modified: rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm	Mon Sep  1 17:05:52 2008
@@ -337,7 +337,7 @@
 
     my $attachments = RT::Model::AttachmentCollection->new( current_user => RT->system_user );
     $attachments->limit(
-        column => 'transaction',
+        column => 'transaction_id',
         value  => $self->transaction_obj->id
     );
 

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Shredder/Attachment.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Shredder/Attachment.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Shredder/Attachment.pm	Mon Sep  1 17:05:52 2008
@@ -113,14 +113,14 @@
     }
 
     # Transaction
-    my $obj = $self->transaction;
+    my $obj = $self->transaction_obj;
     if ( defined $obj->id ) {
         push( @$list, $obj );
     } else {
         my $rec = $args{'shredder'}->get_record( object => $self );
         $self = $rec->{'object'};
         $rec->{'state'} |= INVALID;
-        $rec->{'description'} = "Have no related transaction #" . $self->transaction->id . " object";
+        $rec->{'description'} = "Have no related transaction #" . $self->transaction_id . " object";
     }
 
     $deps->_push_dependencies(

Modified: rt/branches/3.999-DANGEROUS/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment	Mon Sep  1 17:05:52 2008
@@ -48,6 +48,6 @@
 <%ARGS>
 $object => undef
 </%ARGS>
-<a href="<% RT->config->get('WebURL') %>/Ticket/Attachment/<% $object->transaction->id %>/<% $object->id %>/">
+<a href="<% RT->config->get('WebURL') %>/Ticket/Attachment/<% $object->transaction_id %>/<% $object->id %>/">
 Attachment(id:<% $object->id %>, Filename: <% $object->filename || '(no value)' %>)
 </a>

Modified: rt/branches/3.999-DANGEROUS/share/html/REST/1.0/Forms/ticket/attachments
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/REST/1.0/Forms/ticket/attachments	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/REST/1.0/Forms/ticket/attachments	Mon Sep  1 17:05:52 2008
@@ -94,7 +94,7 @@
 	push @data, [ subject    => $attachment->subject   ];
 	push @data, [ Creator    => $attachment->creator   ];
 	push @data, [ Created    => $attachment->created   ];
-	push @data, [ Transaction    => $attachment->transaction->id   ];
+	push @data, [ Transaction    => $attachment->transaction_id   ];
 	push @data, [ Parent    => $attachment->parent   ];
 	push @data, [ message_id    => $attachment->message_id   ];
 	push @data, [ Filename    => $attachment->filename   ];

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Attachment/dhandler
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Attachment/dhandler	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Attachment/dhandler	Mon Sep  1 17:05:52 2008
@@ -62,8 +62,8 @@
      unless ($AttachmentObj->id) {
         abort("Bad attachment id. Couldn't find attachment '$attach'\n");
     }
-     unless ($AttachmentObj->transaction->id == $trans ) {
-        abort("Bad transaction number for attachment. $trans should be".$AttachmentObj->transaction->id ."\n");
+     unless ($AttachmentObj->transaction_id() == $trans ) {
+        abort("Bad transaction number for attachment. $trans should be".$AttachmentObj->transaction_id() ."\n");
 
      }
 

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/FindAttachments
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/FindAttachments	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/FindAttachments	Mon Sep  1 17:05:52 2008
@@ -55,11 +55,11 @@
 # code that looks at attachments will look at each one in turn.
 my $attachments = RT::Model::AttachmentCollection->new();
 
-$attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction created));
+$attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction_id created));
 
 my $transactions = $attachments->new_alias('Transactions');
 $attachments->join( alias1 => 'main',
-		    column1 => 'transaction',
+		    column1 => 'transaction_id',
 		    alias2 => $transactions,
 		    column2 => 'id' );
     

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/LoadTextAttachments
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/LoadTextAttachments	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/LoadTextAttachments	Mon Sep  1 17:05:52 2008
@@ -49,12 +49,12 @@
 
 my $attachments = RT::Model::AttachmentCollection->new();
 
-$attachments->query_columns( qw(id content content_type transaction content_encoding));
+$attachments->query_columns( qw(id content content_type transaction_id content_encoding));
 
 if ( $ticket->current_user_has_right('ShowTicket') ) {
     my $transactions = $attachments->new_alias('Transactions');
     $attachments->join( alias1 => 'main',
-                                           column1 => 'transaction',
+                                           column1 => 'transaction_id',
                                            alias2 => $transactions,
                                            column2 => 'id' );
     

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowAttachments
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowAttachments	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowAttachments	Mon Sep  1 17:05:52 2008
@@ -71,7 +71,7 @@
 </%PERL>
 
 <li><font size="-2">
-<a href="<%RT->config->get('WebPath')%>/Ticket/Attachment/<%$rev->transaction->id%>/<%$rev->id%>/<%$rev->filename | u%>">
+<a href="<%RT->config->get('WebPath')%>/Ticket/Attachment/<%$rev->transaction_id%>/<%$rev->id%>/<%$rev->filename | u%>">
 <&|/l, $rev->created_as_string, $size, $rev->creator_obj->name &>%1 (%2) by %3</&>
 </a>
 </font></li>

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowGnuPGStatus
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowGnuPGStatus	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowGnuPGStatus	Mon Sep  1 17:05:52 2008
@@ -80,7 +80,7 @@
 my $reverify_cb = sub  {
     my $top = shift;
 
-    my $txn = $top->transaction;
+    my $txn = $top->transaction_obj;
     unless ( $txn && $txn->id ) {
         return (0, "Couldn't get transaction of attachment #". $top->id);
     }

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowHistory
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowHistory	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowHistory	Mon Sep  1 17:05:52 2008
@@ -97,10 +97,10 @@
 
     $i++;
 
-    my @trans_attachments = grep { $_->transaction->id == $Transaction->id } @attachments;
+    my @trans_attachments = grep { $_->transaction_id == $Transaction->id } @attachments;
 
     my $trans_content = {};
-    grep { ($_->transaction->id == $Transaction->id ) && ($trans_content->{$_->id} = $_)  } @attachment_content;
+    grep { ($_->transaction_id == $Transaction->id ) && ($trans_content->{$_->id} = $_)  } @attachment_content;
 
    
     #Args is first because we're clobbering the "Attachments" parameter 

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowMessageHeaders
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowMessageHeaders	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowMessageHeaders	Mon Sep  1 17:05:52 2008
@@ -73,7 +73,7 @@
     @headers = grep $display_headers{ lc $_->{'Tag'} }, @headers;
 }
 
-my $ticket = $message->transaction->ticket_obj;
+my $ticket = $message->transaction_obj->ticket_obj;
 foreach my $f (@headers) {
     $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, ticket => $ticket, %ARGS);
 }

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowTransaction
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowTransaction	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowTransaction	Mon Sep  1 17:05:52 2008
@@ -157,7 +157,7 @@
 
 unless ($attachments) { 
     my $attachments = $transaction->attachments;
-    $attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction) );
+    $attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction_id) );
     $attachments = $attachments->items_array_ref();
 }
 my $titlebar_commands = '';

Modified: rt/branches/3.999-DANGEROUS/share/html/Ticket/ShowEmailRecord.html
==============================================================================
--- rt/branches/3.999-DANGEROUS/share/html/Ticket/ShowEmailRecord.html	(original)
+++ rt/branches/3.999-DANGEROUS/share/html/Ticket/ShowEmailRecord.html	Mon Sep  1 17:05:52 2008
@@ -57,7 +57,7 @@
         return;
     }
     my $href = RT->config->get('WebPath') .'/Ticket/Attachment/'
-        . $attach->transaction->id .'/'. $attach->id .'/'
+        . $attach->transaction_id .'/'. $attach->id .'/'
         . $m->interp->apply_escapes( $attach->filename, 'u' );
     $m->out( '<a href="'. $href  .'">'. _('download') .'</a>' );
 };
@@ -84,7 +84,7 @@
 unless ( $AttachmentObj->id ) {
     abort(_("Attachment '%1' could not be loaded", $attachment));
 }
-unless ($AttachmentObj->transaction->id == $transaction ) {
+unless ($AttachmentObj->transaction_id() == $transaction ) {
     abort(_("Attachment '%1' could not be loaded", $attachment));
 }
 


More information about the Rt-commit mailing list