[Bps-public-commit] r17149 - sd/trunk/lib/App/SD/Replica/hm

ruz at bestpractical.com ruz at bestpractical.com
Tue Dec 9 08:58:14 EST 2008


Author: ruz
Date: Tue Dec  9 08:58:13 2008
New Revision: 17149

Modified:
   sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm

Log:
* fix failing tests

Modified: sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	Tue Dec  9 08:58:13 2008
@@ -174,8 +174,8 @@
     my $tid = $self->sync_source->remote_id_for_uuid( $change->record_uuid )
         or die "Couldn't get remote id of SD ticket";
 
-    my ($seen_current, @new_requestors) = (0);
-    if ( $args{'requestor_id'} ) {
+    my ($seen_current, $dropped_all, @new_requestors) = (0, 0);
+    if ( exists $args{'requestor_id'} && defined $args{'requestor_id'} && length $args{'requestor_id'} ) {
         my $task = $self->sync_source->hm->read('Task', id => $tid );
         my $current_requestor = $self->sync_source->user_info(
             id => $task->{'requester_id'}
@@ -196,6 +196,11 @@
             warn "Can not set more than one requestor in HM";
         }
     }
+    elsif ( exists $args{'requestor_id'} ) {
+        $dropped_all = 1;
+        delete $args{'requestor_id'};
+        warn "Requestor can not be empty in HM";
+    }
 
     my $txn_id;
     if ( keys %args ) {
@@ -208,25 +213,44 @@
     }
 
     if ( @new_requestors ) {
-        my $hm_user = $self->sync_source->user_info;
-        my $email = $self->comment_as_email( {
-            creator => $hm_user->{'email'},
-            content => ($seen_current? "New requestors in addition to the current: " : "Requestors have been changed: ")
-                . join( ', ', map $_->format, @new_requestors ),
-        } );
-        my $status = $self->sync_source->hm->act(
-            'CreateTaskEmail',
-            task_id => $tid,
-            message => $email->as_string,
+        my $comment_id = $self->record_comment(
+            task => $tid,
+            content => 
+                ($seen_current
+                    ? "New requestors in addition to the current: "
+                    : "Requestors have been changed: "
+                ) . join( ', ', map $_->format, @new_requestors ),
         );
-        warn "Couldn't add a comment on the recently created HM task"
-            unless $status->{'success'};
-        $txn_id = $status->{'content'}{'id'} if $status->{'content'}{'id'};
+        $txn_id = $comment_id if $comment_id;
+    }
+    elsif ( $dropped_all ) {
+        my $comment_id = $self->record_comment(
+            task => $tid,
+            content => "All requestors have been deleted",
+        );
+        $txn_id = $comment_id if $comment_id;
     }
 
     return $txn_id;
 }
 
+sub record_comment {
+    my $self = shift;
+    my %args = @_;
+    my $tid  = delete $args{'task'};
+    $args{'creator'} ||= $self->sync_source->user_info->{'email'};
+
+    my $email = $self->comment_as_email( \%args );
+    my $status = $self->sync_source->hm->act(
+        'CreateTaskEmail',
+        task_id => $tid,
+        message => $email->as_string,
+    );
+    warn "Couldn't add a comment on the recently created HM task"
+        unless $status->{'success'};
+    return $status->{'content'}{'id'};
+}
+
 sub integrate_attachment {
     my $self = shift;
     my ($change, $changeset) = validate_pos( @_, { isa => 'Prophet::Change' }, {isa => 'Prophet::ChangeSet'} );



More information about the Bps-public-commit mailing list