[Rt-commit] r15681 - in rt/branches/3.999-DANGEROUS: lib/RT/Interface lib/RT/Model lib/RT/ScripAction share/html/Ticket/Elements

ruz at bestpractical.com ruz at bestpractical.com
Sun Aug 31 22:14:21 EDT 2008


Author: ruz
Date: Sun Aug 31 22:14:21 2008
New Revision: 15681

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/Ticket/Elements/FindAttachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/LoadTextAttachments
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowGnuPGStatus
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowMessageHeaders
   rt/branches/3.999-DANGEROUS/share/html/Ticket/Elements/ShowTransaction

Log:
* replace Attachments.transaction_id with transaction
* use jifty object accessors

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	Sun Aug 31 22:14:21 2008
@@ -549,9 +549,8 @@
         # 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_id headers));
-        $attachments->limit( column => 'transaction_id', value => $txn->id );
-        $attachments->limit( column => 'parent',         value => 0 );
+        $attachments->query_columns(qw(id parent transaction headers));
+        $attachments->limit( column => 'transaction', value => $txn->id );
         $attachments->limit(
             column      => 'parent',
             operator    => 'IS',
@@ -569,7 +568,7 @@
     }
 
     my $attachments = RT::Model::AttachmentCollection->new( current_user => $txn->current_user );
-    $attachments->limit( column => 'transaction_id', value => $txn->id );
+    $attachments->limit( column => 'transaction', 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	Sun Aug 31 22:14:21 2008
@@ -78,7 +78,7 @@
 use base 'RT::Record';
 use Jifty::DBI::Schema;
 use Jifty::DBI::Record schema {
-    column transaction_id => references RT::Model::Transaction;
+    column transaction => 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_id' is the mandatory id of the transaction this attachment is associated with.;
+    'transaction' 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_id => 0,
+        transaction => 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_id'} ) {
+    unless ( $args{'transaction'} ) {
         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_id => $args{'transaction_id'},
+            transaction => $args{'transaction'},
             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_id => $args{'transaction_id'},
+                transaction => $args{'transaction'},
                 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_id   => $args{'transaction_id'},
+            transaction   => $args{'transaction'},
             content_type     => $Attachment->mime_type,
             content_encoding => $content_encoding,
             parent           => $args{'parent'},
@@ -212,27 +212,17 @@
     return ( $self->SUPER::create(%args) );
 }
 
-=head2 transaction_obj
+=head2 transaction
 
-Returns the transaction object asscoiated with this attachment.
+Returns the L<RT::Model::Transaction> object this attachment is asscoiated to.
 
 =cut
 
 sub 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};
+    require Carp; Carp::confess('use transaction method instead of transaction_obj');
 }
 
-=head2 parent_obj
+=head2 parent
 
 Returns a parent's L<RT::Model::Attachment> object if this attachment
 has a parent, otherwise returns undef.
@@ -240,12 +230,7 @@
 =cut
 
 sub parent_obj {
-    my $self = shift;
-    return undef unless $self->parent;
-
-    my $parent = RT::Model::Attachment->new;
-    $parent->load_by_id( $self->parent );
-    return $parent;
+    require Carp; Carp::confess('use parent method instead of parent_obj');
 }
 
 =head2 children
