[Bps-public-commit] r13913 - in sd/trunk: bin lib/App/SD/Replica/RT
jesse at bestpractical.com
jesse at bestpractical.com
Wed Jul 9 12:47:04 EDT 2008
Author: jesse
Date: Wed Jul 9 12:47:03 2008
New Revision: 13913
Modified:
sd/trunk/bin/sd
sd/trunk/lib/App/SD/Replica/RT.pm
sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm
Log:
* Better normalization of undef and '' values in the RT pull encoder
Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd (original)
+++ sd/trunk/bin/sd Wed Jul 9 12:47:03 2008
@@ -138,9 +138,19 @@
$0 ticket show --uuid <uuid>
$0 pull --from remote-url
+
$0 help
Show this file
+= ENVIRONMENT
+
+ export SD_REPO=/path/to/sd/replica
+ # Specify where the ticket database SD is using should reside
+
+= EXAMPLES
+
+ sd pull --from rt:http://rt3.fsck.com|QUEUENAME|QUERY
+
EOF
}
Modified: sd/trunk/lib/App/SD/Replica/RT.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/RT.pm (original)
+++ sd/trunk/lib/App/SD/Replica/RT.pm Wed Jul 9 12:47:03 2008
@@ -5,7 +5,6 @@
use Moose;
extends qw/Prophet::ForeignReplica/;
use Params::Validate qw(:all);
-use UNIVERSAL::require;
use File::Temp ();
use Path::Class;
use Prophet::ChangeSet;
@@ -98,9 +97,10 @@
( $username, $password ) = split /:/, $auth, 2;
$uri->userinfo(undef);
}
- $self->rt_url("$uri");
+ $self->rt_url($uri->as_string);
$self->rt_queue($type);
- $self->rt_query( $query . " AND Queue = '$type'" );
+ $self->rt_query( ( $query ? "($query) AND " :"") . " Queue = '$type'" );
+ warn $self->rt_query;
$self->rt( RT::Client::REST->new( server => $server ) );
( $username, $password ) = $self->prompt_for_login( $uri, $username )
Modified: sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm (original)
+++ sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm Wed Jul 9 12:47:03 2008
@@ -2,13 +2,18 @@
use strict;
package App::SD::Replica::RT::PullEncoder;
+use Moose;
+
use base qw/Class::Accessor/;
use Params::Validate qw(:all);
use UNIVERSAL::require;
use Memoize;
-__PACKAGE__->mk_accessors(qw/sync_source/);
+has sync_source =>
+ ( isa => 'Str',
+ is => 'rw');
+
our $DEBUG = $Prophet::Handle::DEBUG;
@@ -40,7 +45,8 @@
sub txn_to_changeset {
my ($self, $txn, $ticket, $create_state) = (@_);
-
+
+ if ($ENV{'SD_DEBUG'}) {warn YAML::Dump($txn); use YAML;}
if ( my $sub = $self->can( '_recode_txn_' . $txn->{'Type'} ) ) {
my $changeset = Prophet::ChangeSet->new(
{ original_source_uuid => $self->sync_source->uuid,
@@ -53,6 +59,8 @@
next;
}
+
+
delete $txn->{'OldValue'} if ( $txn->{'OldValue'} eq '');
delete $txn->{'NewValue'} if ( $txn->{'NewValue'} eq '');
@@ -91,7 +99,7 @@
$args{'changeset'}->add_change( { change => $change } );
}
-
+sub _recode_txn_Keyword {} # RT 2 - unused
sub _recode_txn_CommentEmailRecord { return; }
sub _recode_txn_EmailRecord { return; }
@@ -315,7 +323,11 @@
my $id = shift;
return undef unless ($id);
- my $user = RT::Client::REST::User->new( rt => $self->sync_source->rt, id => $id )->retrieve;
+ my $user = eval { RT::Client::REST::User->new( rt => $self->sync_source->rt, id => $id )->retrieve};
+ if (my $err = $@) {
+ warn $err;
+ return $attr eq 'name' ? 'Unknown user' : 'nobody at localhost';
+ }
return $attr eq 'name' ? $user->name : $user->email_address;
}
@@ -324,12 +336,12 @@
sub warp_list_to_old_value {
my $self = shift;
- my $ticket_value = shift || '';
+ my $ticket_value = shift ||'';
my $add = shift;
my $del = shift;
- my @new = split( /\s*,\s*/, $ticket_value );
- my @old = grep { $_ ne $add } @new, $del;
+ my @new = grep { defined } split( /\s*,\s*/, $ticket_value );
+ my @old = (grep { defined $_ && $_ ne $add } @new, $del ) || ();
return join( ", ", @old );
}
@@ -396,6 +408,12 @@
for my $prop ( $change->prop_changes ) {
next if ( ( $PROP_MAP{ lc( $prop->name ) } || '' ) eq '_delete' );
$prop->name( $PROP_MAP{ lc( $prop->name ) } ) if $PROP_MAP{ lc( $prop->name ) };
+ # Normalize away undef -> "" and vice-versa
+ for (qw/new_value old_value/) {
+ $prop->$_("") if !defined ($prop->$_());
+ }
+ next if ( $prop->old_value eq $prop->new_value);
+
#
# if ( $prop->name eq 'id' || $prop->name eq 'queue') {
# $prop->old_value( $prop->old_value . '@' . $changeset->original_source_uuid ) if ( $prop->old_value);
More information about the Bps-public-commit
mailing list