[Bps-public-commit] r11547 - in SVN-PropDB: . lib/Prophet/Replica/Hiveminder
jesse at bestpractical.com
jesse at bestpractical.com
Sat Apr 5 18:40:54 EDT 2008
Author: jesse
Date: Sat Apr 5 18:40:47 2008
New Revision: 11547
Modified:
SVN-PropDB/ (props changed)
SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm
SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm
Log:
r29255 at 31b: jesse | 2008-04-05 12:40:00 -1000
* getting closer to a workable hiveminder pull
Modified: SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm (original)
+++ SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm Sat Apr 5 18:40:47 2008
@@ -125,7 +125,7 @@
sub find_matching_tasks {
my $self = shift;
-my $tasks = $j->act('TaskSearch',
+my $tasks = $self->hm->act('TaskSearch',
owner => 'me',
group => 0,
requestor => 'me',
@@ -143,11 +143,11 @@
my %args = validate( @_, { task => 1, starting_transaction => 1 } );
my ($task) = validate_pos(@_, 1);
- my $txns = $j->search('TaskTransaction', task_id => $args{task});
+ my $txns = $self->hm->search('TaskTransaction', task_id => $args{task});
foreach my $txn (@{$txns||[]}) {
next if $txn < $args{'starting_transaction'}; # Skip things we've pushed
next if $self->prophet_has_seen_transaction($txn);
- $txn->{history_entries} = $j->search('TaskHistory', transaction_id => $txn->{'id'});
+ $txn->{history_entries} = $self->hm->search('TaskHistory', transaction_id => $txn->{'id'});
}
return $txns;
Modified: SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm (original)
+++ SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm Sat Apr 5 18:40:47 2008
@@ -1,13 +1,10 @@
use warnings;
use strict;
-package Prophet::Replica::RT::PullEncoder;
+package Prophet::Replica::Hiveminder::PullEncoder;
use base qw/Class::Accessor/;
use Params::Validate qw(:all);
use UNIVERSAL::require;
-use RT::Client::REST ();
-use RT::Client::REST::User ();
-use RT::Client::REST::Ticket;
use Memoize;
@@ -15,27 +12,16 @@
our $DEBUG = $Prophet::Handle::DEBUG;
-
-
-
-
sub run {
my $self = shift;
- my %args = validate( @_, { ticket => 1, transactions => 1} );
-
- $args{'ticket'}->{'id'} =~ s/^ticket\///g;
-
- my $ticket = $args{'ticket'};
+ my %args = validate( @_, { task => 1, transactions => 1 } );
- warn "Working on " . $ticket->{id};
- my $create_state = $ticket;;
- map { $create_state->{$_} = $self->date_to_iso( $create_state->{$_} ) }
- qw(Created Resolved Told LastUpdated Starts Started);
-
-
- map { $create_state->{$_} =~ s/ minutes$// } qw(TimeWorked TimeLeft TimeEstimated);
+ warn "Working on " . $args{'task'}->{id};
my @changesets;
+
+ my $previous_state = $args{'task'};
for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @{ $args{'transactions'} } ) {
+
if ( my $sub = $self->can( '_recode_txn_' . $txn->{'Type'} ) ) {
my $changeset = Prophet::ChangeSet->new(
{ original_source_uuid => $self->sync_source->uuid,
@@ -43,41 +29,27 @@
}
);
- if ( ( $txn->{'Ticket'} ne $ticket->{id} ) && $txn->{'Type'} !~ /^(?:Comment|Correspond)$/ ) {
- warn "Skipping a data change from a merged ticket" . $txn->{'Ticket'} . ' vs ' . $ticket->{id};
- next;
- }
-
$sub->(
$self,
- ticket => $ticket,
- create_state => $create_state,
- txn => $txn,
- changeset => $changeset
+ previous_state => $previous_state,
+ txn => $txn,
+ changeset => $changeset
);
$self->translate_prop_names($changeset);
unshift @changesets, $changeset unless $changeset->is_empty;
} else {
- warn "not handling txn type $txn->{Type} for $txn->{id} (Ticket $args{ticket}{id}) yet";
+ warn "not handling txn type $txn->{Type} for $txn->{id} (Ticket $args{task}{id}) yet";
die YAML::Dump($txn);
}
-
}
return \@changesets;
}
-sub _recode_txn_CommentEmailRecord { return; }
-
-sub _recode_txn_EmailRecord { return; }
-sub _recode_txn_AddReminder { return; }
-sub _recode_txn_ResolveReminder { return; }
-sub _recode_txn_DeleteLink { }
-
sub _recode_txn_Status {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
$args{txn}->{'Type'} = 'Set';
return $self->_recode_txn_Set(%args);
@@ -85,51 +57,50 @@
sub _recode_txn_Told {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
$args{txn}->{'Type'} = 'Set';
return $self->_recode_txn_Set(%args);
}
-
sub _recode_txn_Set {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
my $change = Prophet::Change->new(
{ node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id($args{'create_state'}->{'id'}),
+ node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
change_type => 'update_file'
}
);
if ( $args{txn}->{Field} eq 'Queue' ) {
- my $current_queue = $args{ticket}->{'Queue'};
+ my $current_queue = $args{task}->{'Queue'};
my $user = $args{txn}->{Creator};
if ( $args{txn}->{Description} =~ /Queue changed from (.*) to $current_queue by $user/ ) {
- $args{txn}->{OldValue} = $1;
- $args{txn}->{NewValue} = $current_queue;
+ $args{txn}->{old_value} = $1;
+ $args{txn}->{new_value} = $current_queue;
}
} elsif ( $args{txn}->{Field} eq 'Owner' ) {
- $args{'txn'}->{NewValue} = $self->resolve_user_id_to( name => $args{'txn'}->{'NewValue'} ),
- $args{'txn'}->{OldValue}
- = $self->resolve_user_id_to( name => $args{'txn'}->{'OldValue'} )
+ $args{'txn'}->{new_value} = $self->resolve_user_id_to( name => $args{'txn'}->{'new_value'} ),
+ $args{'txn'}->{old_value}
+ = $self->resolve_user_id_to( name => $args{'txn'}->{'old_value'} )
}
$args{'changeset'}->add_change( { change => $change } );
- if ( $args{'create_state'}->{ $args{txn}->{Field} } eq $args{txn}->{'NewValue'} ) {
- $args{'create_state'}->{ $args{txn}->{Field} } = $args{txn}->{'OldValue'};
+ if ( $args{'previous_state'}->{ $args{txn}->{Field} } eq $args{txn}->{'new_value'} ) {
+ $args{'previous_state'}->{ $args{txn}->{Field} } = $args{txn}->{'old_value'};
} else {
- $args{'create_state'}->{ $args{txn}->{Field} } = $args{txn}->{'OldValue'};
- warn $args{'create_state'}->{ $args{txn}->{Field} } . " != "
- . $args{txn}->{'NewValue'} . "\n\n"
+ $args{'previous_state'}->{ $args{txn}->{Field} } = $args{txn}->{'old_value'};
+ warn $args{'previous_state'}->{ $args{txn}->{Field} } . " != "
+ . $args{txn}->{'new_value'} . "\n\n"
. YAML::Dump( \%args );
}
$change->add_prop_change(
name => $args{txn}->{'Field'},
- old => $args{txn}->{'OldValue'},
- new => $args{txn}->{'NewValue'}
+ old => $args{txn}->{'old_value'},
+ new => $args{txn}->{'new_value'}
);
@@ -141,24 +112,24 @@
sub _recode_txn_Create {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
my $change = Prophet::Change->new(
{ node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id($args{'create_state'}->{'id'}),
+ node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
change_type => 'add_file'
}
);
- $args{'create_state'}->{ $self->sync_source->uuid . '-id' } = delete $args{'create_state'}->{'id'};
+ $args{'previous_state'}->{ $self->sync_source->uuid . '-id' } = delete $args{'previous_state'}->{'id'};
$args{'changeset'}->add_change( { change => $change } );
- for my $name ( keys %{ $args{'create_state'} } ) {
+ for my $name ( keys %{ $args{'previous_state'} } ) {
$change->add_prop_change(
name => $name,
old => undef,
- new => $args{'create_state'}->{$name},
+ new => $args{'previous_state'}->{$name},
);
}
@@ -169,24 +140,24 @@
sub _recode_txn_AddLink {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
- my $new_state = $args{'create_state'}->{ $args{'txn'}->{'Field'} };
- $args{'create_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
- $args{'create_state'}->{ $args{'txn'}->{'Field'} },
- $args{'txn'}->{'NewValue'},
- $args{'txn'}->{'OldValue'}
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
+ my $new_state = $args{'previous_state'}->{ $args{'txn'}->{'Field'} };
+ $args{'previous_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
+ $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
+ $args{'txn'}->{'new_value'},
+ $args{'txn'}->{'old_value'}
);
my $change = Prophet::Change->new(
{ node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id($args{'create_state'}->{'id'}),
+ node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
change_type => 'update_file'
}
);
$args{'changeset'}->add_change( { change => $change } );
$change->add_prop_change(
name => $args{'txn'}->{'Field'},
- old => $args{'create_state'}->{ $args{'txn'}->{'Field'} },
+ old => $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
new => $new_state
);
@@ -194,10 +165,11 @@
sub _recode_content_update {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
my $change = Prophet::Change->new(
- { node_type => 'comment',
- node_uuid => $self->sync_source->uuid_for_url( $self->sync_source->rt_url . "/transaction/" . $args{'txn'}->{'id'} ),
+ { node_type => 'comment',
+ node_uuid =>
+ $self->sync_source->uuid_for_url( $self->sync_source->rt_url . "/transaction/" . $args{'txn'}->{'id'} ),
change_type => 'add_file'
}
);
@@ -218,9 +190,9 @@
new => $args{'txn'}->{'Content'}
);
$change->add_prop_change(
- name => 'ticket',
+ name => 'task',
old => undef,
- new => $args{ticket}->{uuid},
+ new => $args{task}->{uuid},
);
$args{'changeset'}->add_change( { change => $change } );
}
@@ -230,28 +202,28 @@
sub _recode_txn_AddWatcher {
my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
+ my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
- my $new_state = $args{'create_state'}->{ $args{'txn'}->{'Field'} };
+ my $new_state = $args{'previous_state'}->{ $args{'txn'}->{'Field'} };
- $args{'create_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
- $args{'create_state'}->{ $args{'txn'}->{'Field'} },
+ $args{'previous_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
+ $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
- $self->resolve_user_id_to( email => $args{'txn'}->{'NewValue'} ),
- $self->resolve_user_id_to( email => $args{'txn'}->{'OldValue'} )
+ $self->resolve_user_id_to( email => $args{'txn'}->{'new_value'} ),
+ $self->resolve_user_id_to( email => $args{'txn'}->{'old_value'} )
);
my $change = Prophet::Change->new(
{ node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id($args{'create_state'}->{'id'}),
+ node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
change_type => 'update_file'
}
);
$args{'changeset'}->add_change( { change => $change } );
$change->add_prop_change(
name => $args{'txn'}->{'Field'},
- old => $args{'create_state'}->{ $args{'txn'}->{'Field'} },
+ old => $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
new => $new_state
);
@@ -259,67 +231,26 @@
*_recode_txn_DelWatcher = \&_recode_txn_AddWatcher;
-sub _recode_txn_CustomField {
- my $self = shift;
- my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
-
- my $new = $args{'txn'}->{'NewValue'};
- my $old = $args{'txn'}->{'OldValue'};
- my $name;
- if ( $args{'txn'}->{'Description'} =~ /^(.*) $new added by/ ) {
- $name = $1;
-
- } elsif ( $args{'txn'}->{'Description'} =~ /^(.*) $old delete by/ ) {
- $name = $1;
- } else {
- die "Uh. what to do with txn descriotion " . $args{'txn'}->{'Description'};
- }
-
- $args{'txn'}->{'Field'} = "CF-" . $name;
-
- my $new_state = $args{'create_state'}->{ $args{'txn'}->{'Field'} };
- $args{'create_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
- $args{'create_state'}->{ $args{'txn'}->{'Field'} },
- $args{'txn'}->{'NewValue'},
- $args{'txn'}->{'OldValue'}
- );
-
- my $change = Prophet::Change->new(
- { node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id($args{'create_state'}->{'id'}),
- change_type => 'update_file'
- }
- );
-
- $args{'changeset'}->add_change( { change => $change } );
- $change->add_prop_change(
- name => $args{'txn'}->{'Field'},
- old => $args{'create_state'}->{ $args{'txn'}->{'Field'} },
- new => $new_state
- );
-}
-
sub resolve_user_id_to {
my $self = shift;
my $attr = shift;
my $id = shift;
return undef unless ($id);
- my $user = RT::Client::REST::User->new( rt => $self->sync_source->rt, id => $id )->retrieve;
+ my $user = Hiveminder::Client::REST::User->new( rt => $self->sync_source->rt, id => $id )->retrieve;
return $attr eq 'name' ? $user->name : $user->email_address;
}
memoize 'resolve_user_id_to';
-
sub warp_list_to_old_value {
- my $self = shift;
- my $ticket_value = shift || '';
- my $add = shift;
- my $del = shift;
+ my $self = shift;
+ my $task_value = shift || '';
+ my $add = shift;
+ my $del = shift;
- my @new = split( /\s*,\s*/, $ticket_value );
+ my @new = split( /\s*,\s*/, $task_value );
my @old = grep { $_ ne $add } @new, $del;
return join( ", ", @old );
}
More information about the Bps-public-commit
mailing list