@@ -340,7 +325,7 @@
 sub content_length {
     my $self = shift;
 
-    return undef unless $self->transaction_obj->current_user_can_see;
+    return undef unless $self->transaction->current_user_can_see;
 
     my $len = $self->get_header('Content-Length');
     unless ( defined $len ) {
@@ -393,7 +378,7 @@
 
         $body =~ s/^/> /gm;
 
-        $body = '[' . $self->transaction_obj->creator_obj->name() . ' - ' . $self->transaction_obj->created_as_string() . "]:\n\n" . $body . "\n\n";
+        $body = '[' . $self->transaction->creator_obj->name() . ' - ' . $self->transaction->created_as_string() . "]:\n\n" . $body . "\n\n";
 
     } else {
         $body = "[Non-text message not quoted]\n\n";
@@ -438,8 +423,8 @@
 
     my %data                 = ();
     my $current_user_address = lc $self->current_user->user_object->email;
-    my $correspond           = lc $self->transaction_obj->ticket_obj->queue_obj->correspond_address;
-    my $comment              = lc $self->transaction_obj->ticket_obj->queue_obj->comment_address;
+    my $correspond           = lc $self->transaction->ticket_obj->queue_obj->correspond_address;
+    my $comment              = lc $self->transaction->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);
@@ -608,7 +593,7 @@
 sub encrypt {
     my $self = shift;
 
-    my $txn = $self->transaction_obj;
+    my $txn = $self->transaction;
     return ( 0, _('Permission Denied') ) unless $txn->current_user_can_see;
     return ( 0, _('Permission Denied') )
         unless $txn->ticket_obj->current_user_has_right('ModifyTicket');
@@ -665,7 +650,7 @@
 sub decrypt {
     my $self = shift;
 
-    my $txn = $self->transaction_obj;
+    my $txn = $self->transaction;
     return ( 0, _('Permission Denied') ) unless $txn->current_user_can_see;
     return ( 0, _('Permission Denied') )
         unless $txn->ticket_obj->current_user_has_right('ModifyTicket');
@@ -713,7 +698,7 @@
         return ( $self->__value( $field, @_ ) );
     }
 
-    return undef unless $self->transaction_obj->current_user_can_see;
+    return undef unless $self->transaction->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	Sun Aug 31 22:14:21 2008
@@ -107,7 +107,7 @@
     my $res = $self->new_alias('Transactions');
     $self->limit(
         entry_aggregator => 'AND',
-        column           => 'transaction_id',
+        column           => 'transaction',
         value            => $res . '.id',
         quote_value      => 0,
     );
@@ -218,7 +218,7 @@
     my $Attachment = $self->SUPER::next;
     return $Attachment unless $Attachment;
 
-    my $txn = $Attachment->transaction_obj;
+    my $txn = $Attachment->transaction;
     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	Sun Aug 31 22:14:21 2008
@@ -685,7 +685,7 @@
             alias1  => $self->{_sql_transalias},
             column1 => 'id',
             table2  => RT::Model::AttachmentCollection->new,
-            column2 => 'transaction_id',
+            column2 => 'transaction',
         );
     }
 

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	Sun Aug 31 22:14:21 2008
@@ -468,8 +468,8 @@
 
         $self->{'message'} = RT::Model::AttachmentCollection->new();
         $self->{'message'}->limit(
-            column => 'transaction_id',
-            value  => $self->id
+            column => 'transaction',
+            value  => $self->id,
         );
         $self->{'message'}->children_of(0);
     } else {
@@ -665,7 +665,7 @@
         return $self->{'attachments'};
     }
 
-    $self->{'attachments'}->limit( column => 'transaction_id', value => $self->id );
+    $self->{'attachments'}->limit( column => 'transaction', 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_id => $self->id,
-        attachment     => $mime_object
+        transaction => $self,
+        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	Sun Aug 31 22:14:21 2008
@@ -337,7 +337,7 @@
 
     my $attachments = RT::Model::AttachmentCollection->new( current_user => RT->system_user );
     $attachments->limit(
-        column => 'transaction_id',
+        column => 'transaction',
         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	Sun Aug 31 22:14:21 2008
@@ -113,7 +113,7 @@
     }
 
     # Transaction
-    my $obj = $self->transaction_obj;
+    my $obj = $self->transaction;
     if ( defined $obj->id ) {
         push( @$list, $obj );
     } else {

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	Sun Aug 31 22:14:21 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_id created));
+$attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction created));
 
 my $transactions = $attachments->new_alias('Transactions');
 $attachments->join( alias1 => 'main',
-		    column1 => 'transaction_id',
+		    column1 => 'transaction',
 		    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	Sun Aug 31 22:14:21 2008
@@ -49,12 +49,12 @@
 
 my $attachments = RT::Model::AttachmentCollection->new();
 
-$attachments->query_columns( qw(id content content_type transaction_id content_encoding));
+$attachments->query_columns( qw(id content content_type transaction content_encoding));
 
 if ( $ticket->current_user_has_right('ShowTicket') ) {
     my $transactions = $attachments->new_alias('Transactions');
     $attachments->join( alias1 => 'main',
-                                           column1 => 'transaction_id',
+                                           column1 => 'transaction',
                                            alias2 => $transactions,
                                            column2 => 'id' );
     

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	Sun Aug 31 22:14:21 2008
@@ -80,7 +80,7 @@
 my $reverify_cb = sub  {
     my $top = shift;
 
-    my $txn = $top->transaction_obj;
+    my $txn = $top->transaction;
     unless ( $txn && $txn->id ) {
         return (0, "Couldn't get transaction of attachment #". $top->id);
     }

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	Sun Aug 31 22:14:21 2008
@@ -73,7 +73,7 @@
     @headers = grep $display_headers{ lc $_->{'Tag'} }, @headers;
 }
 
-my $ticket = $message->transaction_obj->ticket_obj;
+my $ticket = $message->transaction->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	Sun Aug 31 22:14:21 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_id) );
+    $attachments->query_columns( qw( id filename content_type headers subject parent content_encoding content_type transaction) );
     $attachments = $attachments->items_array_ref();
 }
 my $titlebar_commands = '';


More information about the Rt-commit mailing list