[Bps-public-commit] SD branch, master, updated. fa5cdd14f6d003e19bff5209d5baec5d33b39462

jesse jesse at bestpractical.com
Mon May 18 12:00:11 EDT 2009


The branch, master has been updated
       via  fa5cdd14f6d003e19bff5209d5baec5d33b39462 (commit)
      from  4d3a17ab3b24b2eb937d65925169701eb5648db2 (commit)

Summary of changes:
 lib/App/SD/ForeignReplica/PullEncoder.pm |   38 +++++++++++++++++++-----------
 lib/App/SD/Replica/rt.pm                 |    2 +-
 lib/App/SD/Replica/rt/PullEncoder.pm     |    6 ++++-
 lib/App/SD/Replica/trac.pm               |    2 +
 lib/App/SD/Replica/trac/PullEncoder.pm   |   17 +++++++++++--
 5 files changed, 46 insertions(+), 19 deletions(-)

- Log -----------------------------------------------------------------
commit fa5cdd14f6d003e19bff5209d5baec5d33b39462
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 11:59:45 2009 -0400

    Bug fixes and further generalization to the ForeignReplica pull encoder

diff --git a/lib/App/SD/ForeignReplica/PullEncoder.pm b/lib/App/SD/ForeignReplica/PullEncoder.pm
index a6ef447..28420f6 100644
--- a/lib/App/SD/ForeignReplica/PullEncoder.pm
+++ b/lib/App/SD/ForeignReplica/PullEncoder.pm
@@ -5,13 +5,13 @@ use Params::Validate qw/validate/;
 
 sub run {
     my $self = shift;
-    my %args = validate( @_, {   after    => 1, callback => 1, });
+    my %args = validate( @_, { after => 1, callback => 1, } );
 
     $self->sync_source->log('Finding matching tickets');
-    
+
     my $tickets = $self->find_matching_tickets( query => $self->sync_source->query );
 
-    if ( scalar @$tickets == 0 ) {
+    if ( @$tickets == 0 ) {
         $self->sync_source->log("No tickets found.");
         return;
     }
@@ -20,45 +20,54 @@ sub run {
     $self->sync_source->log("Discovering ticket history");
 
     my ( $last_txn, @changesets );
-    my $previously_modified = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
+    my $previously_modified
+        = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
 
     my $progress = Time::Progress->new();
     $progress->attr( max => $#$tickets );
 
     local $| = 1;
-    
+
     my $last_modified;
 
     for my $ticket (@$tickets) {
-        $counter++;
 
-        my $ticket_id = $ticket->{id};
+        $counter++;
+        my $ticket_id = $self->ticket_id($ticket);
 
         print $progress->report( "%30b %p Est: %E\r", $counter );
         $self->sync_source->log( "Fetching ticket $ticket_id - $counter of " . scalar @$tickets );
 
+        if ( my $ticket_last_modified = $self->ticket_last_modified($ticket) ) {
+            $last_modified = $ticket_last_modified
+                if ( !$last_modified || $ticket_last_modified > $last_modified );
+        }
+
         my $final_state         = $self->_translate_final_ticket_state($ticket);
-        my $initial_state       = {%$final_state};
+        my $ticket_initial_data = {%$final_state};
 
         my $transactions = $self->find_matching_transactions(
             ticket => $ticket,
             starting_transaction =>
                 $self->sync_source->app_handle->handle->last_changeset_from_source(
                 $self->sync_source->uuid_for_remote_id($ticket_id)
-                ) || 1
+                )
+                || 1
         );
 
         # Walk transactions newest to oldest.
         my $txn_counter = 0;
         for my $txn ( sort { $b->{'serial'} <=> $a->{'serial'} } @$transactions ) {
-            my $created =  App::SD::Util::string_to_datetime( $txn->{timesta} );
 
-            $last_modified = $txn->{timestamp}     if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
+            $last_modified = $txn->{timestamp}
+                if ( !$last_modified || ( $txn->{timestamp} > $last_modified ) );
 
-            $txn_counter++;
-            $self->sync_source->log( "$ticket_id Transcoding transaction $txn_counter of " . scalar @$transactions );
-            my $changeset = $self->transcode_one_txn( $txn, $initial_state, $final_state );
+            $self->sync_source->log( "$ticket_id Transcoding transaction "
+                    . ++$txn_counter . " of "
+                    . scalar @$transactions );
+            my $changeset = $self->transcode_one_txn( $txn, $ticket_initial_data, $final_state );
             next unless $changeset && $changeset->has_changes;
+
             # the changesets are older than the ones that came before, so they goes first
             unshift @changesets, $changeset;
         }
@@ -77,6 +86,7 @@ sub run {
 
 }
 
+sub ticket_last_modified { undef}
 
 sub warp_list_to_old_value {
     my $self    = shift;
diff --git a/lib/App/SD/Replica/rt.pm b/lib/App/SD/Replica/rt.pm
index 5174a8c..8638f09 100644
--- a/lib/App/SD/Replica/rt.pm
+++ b/lib/App/SD/Replica/rt.pm
@@ -49,7 +49,7 @@ sub BUILD {
 }
 
 sub foreign_username { return shift->rt_username(@_)}
-
+  
 sub get_txn_list_by_date {
     my $self   = shift;
     my $ticket = shift;
diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index a513ac0..79f0890 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -11,7 +11,11 @@ has sync_source =>
     ( isa => 'App::SD::Replica::rt',
       is => 'rw');
 
-
+sub ticket_id {
+    my $self = shift;
+    my $ticket = shift;
+     return $ticket->{id};
+}
 
 sub _translate_final_ticket_state {
     my $self   = shift;
diff --git a/lib/App/SD/Replica/trac.pm b/lib/App/SD/Replica/trac.pm
index 16cd548..82cb273 100644
--- a/lib/App/SD/Replica/trac.pm
+++ b/lib/App/SD/Replica/trac.pm
@@ -47,6 +47,8 @@ sub BUILD {
     $self->trac->ensure_logged_in;
 }
 
+
+
 sub get_txn_list_by_date {
     my $self   = shift;
     my $ticket = shift;
diff --git a/lib/App/SD/Replica/trac/PullEncoder.pm b/lib/App/SD/Replica/trac/PullEncoder.pm
index 064dd18..0801e8d 100644
--- a/lib/App/SD/Replica/trac/PullEncoder.pm
+++ b/lib/App/SD/Replica/trac/PullEncoder.pm
@@ -12,6 +12,18 @@ has sync_source => (
     is  => 'rw');
 
 
+sub ticket_id {
+    my $self = shift;
+    my $ticket = shift;
+     return $ticket->id;
+}
+
+sub ticket_last_modified {
+    my $self = shift;
+    my $ticket = shift;
+    return $ticket->last_modified;
+}
+
 sub _translate_final_ticket_state {
     my $self          = shift;
     my $ticket_object = shift;
@@ -78,13 +90,12 @@ Returns a reference to an array of all transactions (as hashes) on ticket $id af
 sub find_matching_transactions { 
     my $self = shift;
     my %args = validate( @_, { ticket => 1, starting_transaction => 1 } );
-    my @raw_txns = $args{ticket}->comments;
+    my @raw_txns = @{$args{ticket}->history->entries};
 
     my @txns;
     # XXX TODO make this one loop.
-    for my $txn ( sort @raw_txns) {
+    for my $txn ( sort { $a->date cmp $b->date} @raw_txns) {
         my $txn_date = $txn->date->epoch;
-
         # Skip things we know we've already pulled
         next if $txn_date < ( $args{'starting_transaction'} ||0 );
         # Skip things we've pushed

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



More information about the Bps-public-commit mailing list